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

25 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-08-13 11:58:51 +08:00
var fs = require('fs');
2019-08-13 14:31:12 +08:00
require('shelljs/global')
2019-08-13 11:58:51 +08:00
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`);
2019-08-13 14:31:12 +08:00
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`)
})
2019-08-13 11:58:51 +08:00
})
}