index-tasukaru
Advanced tools
Comparing version 0.0.1 to 0.0.3
@@ -31,3 +31,3 @@ "use strict"; | ||
let argv = minimist_1.default(process.argv.slice(2), { | ||
boolean: ['f'], | ||
boolean: ['f', 'version'], | ||
string: ['sourceExts'], | ||
@@ -38,2 +38,5 @@ default: { | ||
}); | ||
if (argv.version) { | ||
exit(`${(yield getPackageJson()).version}`); | ||
} | ||
let targetDir = (_a = argv._[0]) !== null && _a !== void 0 ? _a : '.'; | ||
@@ -52,11 +55,22 @@ let workDir = path_1.default.join(process.cwd(), targetDir); | ||
let matchedFiles = files | ||
// Skip dotfiles | ||
.filter((f) => !!getExportName(f)) | ||
// Skip dotfiles and target file | ||
.filter((f) => !!getExportName(f) && f !== targetIndex) | ||
.filter((f) => matchExts(sourceExts, f)); | ||
if (!matchedFiles.length) { | ||
exitWithError(`No files matched.`, 2); | ||
} | ||
let indexLines = matchedFiles.map(getExportDefaultFromLine); | ||
let indexSource = indexLines.join('\n'); | ||
yield fs_extra_1.default.writeFile(targetIndexPath, indexSource + '\n'); | ||
echo(`Finished exporting ${matchedFiles.length} file(s).`); | ||
}); | ||
} | ||
exports.main = main; | ||
function echo(message) { | ||
console.log(message); | ||
} | ||
function exit(message) { | ||
message && console.log(message); | ||
process.exit(0); | ||
} | ||
function exitWithError(message, code) { | ||
@@ -83,1 +97,7 @@ console.error(`Error: ${message}`); | ||
} | ||
function getPackageJson() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let config = yield fs_extra_1.default.readFile(path_1.default.join(__dirname, '../package.json'), 'utf-8'); | ||
return JSON.parse(config); | ||
}); | ||
} |
{ | ||
"name": "index-tasukaru", | ||
"description": "Generate index file from CLI.", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"preferGlobal": true, | ||
@@ -12,3 +12,4 @@ "bin": { | ||
"dev": "tsc --watch", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prepare": "rm -rf lib/ && yarn build" | ||
}, | ||
@@ -15,0 +16,0 @@ "repository": { |
6889
103