adminforth 2.25.0-next.7 → 2.25.0-next.8

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.
@@ -16,7 +16,8 @@ async function bundle() {
16
16
  `);
17
17
 
18
18
  } catch (e) {
19
- console.log(`Running budndle failed`, e);
19
+ console.log(`Running bundle failed`, e);
20
+ throw new Error(`Failed to bundle admin SPA: ${e.message}`);
20
21
  }
21
22
  }
22
23
 
@@ -1,3 +1,14 @@
1
+
2
+ {{#unless useNpm}}
3
+ FROM devforth/node20-pnpm:latest
4
+ WORKDIR /code/
5
+ ADD package.json pnpm-lock.yaml pnpm-workspace.yaml /code/
6
+ RUN pnpm i
7
+ ADD . /code/
8
+ RUN pnpm exec adminforth bundle
9
+ CMD ["sh", "-c", "pnpm migrate:prod && pnpm prod"]
10
+ {{/unless}}
11
+ {{#if useNpm}}
1
12
  FROM node:{{nodeMajor}}-slim
2
13
  WORKDIR /code/
3
14
  ADD package.json package-lock.json /code/
@@ -5,3 +16,4 @@ RUN npm ci
5
16
  ADD . /code/
6
17
  RUN npx adminforth bundle
7
18
  CMD ["sh", "-c", "npm run migrate:prod && npm run prod"]
19
+ {{/if}}
@@ -8,14 +8,26 @@
8
8
  "license": "ISC",
9
9
  "description": "",
10
10
  "scripts": {
11
- "dev": "npm run _env:dev -- tsx watch index.ts",
12
- "prod": "npm run _env:prod -- tsx index.ts",
13
- "start": "npm run dev",
14
- "makemigration": "npm run _env:dev -- npx --yes prisma migrate dev --create-only",
15
- "migrate:local": "npm run _env:dev -- npx --yes prisma migrate deploy",
16
- "migrate:prod": "npm run _env:prod -- npx --yes prisma migrate deploy",
11
+ {{#unless useNpm}}
12
+ "dev": "pnpm _env:dev tsx watch index.ts",
13
+ "prod": "pnpm _env:prod tsx index.ts",
14
+ "start": "pnpm dev",
15
+ "makemigration": "pnpm _env:dev npx --yes prisma migrate dev --create-only",
16
+ "migrate:local": "pnpm _env:dev npx --yes prisma migrate deploy",
17
+ "migrate:prod": "pnpm _env:prod npx --yes prisma migrate deploy",
17
18
  "_env:dev": "dotenvx run -f .env -f .env.local --",
18
19
  "_env:prod": "dotenvx run -f .env.prod --"
20
+ {{/unless}}
21
+ {{#if useNpm}}
22
+ "dev": "npm run _env:dev -- tsx watch index.ts",
23
+ "prod": "npm run _env:prod -- tsx index.ts",
24
+ "start": "npm run dev",
25
+ "makemigration": "npm run _env:dev -- npx --yes prisma migrate dev --create-only",
26
+ "migrate:local": "npm run _env:dev -- npx --yes prisma migrate deploy",
27
+ "migrate:prod": "npm run _env:prod -- npx --yes prisma migrate deploy",
28
+ "_env:dev": "dotenvx run -f .env -f .env.local --",
29
+ "_env:prod": "dotenvx run -f .env.prod --"
30
+ {{/if}}
19
31
  },
20
32
  "engines": {
21
33
  "node": ">=20"
@@ -0,0 +1,8 @@
1
+ lockfileVersion: '9.0'
2
+
3
+ settings:
4
+ autoInstallPeers: true
5
+ excludeLinksFromLockfile: false
6
+
7
+ importers:
8
+ .: {}
@@ -0,0 +1,2 @@
1
+ onlyBuiltDependencies:
2
+ - better-sqlite3
@@ -1,9 +1,9 @@
1
1
  ## Starting the application
2
2
 
3
3
  Install dependencies:
4
-
4
+ {{#if useNpm}}
5
5
  ```bash
6
- npm ci
6
+ npm i
7
7
  ```
8
8
 
9
9
  Migrate the database:
@@ -17,6 +17,25 @@ Start the server:
17
17
  ```bash
18
18
  npm run dev
19
19
  ```
20
+ {{/if}}
21
+
22
+ {{#unless useNpm}}
23
+ ```bash
24
+ pnpm i
25
+ ```
26
+
27
+ Migrate the database:
28
+
29
+ ```bash
30
+ pnpm migrate:local
31
+ ```
32
+
33
+ Start the server:
34
+
35
+ ```bash
36
+ pnpm dev
37
+ ```
38
+ {{/unless}}
20
39
 
21
40
  {{#if prismaDbUrl}}
22
41
  ## Changing schema
@@ -26,10 +45,10 @@ Open `schema.prisma` and change schema as needed: add new tables, columns, etc (
26
45
  Run the following command to generate a new migration and apply it instantly in local database:
27
46
 
28
47
  ```bash
29
- npm run makemigration -- --name <name_of_changes>
48
+ pnpm makemigration --name <name_of_changes>
30
49
  ```
31
50
 
32
- Your colleagues will need to pull the changes and run `npm run migrateLocal` to apply the migration in their local database.
51
+ Your colleagues will need to pull the changes and run `pnpm migrate:local` to apply the migration in their local database.
33
52
  {{/if}}
34
53
 
35
54
  ## Deployment tips
@@ -44,6 +44,7 @@ export function parseArgumentsIntoOptions(rawArgs) {
44
44
  {
45
45
  '--app-name': String,
46
46
  '--db': String,
47
+ '--use-npm': Boolean,
47
48
  // you can add more flags here if needed
48
49
  },
49
50
  {
@@ -54,6 +55,7 @@ export function parseArgumentsIntoOptions(rawArgs) {
54
55
  return {
55
56
  appName: args['--app-name'],
56
57
  db: args['--db'],
58
+ useNpm: args['--use-npm'],
57
59
  };
58
60
  }
59
61
 
@@ -78,11 +80,25 @@ export async function promptForMissingOptions(options) {
78
80
  });
79
81
  };
80
82
 
83
+ if (!options.useNpm) {
84
+ questions.push({
85
+ type: 'select',
86
+ name: 'useNpm',
87
+ message: 'Select your package manager ->',
88
+ choices: [
89
+ { name: 'pnpm', value: false },
90
+ { name: 'npm', value: true },
91
+ ],
92
+ default: false,
93
+ });
94
+ }
95
+
81
96
  const answers = await inquirer.prompt(questions);
82
97
  return {
83
98
  ...options,
84
99
  appName: options.appName || answers.appName,
85
100
  db: options.db || answers.db,
101
+ useNpm: options.useNpm || answers.useNpm,
86
102
  };
87
103
  }
88
104
 
@@ -230,7 +246,7 @@ async function scaffoldProject(ctx, options, cwd) {
230
246
  await fse.copy(sourceAssetsDir, targetAssetsDir);
231
247
 
232
248
  // Write templated files
233
- await writeTemplateFiles(dirname, projectDir, {
249
+ await writeTemplateFiles(dirname, projectDir, options.useNpm, {
234
250
  dbUrl: connectionString.toString(),
235
251
  dbUrlProd: connectionStringProd,
236
252
  prismaDbUrl,
@@ -244,7 +260,7 @@ async function scaffoldProject(ctx, options, cwd) {
244
260
  return projectDir; // Return the new directory path
245
261
  }
246
262
 
247
- async function writeTemplateFiles(dirname, cwd, options) {
263
+ async function writeTemplateFiles(dirname, cwd, useNpm, options) {
248
264
  const {
249
265
  dbUrl, prismaDbUrl, appName, provider, nodeMajor,
250
266
  dbUrlProd, prismaDbUrlProd, sqliteFile
@@ -268,14 +284,6 @@ async function writeTemplateFiles(dirname, cwd, options) {
268
284
  dest: 'prisma.config.ts',
269
285
  data: {},
270
286
  },
271
- {
272
- src: 'package.json.hbs',
273
- dest: 'package.json',
274
- data: {
275
- appName,
276
- adminforthVersion: adminforthVersion,
277
- },
278
- },
279
287
  {
280
288
  src: 'index.ts.hbs',
281
289
  dest: 'index.ts',
@@ -304,7 +312,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
304
312
  {
305
313
  src: 'readme.md.hbs',
306
314
  dest: 'README.md',
307
- data: { dbUrl, prismaDbUrl, appName, sqliteFile },
315
+ data: { dbUrl, prismaDbUrl, appName, sqliteFile, useNpm },
308
316
  },
309
317
  {
310
318
  // We'll write .env using the same content as .env.sample
@@ -317,30 +325,54 @@ async function writeTemplateFiles(dirname, cwd, options) {
317
325
  dest: 'resources/adminuser.ts',
318
326
  data: {},
319
327
  },
320
- {
321
- src: 'custom/package.json.hbs',
322
- dest: 'custom/package.json',
323
- data: {},
324
- },
325
328
  {
326
329
  src: 'custom/tsconfig.json.hbs',
327
330
  dest: 'custom/tsconfig.json',
328
331
  data: {},
329
332
  },
330
- {
331
- src: 'Dockerfile.hbs',
332
- dest: 'Dockerfile',
333
- data: { nodeMajor },
334
- },
335
333
  {
336
334
  src: '.dockerignore.hbs',
337
335
  dest: '.dockerignore',
338
336
  data: {
339
337
  sqliteFile,
340
338
  },
339
+ },
340
+ {
341
+ src: 'Dockerfile.hbs',
342
+ dest: 'Dockerfile',
343
+ data: { nodeMajor, useNpm },
344
+ },
345
+ {
346
+ src: 'package.json.hbs',
347
+ dest: 'package.json',
348
+ data: {
349
+ appName,
350
+ adminforthVersion: adminforthVersion,
351
+ useNpm
352
+ },
353
+ },
354
+ {
355
+ src: 'custom/package.json.hbs',
356
+ dest: 'custom/package.json',
357
+ data: {}
341
358
  }
342
359
  ];
343
360
 
361
+ if (!useNpm) {
362
+ templateTasks.push(
363
+ {
364
+ src: 'pnpm_templates/pnpm-workspace.yaml.hbs',
365
+ dest: 'pnpm-workspace.yaml',
366
+ data: {},
367
+ },
368
+ {
369
+ src: 'pnpm_templates/pnpm-lock.yaml.hbs',
370
+ dest: 'custom/pnpm-lock.yaml',
371
+ data: {},
372
+ }
373
+ )
374
+ }
375
+
344
376
  for (const task of templateTasks) {
345
377
  // If a condition is specified and false, skip this file
346
378
  if (task.condition === false) continue;
@@ -358,7 +390,26 @@ async function writeTemplateFiles(dirname, cwd, options) {
358
390
  }
359
391
  }
360
392
 
361
- async function installDependencies(ctx, cwd) {
393
+ async function installDependenciesPnpm(ctx, cwd) {
394
+ const isWindows = process.platform === 'win32';
395
+
396
+ const nodeBinary = process.execPath;
397
+ const npmPath = path.join(path.dirname(nodeBinary), isWindows ? 'pnpm.cmd' : 'pnpm');
398
+ const customDir = ctx.customDir;
399
+ if (isWindows) {
400
+ const res = await Promise.all([
401
+ await execAsync(`pnpm install`, { cwd, env: { PATH: process.env.PATH } }),
402
+ await execAsync(`pnpm install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
403
+ ]);
404
+ } else {
405
+ const res = await Promise.all([
406
+ await execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
407
+ await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
408
+ ]);
409
+ }
410
+ }
411
+
412
+ async function installDependenciesNpm(ctx, cwd) {
362
413
  const isWindows = process.platform === 'win32';
363
414
 
364
415
  const nodeBinary = process.execPath;
@@ -375,10 +426,30 @@ async function installDependencies(ctx, cwd) {
375
426
  await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
376
427
  ]);
