adminforth 2.25.0-test.10 → 2.25.0-test.12

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.
@@ -1,3 +1,5 @@
1
+
2
+ {{#unless useNpm}}
1
3
  FROM devforth/node20-pnpm:latest
2
4
  WORKDIR /code/
3
5
  ADD package.json pnpm-lock.yaml pnpm-workspace.yaml /code/
@@ -5,3 +7,13 @@ RUN pnpm i
5
7
  ADD . /code/
6
8
  RUN pnpm exec adminforth bundle
7
9
  CMD ["sh", "-c", "pnpm migrate:prod && pnpm prod"]
10
+ {{/unless}}
11
+ {{#if useNpm}}
12
+ FROM node:{{nodeMajor}}-slim
13
+ WORKDIR /code/
14
+ ADD package.json package-lock.json /code/
15
+ RUN npm ci
16
+ ADD . /code/
17
+ RUN npx adminforth bundle
18
+ CMD ["sh", "-c", "npm run migrate:prod && npm run prod"]
19
+ {{/if}}
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "custom",
3
+ "version": "1.0.0",
4
+ "main": "index.ts",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": ""
12
+ }
@@ -8,6 +8,7 @@
8
8
  "license": "ISC",
9
9
  "description": "",
10
10
  "scripts": {
11
+ {{#unless useNpm}}
11
12
  "dev": "pnpm _env:dev tsx watch index.ts",
12
13
  "prod": "pnpm _env:prod tsx index.ts",
13
14
  "start": "pnpm dev",
@@ -16,6 +17,17 @@
16
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"
@@ -1,7 +1,25 @@
1
1
  ## Starting the application
2
2
 
3
3
  Install dependencies:
4
+ {{#if useNpm}}
5
+ ```bash
6
+ npm i
7
+ ```
8
+
9
+ Migrate the database:
10
+
11
+ ```bash
12
+ npm run migrate:local
13
+ ```
14
+
15
+ Start the server:
16
+
17
+ ```bash
18
+ npm run dev
19
+ ```
20
+ {{/if}}
4
21
 
22
+ {{#unless useNpm}}
5
23
  ```bash
6
24
  pnpm i
7
25
  ```
@@ -17,6 +35,7 @@ Start the server:
17
35
  ```bash
18
36
  pnpm dev
19
37
  ```
38
+ {{/unless}}
20
39
 
21
40
  {{#if prismaDbUrl}}
22
41
  ## Changing schema
@@ -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,21 @@ export async function promptForMissingOptions(options) {
78
80
  });
79
81
  };
80
82
 
83
+ if (!options.useNpm) {
84
+ questions.push({
85
+ type: 'confirm',
86
+ name: 'useNpm',
87
+ message: 'Do you want to use npm instead of pnpm?',
88
+ default: false,
89
+ });
90
+ }
91
+
81
92
  const answers = await inquirer.prompt(questions);
82
93
  return {
83
94
  ...options,
84
95
  appName: options.appName || answers.appName,
85
96
  db: options.db || answers.db,
97
+ useNpm: options.useNpm || answers.useNpm,
86
98
  };
87
99
  }
88
100
 
@@ -230,7 +242,7 @@ async function scaffoldProject(ctx, options, cwd) {
230
242
  await fse.copy(sourceAssetsDir, targetAssetsDir);
231
243
 
232
244
  // Write templated files
233
- await writeTemplateFiles(dirname, projectDir, {
245
+ await writeTemplateFiles(dirname, projectDir, options.useNpm, {
234
246
  dbUrl: connectionString.toString(),
235
247
  dbUrlProd: connectionStringProd,
236
248
  prismaDbUrl,
@@ -244,7 +256,7 @@ async function scaffoldProject(ctx, options, cwd) {
244
256
  return projectDir; // Return the new directory path
245
257
  }
246
258
 
247
- async function writeTemplateFiles(dirname, cwd, options) {
259
+ async function writeTemplateFiles(dirname, cwd, useNpm, options) {
248
260
  const {
249
261
  dbUrl, prismaDbUrl, appName, provider, nodeMajor,
250
262
  dbUrlProd, prismaDbUrlProd, sqliteFile
@@ -268,14 +280,6 @@ async function writeTemplateFiles(dirname, cwd, options) {
268
280
  dest: 'prisma.config.ts',
269
281
  data: {},
270
282
  },
271
- {
272
- src: 'package.json.hbs',
273
- dest: 'package.json',
274
- data: {
275
- appName,
276
- adminforthVersion: adminforthVersion,
277
- },
278
- },
279
283
  {
280
284
  src: 'index.ts.hbs',
281
285
  dest: 'index.ts',
@@ -304,7 +308,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
304
308
  {
305
309
  src: 'readme.md.hbs',
306
310
  dest: 'README.md',
307
- data: { dbUrl, prismaDbUrl, appName, sqliteFile },
311
+ data: { dbUrl, prismaDbUrl, appName, sqliteFile, useNpm },
308
312
  },
309
313
  {
310
314
  // We'll write .env using the same content as .env.sample
@@ -322,11 +326,6 @@ async function writeTemplateFiles(dirname, cwd, options) {
322
326
  dest: 'custom/tsconfig.json',
323
327
  data: {},
324
328
  },
325
- {
326
- src: 'Dockerfile.hbs',
327
- dest: 'Dockerfile',
328
- data: { nodeMajor },
329
- },
330
329
  {
331
330
  src: '.dockerignore.hbs',
332
331
  dest: '.dockerignore',
@@ -335,12 +334,39 @@ async function writeTemplateFiles(dirname, cwd, options) {
335
334
  },
336
335
  },
337
336
  {
338
- src: 'pnpm-workspace.yaml.hbs',
339
- dest: 'pnpm-workspace.yaml',
340
- data: {},
341
- }
337
+ src: 'Dockerfile.hbs',
338
+ dest: 'Dockerfile',
339
+ data: { nodeMajor, useNpm },
340
+ },
341
+ {
342
+ src: 'package.json.hbs',
343
+ dest: 'package.json',
344
+ data: {
345
+ appName,
346
+ adminforthVersion: adminforthVersion,
347
+ useNpm
348
+ },
349
+ },
342
350
  ];
343
351
 
352
+ if (!useNpm) {
353
+ templateTasks.push(
354
+ {
355
+ src: 'pnpm_templates/pnpm-workspace.yaml.hbs',
356
+ dest: 'pnpm-workspace.yaml',
357
+ data: {},
358
+ },
359
+ )
360
+ } else {
361
+ templateTasks.push(
362
+ {
363
+ src: 'custom/package.json.hbs',
364
+ dest: 'custom/package.json',
365
+ data: {}
366
+ }
367
+ )
368
+ }
369
+
344
370
  for (const task of templateTasks) {
345
371
  // If a condition is specified and false, skip this file
346
372
  if (task.condition === false) continue;
@@ -358,7 +384,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
358
384
  }
359
385
  }
360
386
 
361
- async function installDependencies(ctx, cwd) {
387
+ async function installDependenciesPnpm(ctx, cwd) {
362
388
  const isWindows = process.platform === 'win32';
363
389
 
364
390
  const nodeBinary = process.execPath;
@@ -375,10 +401,28 @@ async function installDependencies(ctx, cwd) {
375
401
  await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
376
402
  ]);
377
403
  }
378
- // console.log(chalk.dim(`Dependencies installed in ${cwd} and ${customDir}: \n${res[0].stdout}${res[1].stdout}`));
379
404
  }
380
405
 
381
- function generateFinalInstructions(skipPrismaSetup, options) {
406
+ async function installDependenciesNpm(ctx, cwd) {
407
+ const isWindows = process.platform === 'win32';
408
+
409
+ const nodeBinary = process.execPath;
410
+ const npmPath = path.join(path.dirname(nodeBinary), isWindows ? 'npm.cmd' : 'npm');
411
+ const customDir = ctx.customDir;
412
+ if (isWindows) {
413
+ const res = await Promise.all([
414
+ await execAsync(`npm install`, { cwd, env: { PATH: process.env.PATH } }),
415
+ await execAsync(`npm install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
416
+ ]);
417
+ } else {
418
+ const res = await Promise.all([
419
+ await execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
420
+ await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
421
+ ]);
422
+ }
423
+ }
424
+
425
+ function generateFinalInstructionsPnpm(skipPrismaSetup, options) {
382
426
  let instruction = '⏭️ Run the following commands to get started:\n';
383
427
  if (!skipPrismaSetup)
384
428
  instruction += `
@@ -399,6 +443,27 @@ function generateFinalInstructions(skipPrismaSetup, options) {
399
443
  return instruction;
400
444
  }
401
445
 
446
+ function generateFinalInstructionsNpm(skipPrismaSetup, options) {
447
+ let instruction = '⏭️ Run the following commands to get started:\n';
448
+ if (!skipPrismaSetup)
449
+ instruction += `
450
+ ${chalk.dim('// Go to the project directory')}
451
+ ${chalk.dim('$')}${chalk.cyan(` cd ${options.appName}`)}\n`;
452
+
453
+ instruction += `
454
+ ${chalk.dim('// Generate and apply initial migration')}
455
+ ${chalk.dim('$')}${chalk.cyan(' npm run makemigration -- --name init && npm run migrate:local')}\n`;
456
+
457
+ instruction += `
458
+ ${chalk.dim('// Start dev server with tsx watch for hot-reloading')}
459
+ ${chalk.dim('$')}${chalk.cyan(' npm run dev')}\n
460
+ `;
461
+
462
+ instruction += '😉 Happy coding!';
463
+
464
+ return instruction;
465
+ }
466
+
402
467
  function renderHBSTemplate(templatePath, data) {
403
468
  // Example: renderHBRTemplate('path/to/template.hbs', {name: 'John Doe'})
404
469
  const template = fs.readFileSync(templatePath, 'utf-8');
@@ -425,13 +490,23 @@ export function prepareWorkflow(options) {
425
490
  },
426
491
  {
427
492
  title: '📦 Installing dependencies...',
428
- task: async (ctx) => installDependencies(ctx, ctx.projectDir)
493
+ task: async (ctx) => {
494
+ if (options.useNpm) {
495
+ await installDependenciesNpm(ctx, ctx.projectDir);
496
+ } else {
497
+ await installDependenciesPnpm(ctx, ctx.projectDir);
498
+ }
499
+ }
429
500
  },
430
501
  {
431
502
  title: '📝 Preparing final instructions...',
432
503
  task: (ctx) => {
433
504
  console.log(chalk.green(`✅ Successfully created your new Adminforth project in ${ctx.projectDir}!\n`));
434
- console.log(generateFinalInstructions(ctx.skipPrismaSetup, options));
505
+ if (options.useNpm) {
506
+ console.log(generateFinalInstructionsNpm(ctx.skipPrismaSetup, options));
507
+ } else {
508
+ console.log(generateFinalInstructionsPnpm(ctx.skipPrismaSetup, options));
509
+ }
435
510
  console.log('\n\n');
436
511
  }
437
512
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "2.25.0-test.10",
3
+ "version": "2.25.0-test.12",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -8,7 +8,7 @@
8
8
  "files": [
9
9
  "dist/**/*",
10
10
  "commands/**/*",
11
- "sctripts/**/*"
11
+ "scripts/**/*"
12
12
  ],
13
13
  "bin": {
14
14
  "adminforth": "./commands/cli.js"
@@ -0,0 +1,25 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const nodeBinary = process.execPath;
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const spaPath=path.join(__dirname,'dist','spa');
9
+
10
+ const pnpmPotentionalPath=path.join(nodeBinary,'..','pnpm');
11
+ const doesUserProjectHasPnpm = fs.existsSync(pnpmPotentionalPath)
12
+ console.log('doesUserProjectHasPnpm', doesUserProjectHasPnpm);
13
+ if (doesUserProjectHasPnpm) {
14
+ if(fs.existsSync(spaPath) && !process.env.PNPM_INSTALL_SPA){
15
+ process.env.PNPM_INSTALL_SPA=1;
16
+ require('child_process').execSync('pnpm install --frozen-lockfile',{cwd:spaPath,stdio:'inherit'});
17
+ }
18
+ } else {
19
+ if(fs.existsSync(spaPath)){
20
+ process.chdir(spaPath);
21
+ require('child_process').execSync('npm ci',{stdio:'inherit'});
22
+ }
23
+ }
24
+
25
+ console.log('installed spa dependencies');