-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
129 lines (114 loc) · 3.52 KB
/
cli.js
File metadata and controls
129 lines (114 loc) · 3.52 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env node
var currentPath = process.cwd();
let fs = require('fs');
// Command list
var command = {
build: {
shortDesc: "Compile Blackprint modules for current project (JavaScript)",
longDesc: "Example command:\nblackprint build production",
call(env='development'){
let isProduction = process.env.production === 'true' || env === 'prod' || env === 'production';
// env = @serve, for internal use only
if(!fs.existsSync(`${currentPath}/blackprint.config.js`)
&& !fs.existsSync(`${currentPath}/nodes/`)){
console.error("Config file (./blackprint.config.js) or modules folder was not found (nodes/**/blackprint.config.js)");
process.exit(1);
}
process.stdout.write("Loading Gulp\r");
let Gulp = require('gulp');
process.stdout.write("Loading scarletsframe-compiler\r");
let SFC = require("scarletsframe-compiler")({
// Start the server
browserSync: env === '@serve' && {
port: process.env.PORT || 6791, // Accessible-> http://localhost:6789
ghostMode: false, // Use synchronization between browser?
ui: false,
open: false,
// Standalone server with BrowserSync
cors: true,
server:{ baseDir:'./dist' },
serveStatic: [{
route: '/dist',
dir: 'dist'
}],
middleware: [{
route: "/api/module-list",
handle(req, res, next){
res.end(JSON.stringify(configLoader.moduleList));
next();
}
}, {
route: "/",
handle(req, res, next){
res.end(`<br><p style="font-family: 'Arial'; font-size: 16px;">Please use <b>Blackprint Editor in development mode</b> to connect into this module server for loading your node modules.</p>`);
next();
}
}]
},
includeSourceMap: true,
startupCompile: true,
hotReload:{
html: true,
sf: true,
js: true,
scss: true
},
path: {}
}, Gulp);
let configLoader = require('./blackprint-config-loader.js')(SFC, Gulp);
if(isProduction)
Gulp.task('compile')(); // Transpile + Minify
else Gulp.task('default')();
}
},
serve: {
shortDesc: "Create a server for compiled Blackprint modules",
longDesc: "Example command:\nblackprint serve",
call(){
command.build.call('@serve');
}
},
create: {
shortDesc: "Create a new Blackprint module from template",
longDesc: "Example command:\nblackprint create",
call(){
require('./create-from-template.js')();
}
},
'run:relay': {
shortDesc: "Start a relay server for remote control",
longDesc: "Start a relay server that can be used for remote controling a Blackprint engine",
call(){
let remotePort = undefined;
let cors = undefined;
process.argv.forEach(v => {
if(v.startsWith('--remote=')){
let port = Number(v.replace('--remote=', ''));
if(!port) throw new Error('--remote=port must be number, but get: ' + port);
remotePort = port;
}
else if(v.startsWith('--cors=')){
cors = v.replace('--cors=', '').replace(/['"]/g, '').split(',');
}
});
require('./utils/runRelay.js')(remotePort, cors);
}
},
};
// No need to modify below
var args = globalThis.process?.argv.slice(2) || globalThis.Deno;
if(args[0] === void 0 || /-h|--h|\/h|\/help|help/.test(args[0])){
console.log("Available commands:");
for(let key in command)
console.log(' - '+key+': '+command[key].shortDesc);
}
else if(command[args[0]] !== void 0){
if(/-h|--h|\/h|\/help|help/.test(args[1])){
console.log(command[args[0]].longDesc);
return;
}
command[args[0]].call(args[1]);
}
else {
console.log("Command not found: ", args[0]);
}