@slvn/neon 1.0.2 → 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 +20 -13
- package/package.json +1 -1
package/bin/neon.js
CHANGED
|
@@ -4,16 +4,27 @@ 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
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
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');
|
|
10
21
|
|
|
11
22
|
const [, , command, projectName] = process.argv;
|
|
12
|
-
const script = fs.readFileSync(scriptPath, "utf-8");
|
|
13
|
-
const readme = fs.readFileSync(readmePath , "utf-8")
|
|
23
|
+
const script = fs.readFileSync(scriptPath, "utf-8");
|
|
24
|
+
const readme = fs.readFileSync(readmePath , "utf-8")
|
|
14
25
|
const cwd = process.cwd();
|
|
15
26
|
|
|
16
|
-
// --- FIN DES CORRECTIONS
|
|
27
|
+
// --- FIN DES CORRECTIONS ---
|
|
17
28
|
|
|
18
29
|
|
|
19
30
|
if (command === "create") {
|
|
@@ -41,8 +52,7 @@ if (command === "create") {
|
|
|
41
52
|
readme
|
|
42
53
|
);
|
|
43
54
|
|
|
44
|
-
//
|
|
45
|
-
// qui est censé être projectPath. Je le corrige pour être sûr.
|
|
55
|
+
// Fichier index.js copié dans le nouveau répertoire de projet
|
|
46
56
|
fs.writeFileSync(path.join(projectPath, "index.js"), script);
|
|
47
57
|
|
|
48
58
|
console.log(chalk.green("\n Projet", projectName, "crée \n"));
|
|
@@ -54,21 +64,18 @@ if (command === "create") {
|
|
|
54
64
|
if (command === "build") {
|
|
55
65
|
if (!projectName) {
|
|
56
66
|
console.log("\n Usage : neon build int.txt");
|
|
57
|
-
|
|
58
|
-
process.exit(1);
|
|
67
|
+
process.exit(1);
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
const intentPath = path.resolve(cwd, projectName);
|
|
62
|
-
|
|
63
|
-
const indexJs = path.join(cwd, "index.js");
|
|
64
|
-
|
|
71
|
+
const indexJs = path.join(cwd, "index.js"); // Le index.js de l'utilisateur
|
|
65
72
|
|
|
66
73
|
if (!fs.existsSync(intentPath)) {
|
|
67
74
|
console.log(chalk.red("\n Fichier d'intention spécifié introuvable"));
|
|
68
75
|
process.exit(1);
|
|
69
76
|
}
|
|
70
77
|
if (!fs.existsSync(indexJs)) {
|
|
71
|
-
console.log(chalk.red("Fichier 'index.js' introuvable dans le répertoire courant."));
|
|
78
|
+
console.log(chalk.red("Fichier 'index.js' introuvable dans le répertoire courant."));
|
|
72
79
|
process.exit(1);
|
|
73
80
|
}
|
|
74
81
|
|