@ilanalimanjs/open_pack 1.0.1 → 2.2.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.
Files changed (2) hide show
  1. package/bin/index.js +71 -14
  2. package/package.json +4 -2
package/bin/index.js CHANGED
@@ -1,36 +1,93 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'node:path';
3
+ import process from 'node:process';
3
4
  import { downloadTemplate } from 'giget';
5
+ import chalk from 'chalk';
6
+ import ora from 'ora';
4
7
 
5
8
  const TEMPLATE_SOURCE = 'github:DevIlannn/open_pack/Source';
9
+ const PACKAGE_COMMAND = 'npx @ilanalimanjs/open_pack@latest';
6
10
  const NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
7
11
 
8
12
  const [projectName] = process.argv.slice(2);
9
13
 
14
+ const accent = chalk.cyan;
15
+ const muted = chalk.gray;
16
+
17
+ const printHeader = () => {
18
+ console.log();
19
+ console.log(` ${chalk.bold('Open Pack')} ${muted('Fast starter for Node.js, Express, and PostgreSQL')}`);
20
+ console.log();
21
+ };
22
+
23
+ const printFailure = (title, detail) => {
24
+ console.log(` ${chalk.red('✖')} ${chalk.bold(title)}`);
25
+ if (detail) console.log(` ${muted(detail)}`);
26
+ console.log();
27
+ process.exitCode = 1;
28
+ };
29
+
30
+ const printUsage = () => {
31
+ console.log(` ${muted('Usage')}`);
32
+ console.log(` ${PACKAGE_COMMAND} ${accent('<project-name>')}`);
33
+ console.log();
34
+ console.log(` ${muted('Example')}`);
35
+ console.log(` ${PACKAGE_COMMAND} ${accent('my-project')}`);
36
+ console.log();
37
+ };
38
+
39
+ const printNextSteps = (name, startedAt) => {
40
+ const duration = ((performance.now() - startedAt) / 1000).toFixed(1);
41
+ const steps = [
42
+ `cd ${name}`,
43
+ 'npm install',
44
+ 'cp .env.examples .env',
45
+ 'npm run dev',
46
+ ];
47
+
48
+ console.log();
49
+ console.log(` ${chalk.green('✔')} ${chalk.bold(name)} is ready ${muted(`in ${duration}s`)}`);
50
+ console.log();
51
+ console.log(` ${muted('Next steps')}`);
52
+ steps.forEach((step, index) => {
53
+ console.log(` ${muted(`${index + 1}`)} ${accent(step)}`);
54
+ });
55
+ console.log();
56
+ console.log(` ${muted('Fill in')} DATABASE_URL ${muted('and')} SESSION_SECRET ${muted('inside .env before running.')}`);
57
+ console.log(` ${muted('Health check')} http://localhost:3000/api/health`);
58
+ console.log();
59
+ };
60
+
10
61
  async function main() {
62
+ printHeader();
63
+
11
64
  if (!projectName) {
12
- console.log('Usage: npx open_pack@latest <project-name>');
13
- process.exitCode = 1;
65
+ printFailure('Project name is required');
66
+ printUsage();
14
67
  return;
15
68
  }
16
69
 
17
70
  if (!NAME_PATTERN.test(projectName)) {
18
- console.error('Invalid project name. Use letters, numbers, dot, dash, or underscore.');
19
- process.exitCode = 1;
71
+ printFailure('Invalid project name', 'Use letters, numbers, dot, dash, or underscore.');
20
72
  return;
21
73
  }
22
74
 
23
75
  const targetDirectory = path.resolve(process.cwd(), projectName);
76
+ const startedAt = performance.now();
77
+ const spinner = ora({ text: `Creating ${chalk.bold(projectName)} from the Open Pack template`, indent: 2 }).start();
24
78
 
25
- console.log(`Creating ${projectName} from Open Pack...`);
26
- await downloadTemplate(TEMPLATE_SOURCE, { dir: targetDirectory });
27
-
28
- console.log(
29
- `\nDone. Next steps:\n\n cd ${projectName}\n npm install\n cp .env.examples .env\n npm run start\n`
30
- );
79
+ try {
80
+ await downloadTemplate(TEMPLATE_SOURCE, { dir: targetDirectory });
81
+ spinner.stop();
82
+ printNextSteps(projectName, startedAt);
83
+ } catch (error) {
84
+ spinner.stop();
85
+ const alreadyExists = /already exists/i.test(error.message);
86
+ printFailure(
87
+ alreadyExists ? 'Directory already exists' : 'Failed to create project',
88
+ alreadyExists ? `Choose another name or remove ${targetDirectory}` : error.message
89
+ );
90
+ }
31
91
  }
32
92
 
33
- main().catch((error) => {
34
- console.error(`Failed to create project: ${error.message}`);
35
- process.exitCode = 1;
36
- });
93
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilanalimanjs/open_pack",
3
- "version": "1.0.1",
3
+ "version": "2.2.4",
4
4
  "description": "Open Pack CLI: create a new project from the Open Pack source template",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,6 +20,8 @@
20
20
  "url": "git+https://github.com/DevIlannn/open_pack.git"
21
21
  },
22
22
  "dependencies": {
23
- "giget": "^2.0.0"
23
+ "giget": "^2.0.0",
24
+ "chalk": "^5.4.1",
25
+ "ora": "^8.1.1"
24
26
  }
25
27
  }