@slvn/neon 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.
- package/bin/neon.js +60 -48
- package/package.json +1 -1
package/bin/neon.js
CHANGED
|
@@ -1,68 +1,80 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { spawnSync } from "child_process";
|
|
6
6
|
import chalk from "chalk";
|
|
7
7
|
|
|
8
|
+
const scriptPath = require.resolve('@slvn/neon/index.js');
|
|
9
|
+
const readmePath = require.resolve('@slvn/neon/readme.md');
|
|
10
|
+
|
|
8
11
|
const [, , command, projectName] = process.argv;
|
|
9
|
-
const script = fs.readFileSync(
|
|
10
|
-
const readme = fs.readFileSync(
|
|
12
|
+
const script = fs.readFileSync(scriptPath, "utf-8"); // Utilisation du chemin absolu
|
|
13
|
+
const readme = fs.readFileSync(readmePath , "utf-8") // Utilisation du chemin absolu
|
|
11
14
|
const cwd = process.cwd();
|
|
12
15
|
|
|
16
|
+
// --- FIN DES CORRECTIONS POUR LES CHEMINS ---
|
|
17
|
+
|
|
18
|
+
|
|
13
19
|
if (command === "create") {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
if (!projectName) {
|
|
21
|
+
console.log("\n Usage : neon create <project name>");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
const projectPath = path.join(cwd, projectName);
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
if (fs.existsSync(projectPath)) {
|
|
28
|
+
console.log(chalk.green("\n Projet existant veuillez le supprimez ou choisir un autre nom de projet"))
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
fs.mkdirSync(projectPath);
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
fs.writeFileSync(
|
|
35
|
+
path.join(projectPath, "int.txt"),
|
|
36
|
+
"Entrez la description de votre site a concevoir"
|
|
37
|
+
);
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(projectPath, "readme.md"),
|
|
41
|
+
readme
|
|
42
|
+
);
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
// Attention: le fichier est écrit dans le dossier du projet (projectName),
|
|
45
|
+
// qui est censé être projectPath. Je le corrige pour être sûr.
|
|
46
|
+
fs.writeFileSync(path.join(projectPath, "index.js"), script);
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
console.log(chalk.green("\n Projet", projectName, "crée \n"));
|
|
49
|
+
console.log(" Entrez : cd" , chalk.bgBlue(projectName) , "\n")
|
|
50
|
+
console.log(chalk.gray(" Editez la description de votre site dans int.txt ou autre fichier.txt \n"))
|
|
51
|
+
console.log(chalk.green(" Lancez le build avec : neon build int.txt ou le nom de votre fichier.txt \n"))
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
if (command === "build") {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
if (!projectName) {
|
|
56
|
+
console.log("\n Usage : neon build int.txt");
|
|
57
|
+
// Sortie nécessaire si projectName est manquant pour 'build'
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const intentPath = path.resolve(cwd, projectName);
|
|
62
|
+
|
|
63
|
+
const indexJs = path.join(cwd, "index.js");
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if (!fs.existsSync(intentPath)) {
|
|
67
|
+
console.log(chalk.red("\n Fichier d'intention spécifié introuvable"));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
if (!fs.existsSync(indexJs)) {
|
|
71
|
+
console.log(chalk.red("Fichier 'index.js' introuvable dans le répertoire courant."));
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
spawnSync("node", [indexJs, intentPath], {
|
|
76
|
+
stdio: "inherit",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|