Working init app
Change-Id: I545c6c2f7182adf28d4ced41ac38613746d2b3d8
This commit is contained in:
parent
13ab39d1fd
commit
6f2586ccad
15 changed files with 133 additions and 62 deletions
65
create.js
65
create.js
|
|
@ -1,37 +1,60 @@
|
|||
const fs = require('fs')
|
||||
var readlineSync = require('readline-sync');
|
||||
const fs = require('fs');
|
||||
const replaceInFiles = require('replace-in-file');
|
||||
const { execSync } = require('child_process');
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
|
||||
// questions
|
||||
const appName = readlineSync.question('What is app name? ', { defaultInput: 'many' });
|
||||
const appPort = readlineSync.question('Which port use for deployment? ', { defaultInput: '93' });
|
||||
const isMonorepo = readlineSync.keyInYN('Apply monorepo?');
|
||||
const appName = argv.name ?? 'app';
|
||||
const appPort = argv.port ?? '0';
|
||||
const isMonorepo = argv.monorepo === 'T';
|
||||
|
||||
// context directory
|
||||
const contextDir = `${argv._[0]}/` ?? './';
|
||||
const contextDir = `${argv._[0]}` ?? '.';
|
||||
|
||||
// create app folder
|
||||
const appsDir = `${contextDir}/apps`
|
||||
const appDir = isMonorepo ? `${contextDir}/apps/${appName}-fe` : `${contextDir}/`
|
||||
if (!fs.existsSync(appDir)){
|
||||
if (isMonorepo) {
|
||||
fs.mkdirSync(appsDir);
|
||||
}
|
||||
fs.mkdirSync(appDir);
|
||||
fs.mkdirSync(`${appDir}/src`);
|
||||
const appsDir = `${contextDir}/apps`;
|
||||
const appDir = isMonorepo ? `${contextDir}/apps/${appName}-fe` : `${contextDir}/`;
|
||||
if (!fs.existsSync(appDir)) {
|
||||
fs.mkdirSync(contextDir);
|
||||
if (isMonorepo) {
|
||||
fs.mkdirSync(appsDir);
|
||||
}
|
||||
fs.mkdirSync(appDir);
|
||||
fs.mkdirSync(`${appDir}/src`);
|
||||
}
|
||||
|
||||
// copy folder content
|
||||
try {
|
||||
fs.cpSync('./source/shared/', contextDir, { overwrite: false, recursive: true })
|
||||
fs.cpSync('./source/app/', appDir, { overwrite: true, recursive: true })
|
||||
fs.cpSync('./source/shared/', contextDir, {
|
||||
overwrite: false,
|
||||
recursive: true,
|
||||
});
|
||||
fs.cpSync('./source/app/', appDir, { overwrite: true, recursive: true });
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
// replace in files
|
||||
replaceInFiles.sync({ files: './build/**/*.{ts,tsx}', from: /\/\/.\@ts\-nocheck\n/gm, to: '' });
|
||||
replaceInFiles.sync({ files: './build/**/*', from: /\$\(appName\)/gm, to: appName });
|
||||
replaceInFiles.sync({ files: './build/**/*', from: /\$\(AppName\)/gm, to: appName.charAt(0).toUpperCase() + appName.slice(1) });
|
||||
replaceInFiles.sync({ files: './build/**/*', from: /\$\(appPort\)/gm, to: appPort });
|
||||
replaceInFiles.sync({
|
||||
files: `./${contextDir}/**/*.{ts,tsx}`,
|
||||
from: /\/\/.\@ts\-nocheck\n/gm,
|
||||
to: '',
|
||||
});
|
||||
replaceInFiles.sync({
|
||||
files: `./${contextDir}/**/*`,
|
||||
from: /\$\(appName\)/gm,
|
||||
to: appName,
|
||||
});
|
||||
replaceInFiles.sync({
|
||||
files: `./${contextDir}/**/*`,
|
||||
from: /\$\(AppName\)/gm,
|
||||
to: appName.charAt(0).toUpperCase() + appName.slice(1),
|
||||
});
|
||||
replaceInFiles.sync({
|
||||
files: `./${contextDir}/**/*`,
|
||||
from: /\$\(appPort\)/gm,
|
||||
to: appPort,
|
||||
});
|
||||
|
||||
// install deps
|
||||
execSync(`cd ${contextDir} && pnpm i`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue