@svgrid/studio 0.1.1 → 0.1.3

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/cli.js CHANGED
@@ -14,6 +14,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
14
14
  import { dirname } from 'node:path';
15
15
  import { buildStudioBugReport, introspectDatabase, listDatabaseTables, parseProject, resolveSchemas, runStudioAdd, runStudioAddApp, summarizeVerify, } from '@svgrid/enterprise/studio';
16
16
  import { connect } from './db-connect.js';
17
+ import { DRIVER_FOR, installDriver, isDriverInstalled } from './driver-install.js';
17
18
  import { startDesignerServer } from './designer-server.js';
18
19
  const io = {
19
20
  readFile: async (path) => {
@@ -142,6 +143,34 @@ async function main() {
142
143
  process.stderr.write('svgrid-studio: --url is required with --db\n\n' + HELP);
143
144
  process.exit(1);
144
145
  }
146
+ // Studio detects the project's package manager and installs the driver for
147
+ // the user - they never need to know `pg`/`mysql2`/etc. must be present
148
+ // before --db works (mirrors the designer's "Install driver" flow).
149
+ const cwd = process.cwd();
150
+ if (!isDriverInstalled(opts.db, cwd)) {
151
+ const driver = DRIVER_FOR[opts.db];
152
+ process.stdout.write(`Installing ${driver} (required for --db ${opts.db})...\n`);
153
+ const result = await installDriver(opts.db, cwd);
154
+ if (!result.ok) {
155
+ process.stderr.write(`svgrid-studio: could not install "${driver}" automatically.\n${result.output}\n` +
156
+ `Run \`${result.manager} install ${driver}\` yourself and try again.\n`);
157
+ process.exit(1);
158
+ }
159
+ process.stdout.write(`Installed ${driver}.\n`);
160
+ // The install child process can report success before the new module is
161
+ // reliably resolvable (seen on Windows - antivirus/file-sync tools can
162
+ // briefly hold the just-written files). Poll rather than racing straight
163
+ // into connect(), which would resolve the driver too early and crash.
164
+ const deadline = Date.now() + 5000;
165
+ while (!isDriverInstalled(opts.db, cwd) && Date.now() < deadline) {
166
+ await new Promise((r) => setTimeout(r, 200));
167
+ }
168
+ if (!isDriverInstalled(opts.db, cwd)) {
169
+ process.stderr.write(`svgrid-studio: installed "${driver}" but it's still not resolvable from this directory.\n` +
170
+ `Something (antivirus, a file-sync tool) may be holding a lock on the new files. Try running the command again.\n`);
171
+ process.exit(1);
172
+ }
173
+ }
145
174
  const execute = await connect(opts.db, opts.url);
146
175
  // A dialect dataSource emits a fully-connected +server.ts (driver + DATABASE_URL);
147
176
  // --sql keeps the generic execute() stub instead.
@@ -31,17 +31,22 @@ export function detectPackageManager(cwd) {
31
31
  return 'bun';
32
32
  return 'npm';
33
33
  }
34
- /** The install args to add `pkg` as a dev dependency for a given manager. */
34
+ /**
35
+ * The install args to add `pkg` as a regular dependency for a given manager.
36
+ * A regular dependency, not dev - the generated `+server.ts` imports the
37
+ * driver at module scope (see `DRIVERS` in `@svgrid/enterprise/studio`'s
38
+ * `scaffold.ts`), so it must survive a production `--omit=dev` install.
39
+ */
35
40
  export function installArgs(pm, pkg) {
36
41
  switch (pm) {
37
42
  case 'pnpm':
38
- return ['add', '-D', pkg];
43
+ return ['add', pkg];
39
44
  case 'yarn':
40
- return ['add', '--dev', pkg];
45
+ return ['add', pkg];
41
46
  case 'bun':
42
- return ['add', '-d', pkg];
47
+ return ['add', pkg];
43
48
  default:
44
- return ['install', '--save-dev', pkg];
49
+ return ['install', '--save', pkg];
45
50
  }
46
51
  }
47
52
  /** Is the driver already resolvable from the project? (skip a needless install). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svgrid/studio",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "SvGrid Studio CLI: scaffold a full CRUD screen (grid + edit panel + SvelteKit API route) from a Drizzle schema in one command.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "jQWidgets <sales@jqwidgets.com>",