Fix tool when run from node_modules

Change-Id: Ica686f76a2264d760a1cd027b3393774778a6466
This commit is contained in:
Roman Jaroš 2023-09-09 19:58:47 +02:00
parent 829249c843
commit 6f08d6cc31
2 changed files with 19 additions and 6 deletions

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# Seedling
## How to start
1. Create context folder and then use it as last argument (use can use `.`)
2. Create file `.npmrc`
3. Paste this content to file `@toolkit:registry=https://npm.romanjaros.dev`
2. Use this `pnpm dlx @toolkit/seedling --name many --port 93 --monorepo T ./build`

View file

@ -8,14 +8,16 @@ const appName = argv.name ?? 'app';
const appPort = argv.port ?? '0';
const isMonorepo = argv.monorepo === 'T';
// context directory
const contextDir = `${argv._[0]}` ?? '.';
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);
}
@ -25,11 +27,14 @@ if (!fs.existsSync(appDir)) {
// copy folder content
try {
fs.cpSync('./source/shared/', contextDir, {
overwrite: false,
fs.cpSync(`${rootDir}/source/shared/`, contextDir, {
force: true,
recursive: true,
});
fs.cpSync(`${rootDir}/source/app/`, appDir, {
force: true,
recursive: true,
});
fs.cpSync('./source/app/', appDir, { overwrite: true, recursive: true });
} catch (err) {
console.error(err);
}