feat: package script
This commit is contained in:
parent
895e669082
commit
decca35009
37
package.js
Normal file
37
package.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const {execSync} = require('child_process');
|
||||
const {join} = require('path');
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const cwd = process.cwd();
|
||||
const [exe, script, package] = process.argv;
|
||||
|
||||
const path = join(cwd, 'packages', package);
|
||||
try {
|
||||
fs.accessSync(path);
|
||||
console.error(`Package '${package}' already exists, aborting.`);
|
||||
process.exit(1);
|
||||
}
|
||||
catch (error) {}
|
||||
|
||||
const [scope] = require('./package.json').name.split('/');
|
||||
const name = [scope, package].join('/');
|
||||
console.log(`Copying new project '${name}' to ${path}...`);
|
||||
fs.copySync(
|
||||
join(cwd, 'config/package'),
|
||||
path,
|
||||
);
|
||||
const json = {
|
||||
...require(join(path, 'package.json')),
|
||||
name,
|
||||
};
|
||||
fs.writeFileSync(
|
||||
join(path, 'package.json'),
|
||||
JSON.stringify(json, null, 2),
|
||||
);
|
||||
|
||||
const exec = (cmd) => execSync(cmd, {cwd: path, stdio: 'inherit'});
|
||||
console.log(`Installing...`);
|
||||
exec('yarn');
|
||||
|
||||
console.log(`Testing...`);
|
||||
exec('yarn run test');
|
|
@ -7,6 +7,7 @@
|
|||
"dev": "lerna run dev",
|
||||
"forcepub": "lerna run forcepub",
|
||||
"lint": "lerna run lint",
|
||||
"package": "node ./package.js",
|
||||
"test": "lerna run test --no-bail -- --silent",
|
||||
"watch": "lerna run watch --parallel"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user