65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
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 = argv.name ?? 'app';
|
|
const appPort = argv.port ?? '0';
|
|
const isMonorepo = argv.monorepo === 'T';
|
|
|
|
const rootDir = __dirname;
|
|
const contextDir = `${argv._[0]}/` ?? './';
|
|
|
|
// create app folder
|
|
const appsDir = `${contextDir}/apps`;
|
|
const appDir = isMonorepo ? `${contextDir}/apps/${appName}-fe` : `${contextDir}/`;
|
|
if (!fs.existsSync(appDir)) {
|
|
if (!fs.existsSync(contextDir)) {
|
|
fs.mkdirSync(contextDir);
|
|
}
|
|
if (isMonorepo) {
|
|
fs.mkdirSync(appsDir);
|
|
}
|
|
fs.mkdirSync(appDir);
|
|
fs.mkdirSync(`${appDir}/src`);
|
|
}
|
|
|
|
// copy folder content
|
|
try {
|
|
fs.cpSync(`${rootDir}/source/shared/`, contextDir, {
|
|
force: true,
|
|
recursive: true,
|
|
});
|
|
fs.cpSync(`${rootDir}/source/app/`, appDir, {
|
|
force: true,
|
|
recursive: true,
|
|
});
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
|
|
// replace in files
|
|
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`);
|