@slvn/neon 1.0.0 → 1.0.3
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 +67 -48
- package/package.json +1 -1
package/bin/neon.js
CHANGED
|
@@ -1,68 +1,87 @@
|
|
|
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
|
+
import { fileURLToPath } from 'url'; // Ajout nécessaire pour ESM
|
|
8
|
+
|
|
9
|
+
// --- CORRECTION DES CHEMINS ---
|
|
10
|
+
|
|
11
|
+
// 1. Détermine le chemin absolu du répertoire où le script est exécuté (bin)
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
|
|
15
|
+
// 2. Détermine le chemin absolu de la racine du package (un niveau au-dessus de 'bin')
|
|
16
|
+
const packageRoot = path.join(__dirname, '..');
|
|
17
|
+
|
|
18
|
+
// 3. Lit les fichiers internes en utilisant les chemins absolus
|
|
19
|
+
const scriptPath = path.join(packageRoot, 'index.js');
|
|
20
|
+
const readmePath = path.join(packageRoot, 'readme.md');
|
|
7
21
|
|
|
8
22
|
const [, , command, projectName] = process.argv;
|
|
9
|
-
const script = fs.readFileSync(
|
|
10
|
-
const readme = fs.readFileSync(
|
|
23
|
+
const script = fs.readFileSync(scriptPath, "utf-8");
|
|
24
|
+
const readme = fs.readFileSync(readmePath , "utf-8")
|
|
11
25
|
const cwd = process.cwd();
|
|
12
26
|
|
|
27
|
+
// --- FIN DES CORRECTIONS ---
|
|
28
|
+
|
|
29
|
+
|
|
13
30
|
if (command === "create") {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
if (!projectName) {
|
|
32
|
+
console.log("\n Usage : neon create <project name>");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
const projectPath = path.join(cwd, projectName);
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
if (fs.existsSync(projectPath)) {
|
|
39
|
+
console.log(chalk.green("\n Projet existant veuillez le supprimez ou choisir un autre nom de projet"))
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
fs.mkdirSync(projectPath);
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
path.join(projectPath, "int.txt"),
|
|
47
|
+
"Entrez la description de votre site a concevoir"
|
|
48
|
+
);
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
fs.writeFileSync(
|
|
51
|
+
path.join(projectPath, "readme.md"),
|
|
52
|
+
readme
|
|
53
|
+
);
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
// Fichier index.js copié dans le nouveau répertoire de projet
|
|
56
|
+
fs.writeFileSync(path.join(projectPath, "index.js"), script);
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
console.log(chalk.green("\n Projet", projectName, "crée \n"));
|
|
59
|
+
console.log(" Entrez : cd" , chalk.bgBlue(projectName) , "\n")
|
|
60
|
+
console.log(chalk.gray(" Editez la description de votre site dans int.txt ou autre fichier.txt \n"))
|
|
61
|
+
console.log(chalk.green(" Lancez le build avec : neon build int.txt ou le nom de votre fichier.txt \n"))
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
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
|
-
|
|
65
|
+
if (!projectName) {
|
|
66
|
+
console.log("\n Usage : neon build int.txt");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const intentPath = path.resolve(cwd, projectName);
|
|
71
|
+
const indexJs = path.join(cwd, "index.js"); // Le index.js de l'utilisateur
|
|
72
|
+
|
|
73
|
+
if (!fs.existsSync(intentPath)) {
|
|
74
|
+
console.log(chalk.red("\n Fichier d'intention spécifié introuvable"));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
if (!fs.existsSync(indexJs)) {
|
|
78
|
+
console.log(chalk.red("Fichier 'index.js' introuvable dans le répertoire courant."));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
spawnSync("node", [indexJs, intentPath], {
|
|
83
|
+
stdio: "inherit",
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|