377
428
  }
378
- // console.log(chalk.dim(`Dependencies installed in ${cwd} and ${customDir}: \n${res[0].stdout}${res[1].stdout}`));
379
429
  }
380
430
 
381
- function generateFinalInstructions(skipPrismaSetup, options) {
431
+ function generateFinalInstructionsPnpm(skipPrismaSetup, options) {
432
+ let instruction = '⏭️ Run the following commands to get started:\n';
433
+ if (!skipPrismaSetup)
434
+ instruction += `
435
+ ${chalk.dim('// Go to the project directory')}
436
+ ${chalk.dim('$')}${chalk.cyan(` cd ${options.appName}`)}\n`;
437
+
438
+ instruction += `
439
+ ${chalk.dim('// Generate and apply initial migration')}
440
+ ${chalk.dim('$')}${chalk.cyan(' pnpm makemigration --name init && pnpm migrate:local')}\n`;
441
+
442
+ instruction += `
443
+ ${chalk.dim('// Start dev server with tsx watch for hot-reloading')}
444
+ ${chalk.dim('$')}${chalk.cyan(' pnpm dev')}\n
445
+ `;
446
+
447
+ instruction += '😉 Happy coding!';
448
+
449
+ return instruction;
450
+ }
451
+
452
+ function generateFinalInstructionsNpm(skipPrismaSetup, options) {
382
453
  let instruction = '⏭️ Run the following commands to get started:\n';
383
454
  if (!skipPrismaSetup)
384
455
  instruction += `
@@ -425,13 +496,23 @@ export function prepareWorkflow(options) {
425
496
  },
426
497
  {
427
498
  title: '📦 Installing dependencies...',
428
- task: async (ctx) => installDependencies(ctx, ctx.projectDir)
499
+ task: async (ctx) => {
500
+ if (options.useNpm) {
501
+ await installDependenciesNpm(ctx, ctx.projectDir);
502
+ } else {
503
+ await installDependenciesPnpm(ctx, ctx.projectDir);
504
+ }
505
+ }
429
506
  },
430
507
  {
431
508
  title: '📝 Preparing final instructions...',
432
509
  task: (ctx) => {
433
510
  console.log(chalk.green(`✅ Successfully created your new Adminforth project in ${ctx.projectDir}!\n`));
434
- console.log(generateFinalInstructions(ctx.skipPrismaSetup, options));
511
+ if (options.useNpm) {
512
+ console.log(generateFinalInstructionsNpm(ctx.skipPrismaSetup, options));
513
+ } else {
514
+ console.log(generateFinalInstructionsPnpm(ctx.skipPrismaSetup, options));
515
+ }
435
516
  console.log('\n\n');
436
517
  }
437
518
  }
@@ -158,8 +158,8 @@ async function installDependencies(ctx, cwd) {
158
158
  const customDir = ctx.customDir;
159
159
 
160
160
  await Promise.all([
161
- await execa("npm", ["install", "--no-package-lock"], { cwd }),
162
- await execa("npm", ["install"], { cwd: customDir }),
161
+ await execa("pnpm", ["install"], { cwd }),
162
+ await execa("pnpm", ["install"], { cwd: customDir }),
163
163
  ]);
164
164
  }
165
165
 
@@ -168,15 +168,14 @@ function generateFinalInstructions() {
168
168
 
169
169
  instruction += `
170
170
  ${chalk.dim("// Build your plugin")}
171
- ${chalk.cyan("$ npm run build")}\n`;
171
+ ${chalk.cyan("$ pnpm build")}\n`;
172
172
 
173
173
  instruction += `
174
174
  ${chalk.dim("// To test your plugin locally")}
175
- ${chalk.cyan("$ npm link")}\n`;
176
-
175
+ ${chalk.cyan("$ pnpm link")}\n`;
177
176
  instruction += `
178
177
  ${chalk.dim("// In your AdminForth project")}
179
- ${chalk.cyan("$ npm link " + chalk.italic("your-plugin-name"))}\n`;
178
+ ${chalk.cyan("$ pnpm link " + chalk.italic("your-plugin-name"))}\n`;
180
179
 
181
180
  instruction += "\n😉 Happy coding!";
182
181
 
@@ -7,7 +7,7 @@ const spaPath = path.join(import.meta.dirname, 'dist', 'spa');
7
7
 
8
8
  if (fs.existsSync(spaPath)){
9
9
  console.log('Installing SPA dependencies...');
10
- execSync('npm ci', { cwd: spaPath, stdio: 'inherit' });
10
+ execSync('pnpm i', { cwd: spaPath, stdio: 'inherit' });
11
11
  console.log('Installed spa dependencies');
12
12
  } else {
13
13
  console.log('SPA dependencies not found');
@@ -15,7 +15,8 @@ declare class CodeInjector implements ICodeInjector {
15
15
  registerCustomComponent(filePath: string): void;
16
16
  cleanup(): void;
17
17
  constructor(adminforth: any);
18
- runNpmShell({ command, cwd, envOverrides }: {
18
+ doesUserHasPnpmLockFile(dir: string): Promise<boolean>;
19
+ runPackageManagerShell({ command, cwd, envOverrides }: {
19
20
  command: string;
20
21
  cwd: string;
21
22
  envOverrides?: {
@@ -24,7 +25,7 @@ declare class CodeInjector implements ICodeInjector {
24
25
  }): Promise<void>;
25
26
  rmTmpDir(): Promise<void>;
26
27
  getServeDir(): string;
27
- packagesFromNpm(dir: string): Promise<[string, string[]]>;
28
+ packagesFromPnpm(dir: string): Promise<[string, string[]]>;
28
29
  getSpaDir(): string;
29
30
  updatePartials({ filesUpdated }: {
30
31
  filesUpdated: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"codeInjector.d.ts","sourceRoot":"","sources":["../../modules/codeInjector.ts"],"names":[],"mappings":"AAOA,OAAO,UAAwC,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAmEjD,cAAM,YAAa,YAAW,aAAa;IAEzC,WAAW,QAAM;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;IAClD,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;IACjD,aAAa,EAAE,MAAM,CAAQ;IAE7B,UAAU,IAAI,MAAM;IAQd,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;IA8BpC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAK/C,OAAO;gBAMK,UAAU,KAAA;IAWhB,WAAW,CAAC,EAAC,OAAO,EAAE,GAAG,EAAE,YAAiB,EAAC,EAAE;QACnD,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,YAAY,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KACzC;IA+CK,QAAQ;IAUd,WAAW;IAIL,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAyC/D,SAA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