@jordanalec/dtk 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/init.js +11 -5
- package/package.json +1 -1
package/dist/init.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { cp } from 'fs/promises';
|
|
3
|
-
import { join, dirname } from 'path';
|
|
2
|
+
import { cp, readFile, writeFile } from 'fs/promises';
|
|
3
|
+
import { join, dirname, basename } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { execSync } from 'child_process';
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const TEMPLATES_DIR = join(__dirname, '../templates');
|
|
8
|
-
const ROOT_FILES = ['.env.template', 'tsconfig.json', 'tsconfig.test.json', 'jest.config.ts', '
|
|
8
|
+
const ROOT_FILES = ['.env.template', 'tsconfig.json', 'tsconfig.test.json', 'jest.config.ts', 'README.md', 'GUIDE.md'];
|
|
9
9
|
export const initCommand = new Command('init')
|
|
10
10
|
.description('Scaffold a new dtk project in the current directory')
|
|
11
|
-
.
|
|
11
|
+
.argument('[name]', 'project name (defaults to the current directory name)')
|
|
12
|
+
.action(async (name) => {
|
|
12
13
|
const initDir = join(TEMPLATES_DIR, 'init');
|
|
13
14
|
const dest = process.cwd();
|
|
15
|
+
const projectName = name ?? basename(dest);
|
|
14
16
|
await cp(join(initDir, 'src'), join(dest, 'src'), { recursive: true });
|
|
15
17
|
await cp(join(initDir, 'gitignore'), join(dest, '.gitignore'));
|
|
16
18
|
for (const file of ROOT_FILES) {
|
|
17
19
|
await cp(join(initDir, file), join(dest, file));
|
|
18
20
|
}
|
|
21
|
+
const pkgRaw = await readFile(join(initDir, 'package.json'), 'utf8');
|
|
22
|
+
const pkg = JSON.parse(pkgRaw);
|
|
23
|
+
pkg.name = projectName;
|
|
24
|
+
await writeFile(join(dest, 'package.json'), JSON.stringify(pkg, null, 2) + '\n', 'utf8');
|
|
19
25
|
console.log('Project scaffolded. Installing dependencies...');
|
|
20
|
-
execSync('npm install', { cwd: dest, stdio: 'inherit' });
|
|
26
|
+
execSync('npm install --no-workspaces', { cwd: dest, stdio: 'inherit' });
|
|
21
27
|
});
|