-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (77 loc) · 2 KB
/
index.js
File metadata and controls
82 lines (77 loc) · 2 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env node
var jetpack = require('fs-jetpack');
var compile = require('./compile.js');
var braml = require('braml');
var userArgs = process.argv.slice(2);
var exit = false;
var cont = false;
var param = [];
var command = [];
var exist = false;
for (var i = 0; i < userArgs.length; i++) {
var arg = userArgs[i];
if (arg.charAt(0) == '-') {
cont = true;
param.push(arg);
}
else {
command.push(arg);
}
}
if (userArgs[0] == 'compile') {
if (cont) {
cont = false;
for (var i = 0; i < param.length; i++) {
if (param[i] == '-o') {
cont = true;
}
}
if (cont) {
cont = false;
if (jetpack.exists(command[1])) {
if (jetpack.exists(command[2]) && param.indexOf('-f') == 1) {
compile(command[1], command[2]);
}
else if (!jetpack.exists(command[2])) {
compile(command[1], command[2]);
}
else {
console.error(`'${command[2]}' already exists. Try using '-f' to force overwrite.`);
}
}
else {
console.error(`'${command[1]}' does not exist.`);
}
}
else {
console.error(`'${param}' are not any of the expected parameters for the compile command.`);
}
}
else {
console.error('No parameters were recieved.');
}
}
else if (userArgs[0] == 'parse') {
if (jetpack.exists(command[1])) {
console.log(braml(jetpack.read(command[1]))[1]);
}
else {
console.error(`'${command[1]}' does not exist.`);
}
}
else if (userArgs[0] == 'help') {
console.log(
`Commands:
Compile -- Takes in a braml file and spits out an html file.
Help -- Displays this command and parameters definition.
Parameters:
-o -- Tells the command where to ouput. e.g 'braml compile index.html -o index.braml'
-f -- Tells the command to execute no matter what.`);
}
else if (command[0] == null) {
console.error('Command Was not Passed.');
console.log("Try using the 'help' command.");
}
else {
console.error(`'${userArgs[0]}' is not a braml-cli command.`);
}