fbp-language 1.1.9 → 1.2.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/dist/cli.js DELETED
@@ -1,160 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_os_1 = __importDefault(require("node:os"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
- const compiler_1 = require("./compiler");
11
- const errors_1 = require("./errors");
12
- const VERSION = "1.1.9";
13
- function help() {
14
- console.log(`FBP — French Bot Programming
15
-
16
- Utilisation :
17
- fbp help Affiche cette aide
18
- fbp version Affiche la version de FBP
19
- fbp info Affiche les informations du moteur
20
- fbp ping Vérifie que le CLI répond
21
- fbp -init Prépare un projet FBP et le support VS Code
22
- fbp init Alias de -init
23
- fbp run <commande> Exécute une commande de commandes.fbp
24
- fbp run-file <fichier> Exécute directement un fichier .fbp`);
25
- }
26
- function ping() {
27
- console.log("FBP : opérationnel");
28
- console.log(`Version : ${VERSION}`);
29
- console.log(`Node.js : ${process.version}`);
30
- console.log("Bot : aucune connexion externe n'est configurée par le CLI seul.");
31
- }
32
- function initProject() {
33
- const root = process.cwd();
34
- const commandsPath = node_path_1.default.join(root, "commandes.fbp");
35
- const mainDir = node_path_1.default.join(root, "scripts");
36
- const mainPath = node_path_1.default.join(mainDir, "main.fbp");
37
- node_fs_1.default.mkdirSync(mainDir, { recursive: true });
38
- if (!node_fs_1.default.existsSync(commandsPath)) {
39
- node_fs_1.default.writeFileSync(commandsPath, JSON.stringify({ lancer: "scripts/main.fbp" }, null, 2) + "\n", "utf8");
40
- console.log("Créé : commandes.fbp");
41
- }
42
- else {
43
- console.log("Conservé : commandes.fbp existe déjà.");
44
- }
45
- if (!node_fs_1.default.existsSync(mainPath)) {
46
- node_fs_1.default.writeFileSync(mainPath, 'nom = "Mon projet"\n\nlance() {\n affiche("FBP fonctionne !")\n affiche("Projet :", nom)\n}\n\nlance()\n', "utf8");
47
- console.log("Créé : scripts/main.fbp");
48
- }
49
- else {
50
- console.log("Conservé : scripts/main.fbp existe déjà.");
51
- }
52
- installVscodeSupport();
53
- console.log("\nProjet FBP initialisé. Lance « fbp run lancer » pour exécuter le programme.");
54
- }
55
- function installVscodeSupport() {
56
- const bundledExtension = node_path_1.default.resolve(__dirname, "../vscode-extension");
57
- const manifestPath = node_path_1.default.join(bundledExtension, "package.json");
58
- if (!node_fs_1.default.existsSync(manifestPath)) {
59
- console.log("Support VS Code non trouvé dans le package. La coloration et l'icône n'ont pas été installées.");
60
- return;
61
- }
62
- const extensionRoot = process.env.VSCODE_AGENT_FOLDER
63
- ? node_path_1.default.join(process.env.VSCODE_AGENT_FOLDER, "extensions")
64
- : process.platform === "win32"
65
- ? node_path_1.default.join(process.env.USERPROFILE || node_os_1.default.homedir(), ".vscode", "extensions")
66
- : node_path_1.default.join(node_os_1.default.homedir(), ".vscode", "extensions");
67
- const destination = node_path_1.default.join(extensionRoot, `gabyy1.fbp-language-${VERSION}`);
68
- try {
69
- node_fs_1.default.mkdirSync(extensionRoot, { recursive: true });
70
- if (node_fs_1.default.existsSync(destination)) {
71
- node_fs_1.default.rmSync(destination, { recursive: true, force: true });
72
- }
73
- node_fs_1.default.cpSync(bundledExtension, destination, { recursive: true });
74
- console.log(`Support VS Code installé dans : ${destination}`);
75
- console.log("Recharge la fenêtre VS Code pour activer la coloration FBP.");
76
- console.log("Pour afficher l'icône personnalisée, sélectionne « FBP File Icons » dans le thème d'icônes de fichiers.");
77
- }
78
- catch (error) {
79
- console.log("Installation automatique du support VS Code impossible.");
80
- console.log("Vérifie les permissions du dossier des extensions VS Code.");
81
- if (error instanceof Error)
82
- console.log(error.message);
83
- }
84
- }
85
- function runCommand(name) {
86
- const configPath = node_path_1.default.resolve("commandes.fbp");
87
- if (!node_fs_1.default.existsSync(configPath)) {
88
- throw new errors_1.FbpError("Fichier commandes.fbp introuvable à la racine du projet. Crée ce fichier pour définir tes commandes.");
89
- }
90
- let commands;
91
- try {
92
- commands = JSON.parse(node_fs_1.default.readFileSync(configPath, "utf8"));
93
- }
94
- catch {
95
- throw new errors_1.FbpError("commandes.fbp doit contenir un objet JSON valide associant chaque commande à un fichier .fbp.");
96
- }
97
- if (!commands || typeof commands !== "object" || Array.isArray(commands)) {
98
- throw new errors_1.FbpError("commandes.fbp doit être un objet de commandes.");
99
- }
100
- const target = commands[name];
101
- if (typeof target !== "string" || !target.trim()) {
102
- const available = Object.keys(commands);
103
- throw new errors_1.FbpError(`Commande « ${name} » inconnue.${available.length ? ` Commandes disponibles : ${available.join(", ")}.` : " Aucune commande n'est définie."}`);
104
- }
105
- new compiler_1.FbpCompiler().runFile(node_path_1.default.resolve(node_path_1.default.dirname(configPath), target));
106
- }
107
- function main() {
108
- const [command, ...args] = process.argv.slice(2);
109
- try {
110
- switch (command) {
111
- case "help":
112
- case "--help":
113
- case "-h":
114
- case undefined:
115
- help();
116
- break;
117
- case "version":
118
- case "--version":
119
- case "-v":
120
- console.log(`FBP ${VERSION}`);
121
- break;
122
- case "info":
123
- console.log("FBP — French Bot Programming");
124
- console.log("Moteur : TypeScript / Node.js");
125
- console.log("Fichiers source : .fbp");
126
- break;
127
- case "ping":
128
- ping();
129
- break;
130
- case "-init":
131
- case "init":
132
- initProject();
133
- break;
134
- case "run":
135
- if (!args[0])
136
- throw new errors_1.FbpError("Indique le nom de la commande. Exemple : fbp run lancer");
137
- runCommand(args[0]);
138
- break;
139
- case "run-file":
140
- if (!args[0])
141
- throw new errors_1.FbpError("Indique un fichier. Exemple : fbp run-file bot/main.fbp");
142
- new compiler_1.FbpCompiler().runFile(args[0]);
143
- break;
144
- default:
145
- throw new errors_1.FbpError(`Commande CLI inconnue : « ${command} ». Utilise « fbp help » pour afficher l'aide.`);
146
- }
147
- }
148
- catch (error) {
149
- if (error instanceof errors_1.FbpError) {
150
- console.error(error.format());
151
- process.exitCode = 1;
152
- }
153
- else {
154
- console.error("Erreur FBP : une erreur inattendue est survenue.");
155
- console.error(error instanceof Error ? error.message : String(error));
156
- process.exitCode = 1;
157
- }
158
- }
159
- }
160
- main();