schematic-pg 0.1.1 → 0.1.2
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/README.md +1 -2
- package/dist/cli/init.js +26 -1
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,7 +196,6 @@ Install the CLI and scaffold a new project:
|
|
|
196
196
|
```bash
|
|
197
197
|
npx schematic-pg init my-app
|
|
198
198
|
cd my-app
|
|
199
|
-
npm install
|
|
200
199
|
```
|
|
201
200
|
|
|
202
201
|
Edit `app.schema`, then generate code and start the API:
|
|
@@ -261,7 +260,7 @@ The `schematic-pg` binary is the primary interface. Each command accepts an opti
|
|
|
261
260
|
### Project setup
|
|
262
261
|
|
|
263
262
|
```bash
|
|
264
|
-
schematic-pg init [dir]
|
|
263
|
+
schematic-pg init [dir] [--skip-install] # Scaffold a new project (runs npm install by default)
|
|
265
264
|
```
|
|
266
265
|
|
|
267
266
|
### Code generation
|
package/dist/cli/init.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import { PACKAGE_NAME } from '../constants.js';
|
|
2
3
|
import { existsSync } from 'node:fs';
|
|
3
4
|
import { mkdir, readdir, writeFile } from 'node:fs/promises';
|
|
@@ -17,7 +18,25 @@ function resolveTargetDir(args) {
|
|
|
17
18
|
function resolveProjectName(targetDir) {
|
|
18
19
|
return path.basename(targetDir) || `${PACKAGE_NAME}-app`;
|
|
19
20
|
}
|
|
21
|
+
function runNpmInstall(cwd) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const child = spawn('npm', ['install'], {
|
|
24
|
+
cwd,
|
|
25
|
+
stdio: 'inherit',
|
|
26
|
+
shell: process.platform === 'win32',
|
|
27
|
+
});
|
|
28
|
+
child.on('error', reject);
|
|
29
|
+
child.on('close', (code) => {
|
|
30
|
+
if (code === 0) {
|
|
31
|
+
resolve();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
reject(new Error(`npm install failed with exit code ${code}`));
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
20
38
|
export async function runInit(args) {
|
|
39
|
+
const skipInstall = args.includes('--skip-install');
|
|
21
40
|
const targetDir = resolveTargetDir(args);
|
|
22
41
|
const projectName = resolveProjectName(targetDir);
|
|
23
42
|
if (targetDir !== process.cwd() && existsSync(targetDir)) {
|
|
@@ -45,11 +64,17 @@ export async function runInit(args) {
|
|
|
45
64
|
else {
|
|
46
65
|
console.log('Skipped existing file: package.json');
|
|
47
66
|
}
|
|
67
|
+
if (!skipInstall) {
|
|
68
|
+
console.log('\nRunning npm install...');
|
|
69
|
+
await runNpmInstall(targetDir);
|
|
70
|
+
}
|
|
48
71
|
console.log('\nNext steps:');
|
|
49
72
|
if (targetDir !== process.cwd()) {
|
|
50
73
|
console.log(` cd ${targetDir}`);
|
|
51
74
|
}
|
|
52
|
-
|
|
75
|
+
if (skipInstall) {
|
|
76
|
+
console.log(' npm install');
|
|
77
|
+
}
|
|
53
78
|
console.log(' docker compose up -d');
|
|
54
79
|
console.log(` npx ${PACKAGE_NAME} generate`);
|
|
55
80
|
console.log(` npx ${PACKAGE_NAME} db:bootstrap`);
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { PACKAGE_NAME } from './constants.js';
|
|
|
7
7
|
const USAGE = `Usage: ${PACKAGE_NAME} <command> [options]
|
|
8
8
|
|
|
9
9
|
Commands:
|
|
10
|
-
init [dir]
|
|
10
|
+
init [dir] [--skip-install] Scaffold a new project
|
|
11
11
|
generate [schema] Generate schema.sql, db client, and API
|
|
12
12
|
generate:sql [schema] Generate SQL DDL to stdout
|
|
13
13
|
generate:client [schema] Generate db client files
|