chore(package): use index-modules
This commit is contained in:
parent
b47146de45
commit
7be4e1901a
@ -120,6 +120,7 @@
|
||||
"gulp-plumber": "^1.0.0",
|
||||
"gulp-sourcemaps": "^1.5.1",
|
||||
"gulp-watch": "^4.2.2",
|
||||
"index-modules": "0.0.0",
|
||||
"leche": "^2.1.1",
|
||||
"mocha": "^3.0.2",
|
||||
"must": "^0.13.1",
|
||||
@ -131,7 +132,7 @@
|
||||
"scripts": {
|
||||
"build": "npm run build-indexes && gulp build --production",
|
||||
"depcheck": "dependency-check ./package.json",
|
||||
"build-indexes": "./tools/generate-index src/api src/xapi/mixins src/xo-mixins",
|
||||
"build-indexes": "index-modules src/api src/xapi/mixins src/xo-mixins",
|
||||
"dev": "npm run build-indexes && gulp build",
|
||||
"dev-test": "mocha --opts .mocha.opts --watch --reporter=min \"dist/**/*.spec.js\"",
|
||||
"lint": "standard",
|
||||
|
0
src/api/.index-modules
Normal file
0
src/api/.index-modules
Normal file
0
src/xapi/mixins/.index-modules
Normal file
0
src/xapi/mixins/.index-modules
Normal file
0
src/xo-mixins/.index-modules
Normal file
0
src/xo-mixins/.index-modules
Normal file
@ -1,84 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var join = require('path').join
|
||||
var readdir = require('fs').readdirSync
|
||||
var stat = require('fs').statSync
|
||||
var writeFile = require('fs').writeFileSync
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function bind (fn, thisArg) {
|
||||
return function () {
|
||||
return fn.apply(thisArg, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function camelCase (str) {
|
||||
return str.toLowerCase().replace(/[^a-z0-9]+([a-z0-9])/g, function (_, str) {
|
||||
return str.toUpperCase()
|
||||
})
|
||||
}
|
||||
|
||||
function removeSuffix (str, sfx) {
|
||||
var strLength = str.length
|
||||
var sfxLength = sfx.length
|
||||
|
||||
var pos = strLength - sfxLength
|
||||
if (pos < 0 || str.indexOf(sfx, pos) !== pos) {
|
||||
return false
|
||||
}
|
||||
|
||||
return str.slice(0, pos)
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
function handleEntry (entry, dir) {
|
||||
var stats = stat(join(dir, entry))
|
||||
var base
|
||||
if (stats.isDirectory()) {
|
||||
base = entry
|
||||
} else if (!(
|
||||
stats.isFile() && (
|
||||
(base = removeSuffix(entry, '.coffee')) ||
|
||||
(base = removeSuffix(entry, '.js'))
|
||||
)
|
||||
)) {
|
||||
return
|
||||
}
|
||||
|
||||
var identifier = camelCase(base)
|
||||
this(
|
||||
'import ' + identifier + " from './" + base + "'",
|
||||
'defaults.' + identifier + ' = ' + identifier,
|
||||
'export * as ' + identifier + " from './" + base + "'",
|
||||
''
|
||||
)
|
||||
}
|
||||
|
||||
function generateIndex (dir) {
|
||||
var content = [
|
||||
'//',
|
||||
'// This file has been generated by /tools/generate-index',
|
||||
'//',
|
||||
'// It is automatically re-generated each time a build is started.',
|
||||
'//',
|
||||
'',
|
||||
'const defaults = {}',
|
||||
'export default defaults',
|
||||
''
|
||||
]
|
||||
var write = bind(content.push, content)
|
||||
|
||||
readdir(dir).map(function (entry) {
|
||||
if (entry === 'index.js') {
|
||||
return
|
||||
}
|
||||
|
||||
handleEntry.call(write, entry, dir)
|
||||
})
|
||||
|
||||
writeFile(dir + '/index.js', content.join('\n'))
|
||||
}
|
||||
|
||||
process.argv.slice(2).map(generateIndex)
|
Loading…
Reference in New Issue
Block a user