run-devs-start 0.0.0-stage → 1.0.0
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/cli.js +120 -0
- package/package.json +17 -4
- package/README.md +0 -3
package/cli.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import inquirer from 'inquirer';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
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
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await showLoadingBar('Initializing...', 1000);
|
|
32
|
+
|
|
33
|
+
const title = `
|
|
34
|
+
\x1b[0;97;47m▀\x1b[0;96m▀\x1b[0;36m▀▀▄\x1b[0;37m \x1b[0;97;47m▀\x1b[0;96m \x1b[0;36;47m▄\x1b[0;37m \x1b[0;97;47m▀\x1b[0;36m▄\x1b[0;96m \x1b[0;36;47m▄\x1b[0;37m \x1b[0;96m \x1b[0;37m \x1b[0;97;47m▀\x1b[0;96m▀\x1b[0;36m▀▀▄\x1b[0;37m \x1b[0;97m▄▀\x1b[0;96m▀\x1b[0;36m▀█\x1b[0;37m \x1b[0;97;47m▀\x1b[0;96m \x1b[0;36;47m▄\x1b[0;37m \x1b[0;97m▄▀\x1b[0;96m▀\x1b[0;36m▀▀\x1b[0m
|
|
35
|
+
\x1b[0;36m█▀▀▀▄\x1b[0;37m \x1b[0;36m█\x1b[0;96m \x1b[0;36m█\x1b[0;37m \x1b[0;36m█\x1b[0;96m \x1b[0;36m▀▄█\x1b[0;37m \x1b[0;97m▀\x1b[0;96m▀\x1b[0;37m \x1b[0;36m█\x1b[0;96m \x1b[0;36m█\x1b[0;37m \x1b[0;36;47m▄\x1b[0;36m▀▀\x1b[0;96m ▄\x1b[0;37m \x1b[0;36m▀▄\x1b[0;96m \x1b[0;36m▄▀\x1b[0;37m \x1b[0;96m▀\x1b[0;36m▀▀▀█\x1b[0m
|
|
36
|
+
\x1b[0;36m▀\x1b[0;96m \x1b[0;36m▀\x1b[0;37m \x1b[0;96m \x1b[0;36m▀▀▀\x1b[0;96m \x1b[0;37m \x1b[0;36m▀\x1b[0;96m \x1b[0;36m▀\x1b[0;37m \x1b[0;36m▀▀▀▀\x1b[0;96m \x1b[0;37m \x1b[0;96m \x1b[0;36m▀▀▀▀\x1b[0;37m \x1b[0;96m \x1b[0;36m▀\x1b[0;96m \x1b[0;37m \x1b[0;96m▀\x1b[0;36m▀▀▀\x1b[0;96m \x1b[0m
|
|
37
|
+
|
|
38
|
+
\x1b[0;36mMade by Jhon Ladines\x1b[0m
|
|
39
|
+
\x1b[0;36mhttps://www.jhonladines.top/\x1b[0m
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
console.log(title);
|
|
43
|
+
|
|
44
|
+
const startJsPath = path.join(process.cwd(), 'start.js');
|
|
45
|
+
const indexPath = path.join(process.cwd(), 'index.html');
|
|
46
|
+
|
|
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
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
console.log('\x1b[33mSkipped. Run "node start.js" manually to start the server.\x1b[0m');
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
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
|
+
} else {
|
|
78
|
+
const startJsContent = `import https from 'https';
|
|
79
|
+
import fs from 'fs';
|
|
80
|
+
import path from 'path';
|
|
81
|
+
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()));
|
|
86
|
+
});
|
|
87
|
+
`;
|
|
88
|
+
|
|
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']
|
|
104
|
+
}
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "run-devs-start",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool to generate start.js for SPA development server",
|
|
5
|
+
"main": "cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"run-devs": "./cli.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node cli.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": ["spa", "dev", "server", "cli"],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"inquirer": "^9.2.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/README.md
DELETED