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/scripts/init.js

28 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-04 14:16:57 +08:00
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}/.vscode`)
fs.writeFileSync(`${name}/.vscode/launch.json`, fs.readFileSync(`${__dirname}/../contents/_launch.json`).toString().replace(/__\$__/g, name))
fs.writeFileSync(`${name}/.vscode/tasks.json`, fs.readFileSync(`${__dirname}/../contents/_tasks.json`).toString().replace(/__\$__/g, name))
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`)
})
})
}