@systemlight/fabric
Version:
A collection of configuration files containing prettier, eslint, stylelint.
84 lines (78 loc) • 2.27 kB
JavaScript
;
var node_fs = require('node:fs');
var node_path = require('node:path');
var commander = require('commander');
var chalk = require('chalk');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
let { version } = require('../package.json');
function copyDotFile(filename) {
node_fs.copyFileSync(node_path.resolve(__dirname, 'ignore', filename), `./.${filename}`);
}
function initPrettier() {
copyDotFile('prettierignore');
node_fs.writeFileSync('.prettierrc.js', `const fabric = require('@systemlight/fabric')
module.exports = {
...fabric.prettier,
}`, { flag: 'a' });
}
function initEslint() {
copyDotFile('eslintignore');
node_fs.writeFileSync('.eslintrc.js', `module.exports = {
extends: [require.resolve('@systemlight/fabric/dist/eslint')]
}
`, { flag: 'a' });
}
function initStylelint() {
copyDotFile('stylelintignore');
node_fs.writeFileSync('.stylelintrc.js', `module.exports = {
extends: [require.resolve('@systemlight/fabric/dist/stylelint')]
}`, { flag: 'a' });
}
function initGit() {
copyDotFile('gitignore');
}
function init(type) {
switch (type) {
case 'prettier':
initPrettier();
break;
case 'eslint':
initEslint();
break;
case 'stylelint':
initStylelint();
break;
case 'git':
initGit();
break;
}
console.log(`${chalk__default["default"].bgCyan.black(type)} 初始化完毕`);
}
commander.program
.name('@systemlight/fabric')
.usage('fabric init [--type,-t] [initType]')
.description('生成lint规范样式')
.version(version);
commander.program
.command('init')
.description('初始化配置文件')
.addOption(new commander.Option('-t, --type [initType...]', '选择生成文件类型').choices([
'prettier',
'eslint',
'stylelint',
'git'
]))
.action(({ type }) => {
if (!type) {
init('prettier');
init('eslint');
init('stylelint');
return;
}
type.forEach((v) => {
init(v);
});
});
commander.program.parse();