2023-09-09 18:18:34 +02:00
|
|
|
const fs = require('fs');
|
2023-09-09 16:55:38 +02:00
|
|
|
const replaceInFiles = require('replace-in-file');
|
2023-09-09 18:18:34 +02:00
|
|
|
const { execSync } = require('child_process');
|
2023-09-09 16:55:38 +02:00
|
|
|
const argv = require('minimist')(process.argv.slice(2));
|
|
|
|
|
|
|
|
// questions
|
2023-09-09 18:18:34 +02:00
|
|
|
const appName = argv.name ?? 'app';
|
|
|
|
const appPort = argv.port ?? '0';
|
2023-09-09 16:55:38 +02:00
|
|
|
|
2023-12-22 17:48:27 +00:00
|
|
|
const defaultContextDir = '.';
|
2023-09-09 19:58:47 +02:00
|
|
|
const rootDir = __dirname;
|
2023-12-22 17:48:27 +00:00
|
|
|
const contextDir = `${argv._[0] ?? defaultContextDir}`;
|
2023-09-09 16:55:38 +02:00
|
|
|
|
|
|
|
// create app folder
|
2023-09-09 18:18:34 +02:00
|
|
|
const appsDir = `${contextDir}/apps`;
|
2023-09-10 21:24:57 +02:00
|
|
|
const uiDir = `${contextDir}/apps/${appName}-ui`;
|
2023-12-22 17:48:27 +00:00
|
|
|
const restDir = `${contextDir}/apps/${appName}-rest`;
|
2024-01-10 21:08:53 +00:00
|
|
|
const testDir = `${contextDir}/apps/${appName}-e2e`;
|
2023-09-09 20:35:06 +02:00
|
|
|
|
|
|
|
// prepare structure folders
|
2023-09-10 21:24:57 +02:00
|
|
|
if (!fs.existsSync(uiDir)) {
|
2023-09-09 19:58:47 +02:00
|
|
|
if (!fs.existsSync(contextDir)) {
|
|
|
|
fs.mkdirSync(contextDir);
|
|
|
|
}
|
2023-09-10 21:24:57 +02:00
|
|
|
fs.mkdirSync(appsDir);
|
|
|
|
fs.mkdirSync(uiDir);
|
|
|
|
fs.mkdirSync(`${uiDir}/src`);
|
2023-12-22 17:48:27 +00:00
|
|
|
fs.mkdirSync(restDir);
|
|
|
|
fs.mkdirSync(`${restDir}/src`);
|
2023-12-28 21:58:08 +00:00
|
|
|
fs.mkdirSync(testDir);
|
|
|
|
fs.mkdirSync(`${testDir}/src`);
|
2023-09-09 16:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy folder content
|
|
|
|
try {
|
2024-01-10 21:08:53 +00:00
|
|
|
fs.cpSync(`${rootDir}/source/global/`, contextDir, {
|
2023-09-09 19:58:47 +02:00
|
|
|
force: true,
|
|
|
|
recursive: true,
|
|
|
|
});
|
2023-09-10 21:24:57 +02:00
|
|
|
fs.cpSync(`${rootDir}/source/ui/`, uiDir, {
|
|
|
|
force: true,
|
|
|
|
recursive: true,
|
|
|
|
});
|
2023-12-22 17:48:27 +00:00
|
|
|
fs.cpSync(`${rootDir}/source/rest/`, restDir, {
|
2023-09-09 19:58:47 +02:00
|
|
|
force: true,
|
2023-09-09 18:18:34 +02:00
|
|
|
recursive: true,
|
|
|
|
});
|
2024-01-10 21:08:53 +00:00
|
|
|
fs.cpSync(`${rootDir}/source/e2e/`, testDir, {
|
2023-12-28 21:58:08 +00:00
|
|
|
force: true,
|
|
|
|
recursive: true,
|
|
|
|
});
|
2023-09-09 16:55:38 +02:00
|
|
|
} catch (err) {
|
2023-09-09 18:18:34 +02:00
|
|
|
console.error(err);
|
2023-09-09 16:55:38 +02:00
|
|
|
}
|
|
|
|
|
2023-09-09 20:43:02 +02:00
|
|
|
// rename internal files
|
2023-09-09 20:58:05 +02:00
|
|
|
if (contextDir === defaultContextDir) {
|
|
|
|
fs.unlinkSync(`${contextDir}/.npmrc`);
|
|
|
|
}
|
2023-09-09 20:43:02 +02:00
|
|
|
fs.renameSync(`${contextDir}/npmrc`, `${contextDir}/.npmrc`);
|
|
|
|
fs.renameSync(`${contextDir}/gitignore`, `${contextDir}/.gitignore`);
|
|
|
|
fs.renameSync(`${contextDir}/prettierrc`, `${contextDir}/.prettierrc`);
|
2023-09-09 21:10:07 +02:00
|
|
|
fs.renameSync(`${contextDir}/.tsconfig.json`, `${contextDir}/tsconfig.json`);
|
2023-09-10 21:24:57 +02:00
|
|
|
fs.renameSync(`${uiDir}/.tsconfig.json`, `${uiDir}/tsconfig.json`);
|
2023-12-22 17:48:27 +00:00
|
|
|
fs.renameSync(`${restDir}/.tsconfig.json`, `${restDir}/tsconfig.json`);
|
2023-12-28 21:58:08 +00:00
|
|
|
fs.renameSync(`${testDir}/.tsconfig.json`, `${testDir}/tsconfig.json`);
|
|
|
|
fs.renameSync(`${testDir}/src/.tsconfig.json`, `${testDir}/src/tsconfig.json`);
|
2023-09-09 20:43:02 +02:00
|
|
|
|
2023-09-09 16:55:38 +02:00
|
|
|
// replace in files
|
2023-09-09 18:18:34 +02:00
|
|
|
replaceInFiles.sync({
|
2023-12-22 17:48:27 +00:00
|
|
|
files: [`${contextDir}/**/*`, `${contextDir}/.devcontainer/*`],
|
|
|
|
from: /\/\/.@ts-nocheck\n/gm,
|
2023-09-09 18:18:34 +02:00
|
|
|
to: '',
|
|
|
|
});
|
|
|
|
replaceInFiles.sync({
|
2023-12-22 17:48:27 +00:00
|
|
|
files: [`${contextDir}/**/*`, `${contextDir}/.devcontainer/*`],
|
2023-09-09 18:18:34 +02:00
|
|
|
from: /\$\(appName\)/gm,
|
|
|
|
to: appName,
|
|
|
|
});
|
|
|
|
replaceInFiles.sync({
|
2023-12-22 17:48:27 +00:00
|
|
|
files: [`${contextDir}/**/*`, `${contextDir}/.devcontainer/*`],
|
2023-09-09 18:18:34 +02:00
|
|
|
from: /\$\(AppName\)/gm,
|
|
|
|
to: appName.charAt(0).toUpperCase() + appName.slice(1),
|
|
|
|
});
|
|
|
|
replaceInFiles.sync({
|
2023-12-22 17:48:27 +00:00
|
|
|
files: [`${contextDir}/**/*`, `${contextDir}/.devcontainer/*`],
|
2023-09-09 18:18:34 +02:00
|
|
|
from: /\$\(appPort\)/gm,
|
|
|
|
to: appPort,
|
|
|
|
});
|
|
|
|
|
|
|
|
// install deps
|
2023-12-22 17:48:27 +00:00
|
|
|
execSync(`pnpm i`, { cwd: `${contextDir}` });
|