@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.
Files changed (2) hide show
  1. package/bin/neon.js +67 -48
  2. 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("./index.js", "utf-8");
10
- const readme = fs.readFileSync("./readme.md" , "utf-8")
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
- if (!projectName) {
15
- console.log("\n Usage : neon create <project name>");
16
- process.exit(1);
17
- }
31
+ if (!projectName) {
32
+ console.log("\n Usage : neon create <project name>");
33
+ process.exit(1);
34
+ }
18
35
 
19
- const projectPath = path.join(cwd, projectName);
36
+ const projectPath = path.join(cwd, projectName);
20
37
 
21
- if (fs.existsSync(projectPath)) {
22
- console.log(chalk.green("\n Projet existant veuillez le supprimez ou choisir un autre nom de projet"))
23
- process.exit(1);
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
- fs.mkdirSync(projectPath);
43
+ fs.mkdirSync(projectPath);
27
44
 
28
- fs.writeFileSync(
29
- path.join(projectPath, "int.txt"),
30
- "Entrez la description de votre site a concevoir"
31
- );
45
+ fs.writeFileSync(
46
+ path.join(projectPath, "int.txt"),
47
+ "Entrez la description de votre site a concevoir"
48
+ );
32
49
 
33
- fs.writeFileSync(
34
- path.join(projectPath, "readme.md"),
35
- readme
36
- );
50
+ fs.writeFileSync(
51
+ path.join(projectPath, "readme.md"),
52
+ readme
53
+ );
37
54
 
38
- fs.writeFileSync(path.join(projectName, "index.js"), script);
55
+ // Fichier index.js copié dans le nouveau répertoire de projet
56
+ fs.writeFileSync(path.join(projectPath, "index.js"), script);
39
57
 
40
- console.log(chalk.green("\n Projet", projectName, "crée \n"));
41
- console.log(" Entrez : cd" , chalk.bgBlue(projectName) , "\n")
42
- console.log(chalk.gray(" Editez la description de votre site dans int.txt ou autre fichier.txt \n"))
43
- console.log(chalk.green(" Lancez le build avec : neon build int.txt ou le nom de votre fichier.txt \n"))
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
- if (!projectName) {
48
- console.log("\n Usage : neon build int.txt");
49
- }
50
-
51
- const intentPath = path.resolve(cwd, projectName);
52
- const indexJs = path.join(cwd, "index.js");
53
-
54
- if (!fs.existsSync(intentPath)) {
55
- console.log(chalk.red("\n Fichier d'intention spécifié introuvable"));
56
- process.exit(1);
57
- }
58
- if (!fs.existsSync(indexJs)) {
59
- console.log(chalk.red("Introuvable"));
60
- process.exit(1);
61
- }
62
-
63
- spawnSync("node", [indexJs, intentPath], {
64
- stdio: "inherit",
65
- });
66
-
67
- process.exit(0);
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slvn/neon",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {