-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·66 lines (60 loc) · 1.95 KB
/
cli.js
File metadata and controls
executable file
·66 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const commander = require('commander');
const program = new commander.Command();
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const NekoScript = require('./index');
const NekoPackageManager = require('./src/package-manager');
program
.version('1.0.0')
.description('NekoScript - Un langage de programmation français simple et créatif 🐱');
program
.command('nouveau <nom>')
.description('Crée un nouveau projet NekoScript')
.action((nom) => {
const dir = `./${nom}`;
fs.mkdirSync(dir);
fs.writeFileSync(`${dir}/main.neko`, '// Mon projet NekoScript\n');
console.log(chalk.green(`✨ Projet ${nom} créé!`));
});
program
.command('executer <fichier>')
.description('Exécute un fichier NekoScript')
.action((fichier) => {
try {
if (!fs.existsSync(fichier)) {
console.log(chalk.red(`❌ Le fichier ${fichier} n'existe pas!`));
return;
}
const neko = new NekoScript();
const code = fs.readFileSync(fichier, 'utf-8');
neko.execute(code);
} catch (error) {
console.error(chalk.red('❌ Erreur:'), error.message);
}
});
program
.command('publier <nom>')
.description('Publie un package NekoScript')
.action((nom) => {
const packagePath = path.join(process.cwd(), 'neko.json');
if (!fs.existsSync(packagePath)) {
console.log(chalk.red('❌ Fichier neko.json manquant!'));
return;
}
const pkg = require(packagePath);
console.log(chalk.green(`📦 Publication de ${nom} v${pkg.version}...`));
});
program
.command('installer <package>')
.description('Installe un package NekoScript')
.action(async (package) => {
try {
const pm = new NekoPackageManager();
await pm.installPackage(package);
console.log(chalk.green(`✅ ${package} installé avec succès!`));
} catch (error) {
console.error(chalk.red('❌ Erreur:'), error.message);
}
});
program.parse(process.argv);