This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-cli/scripts/init.js
2019-08-13 14:31:12 +08:00

25 lines
1.2 KiB
JavaScript

var fs = require('fs');
require('shelljs/global')
module.exports = function (name) {
if (fs.existsSync(name)) {
console.warn(`Dir:${process.cwd()}/${name} already exists`)
return;
}
fs.mkdir(name, function (err) {
if (err) {
return console.error(err);
}
console.log(`create dir ${name} success`);
fs.writeFileSync(`${name}/package.json`, fs.readFileSync(`${__dirname}/../contents/_package.json`).toString().replace(/__\$__/g, name))
fs.writeFileSync(`${name}/tsconfig.json`, fs.readFileSync(`${__dirname}/../contents/_tsconfig.json`))
fs.writeFileSync(`${name}/rollup.config.js`, fs.readFileSync(`${__dirname}/../contents/_rollup.config.js`))
fs.writeFileSync(`${name}/.gitignore`, fs.readFileSync(`${__dirname}/../contents/_gitignore`))
fs.mkdirSync(`${name}/src`)
fs.writeFileSync(`${name}/src/${name}.ts`, fs.readFileSync(`${__dirname}/../contents/$.ts`).toString().replace(/__\$__/g, name))
fs.writeFileSync(`${name}/index.ts`, `export default ['src/${name}']`)
exec(`cd ${name} && npm install && npm run build`, () => {
console.log(`Create Doric Project ${name} Success`)
})
})
}