-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaop
executable file
·704 lines (647 loc) · 26.1 KB
/
aop
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#!/usr/bin/env node
const version = 0.36;
const { exec, spawn, spawnSync, execSync } = require("child_process");
const console = require("console");
const fs = require('fs');
const path = require('node:path');
const myArgs = process.argv.slice(2);
const WHICH = (process.platform.startsWith('win')) ? 'set PATH=%PATH%;C:\\xampp\\php\\;D:\\xampp\\php\\ && where' : 'which';
const SPAWNARG = { stdio: 'inherit', shell: true }
const params = {};
const readline = require('readline');
const MAINMODULE = 'main';
const E = '\x1b[1m';
const R = '\x1b[0;31m';
const B = '\x1b[0;34m';
const Y = '\x1b[0;33m';
const G = '\x1b[0;32m';
const N = '\x1b[0m';
var NG = '';
var PHP = '';
var NPM = '';
var NPX = '';
var ftpPort = 21;
var ftpSecure = false;
var forceClean = false;
var silent = false;
class FTPClient {
constructor(ftp, host = 'localhost', port = 21, username = 'anonymous', password = 'guest', secure = false) {
this.client = new ftp.Client(0);
this.settings = {
host: host,
port: port,
user: username,
password: password,
secure: secure
};
}
async setup() {
if (this.client.closed) {
this.client.trackProgress(info => {
info.name = info.name.length ? info.name : "Listing";
let tabs = makeTab(info.name + info.type, 45);
let trans = (info.type == "upload") ? G + E + "Tr" + N : E + "Pr" + N;
if (info.bytes) {
let kb = info.bytes / 1000;
let tt = makeTab(String(kb), 10);
console.log(info.type, "->", B + E + info.name + N, tabs, trans, tt, info.bytes / 1000, "kB");
}
})
await this.client.access(this.settings);
}
}
async removeByExtension(ext) {
let files = await this.client.list();
for (let file of files) {
if (file.type == 1 && file.name.includes('.' + ext)) {
await this.client.remove(file.name);
}
}
}
async exists(exist) {
let files = await this.client.list();
for (let file of files) {
if (file.name == exists) {
return true;
}
}
}
async removeAngularFiles() {
await this.removeByExtension('css');
await this.removeByExtension('js');
await this.removeByExtension('html');
}
upload(sourcePath, remotePath) {
(async() => {
try {
await this.setup();
if (forceClean) {
await this.client.ensureDir(remotePath);
await this.client.clearWorkingDir();
} else {
await this.removeAngularFiles();
}
await this.client.uploadFromDir(sourcePath, remotePath);
if (fs.existsSync(path.join(sourcePath, 'backend'))) {
await this.client.cd('backend');
}
await this.client.cd('writable');
await this.removeByExtension('info.txt');
} catch (err) {
console.log(err);
}
this.close();
})();
}
close() {
this.client.close();
process.exit(0);
}
}
const parseArguments = () => {
for (let a = 0; myArgs.length > a; a++) {
let m = myArgs[a];
if (typeof m == 'string' && m.startsWith('-')) {
let search = m.split('=')[0];
switch (search) {
case '-u':
params.username = myArgs[++a];
break;
case '--username':
params.username = m.split('=')[1];
break;
case '-p':
params.password = myArgs[++a];
break;
case '--password':
params.password = m.split('=')[1];
break;
case '-c':
params.copy = myArgs[++a];
break;
case '--copy':
params.copy = m.split('=')[1];
break;
case '-fp':
ftpPort = myArgs[++a];
break;
case '--ftp-port':
ftpPort = m.split('=')[1];
break;
case '--force-clean':
forceClean = true;
break;
case '--silent':
silent = true;
break;
}
} else {
if (!params.hasOwnProperty('command')) params.command = m;
}
}
}
const makeTab = (name, len) => {
let t = (name > 0) ? parseInt(name) : 1;
t = len - name.length;
t = t > 0 ? t : 1;
let tabs = "";
for (let a = 0; t > a; a++) tabs += " "
return tabs;
}
const copyFileSync = (source, target) => {
var targetFile = target;
// If target is a directory, a new file with the same name will be created
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source));
}
}
fs.writeFileSync(targetFile, fs.readFileSync(source));
}
const ftpSync = (source, target) => {
if (forceClean) {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(`${R}${E}--force-clean\n\n is a personal developer feature that will erase all files from the ftp remote folder before copying on it.\n\n - Are you sure you want to use it?\n\n - Have you backed up this folder? ${N} [${G}${E}NO${N}]/${R}${E}yes${N} `, ans => {
if (ans == 'yes') {
ftpSyncReal(source, target);
} else {
process.exit(0);
}
});
} else {
ftpSyncReal(source, target);
}
}
const ftpSyncReal = (source, target) => {
var ftp = null;
try {
ftp = require(path.join(process.cwd(), 'node_modules', 'basic-ftp'));
} catch (e) {
spawnSync(NPM, ['install', 'basic-ftp', '--save'], SPAWNARG);
ftp = require(path.join(process.cwd(), 'node_modules', 'basic-ftp'));
}
if (ftp != null) {
let cred, chost, user, pass = '';
if (params.hasOwnProperty('username')) {
user = params.username;
pass = params.password;
let ll = target.split('@');
chost = (typeof ll[1] == "undefined") ? ll[0] : ll[1];
} else {
[cred, chost] = target.split('@');
[user, pass] = cred.split(':');
}
let [host, tar] = chost.split(':');
tar = (tar == null) ? '' : tar;
const ftpClient = new FTPClient(ftp, host, ftpPort, user, pass, ftpSecure);
ftpClient.upload(source, tar);
}
}
const copyFolderRecursiveSync = (source, target) => {
var files = [];
// Check if folder needs to be created or integrated
var targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder);
}
// Copy
if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source);
files.forEach(function(file) {
var curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync(curSource, targetFolder);
}
});
}
}
const copyInsideSourceRecursiveSync = (source, target, show = false) => {
if (!fs.existsSync(target)) {
fs.mkdirSync(target);
}
let files = fs.readdirSync(source);
for (let file of files) {
let np = path.join(source, file);
if (show) console.log('copying', B + E + np + N, makeTab(np, 50), '->', G + E + target + N)
if (fs.lstatSync(np).isDirectory()) {
copyFolderRecursiveSync(np, target);
} else {
copyFileSync(np, target);
}
}
}
const usage = u => {
console.log(`\n${R}${E}usage${N}: node aop [Command] [ARG]\n\nCommands:
${G}${E}serve${N} \t- begins the development serve for ${E}Angular${N} and ${E}Codeigniter${N} \n\t \t at ${Y}${E}http://localhost:4200${N} and ${Y}${E}http://localhost:8085${N},\n\t \t You might alternatively use a separate module to serve as a comment,\n\t \t for instance: aop emergency serve or aop serve emergency\n
${G}${E}spark${N} \t- launches the ${E}Codeigniter${N} spark utility\n
${G}${E}composer${N} \t- launches the ${E}Composer${N} PHP tool\n
${G}${E}ng${N} \t- invokes the ${E}Angular${N} ng utility, and you may also begin using it with a different module, \n\t \t such as aop ng emergency... or aop emergency ng ... for example.
${G}${E}npm${N} \t- invokes the ${E}Angular${N} npm utility, and you may alternatively start using it with a different module, \n\t \t such as aop npm emergency... or aop emergency npm... for example.
${G}${E}npx${N} \t- invokes the ${E}Angular${N} npx utility, and you may also start using it with a different module, \n\t \t such as aop npx emergency... or aop emergency npx... for example.\n
${G}${E}ma${N} \t- creates an ${E}Angular${N} which can then be loaded into controller using the method aopRender.
${G}${E}mc${N} \t- will convert an existing ${E}Angular${N} project inside of asrc to a module, \n\t \t which can then be loaded into controller using the method aopRender.\n
${G}${E}build${N} \t- generates a full plug-and-play package in the ${Y}${E}build/${N} folder; but, if you choose, \n\t \t you may generate only one module instead of all of them. For instance: aop build emergency
${G}${E}build:oth${N}\t- generates a complete plug-and-play package on the build folder for all servers \n\t \t that do not support ".htaccess." For reasons of safety, the "public" subfolder is the \n\t \t only one that must be shared; alternatively, you can build just one module rather than all of them.\n\t \t Here is an example of what this might look like: aop build emergency\n
${G}${E}copy${N}\t- will copy your build to a remote ftp server or a folder using the following syntax: \n\t \t ${Y}${E}ftp://user:pass@host[:path]${N}\n
${G}${E}install${N}\t- will install aop as a command inside the system
\n\nOptions:
${G}${E}-c\t${N} path\t\tor ${G}${E}--copy=path${N}\t\tFollowing the completion of the build, this command will transfer the \n\t \t \t \t\t \tbuild to a specified folder or an external FTP server using the \n\t \t \t \t\t \tsyntax ${Y}${E}ftp://user:pass@host[:path]${N}
${G}${E}-fp\t${N} port\t\tor ${G}${E}--ftp-port=port${N}\tchange the default ftp port.
${G}${E}-u\t${N} username\tor ${G}${E}--username=username${N}\tftp username.
${G}${E}-p\t${N} password\tor ${G}${E}--password=password${N}\tftp password.\n\nversion: ${version}
`);
process.exit(0)
}
const check = f => {
exec(WHICH + ' npm', (error, stdout) => {
if (error) {
console.log(`${R}${E}error:${N}${E} unable to find npm executable${N}`);
return;
} else {
NPM = fixPath(stdout.split("\n")[0].trim());
NPX = execSync(WHICH + ' npx').toString();
if (!fs.existsSync('node_modules')) {
spawnSync(NPM, ['install', '--legacy-peer-deps'], SPAWNARG);
}
exec(WHICH + ' php', (error, stdout) => {
if (error) {
console.log(`${R}${E}error:${N}${E} unable to find php executable${N}`);
return;
} else {
PHP = fixPath(stdout.split("\n")[0].trim());
if(fs.existsSync("asrc")) {
exec(WHICH + ' ng', (error, stdout) => {
if (error) {
console.log(`${G}${E}Installing missed ng command:${N}`);
npmprecess = spawn(NPM, ['install', '-g', '@angular/cli@14'], SPAWNARG);
npmprecess.on('exit', () => check(f));
return;
} else {
NG = fixPath(stdout.split("\n")[0].trim());
f();
}
});
} else {
f();
}
}
});
}
});
}
const serve = (module) => {
let source = path.join('envs', 'development.env');
if (!fs.existsSync('.env') && fs.existsSync(source)) copyFileSync(source, '.env');
const codeigniter = spawn(PHP, ['spark', 'serve', '--port', 8085], SPAWNARG);
SPAWNARG.cwd = path.join('asrc', module);
if (!fs.existsSync(path.join(SPAWNARG.cwd, 'node_modules'))) {
spawnSync(NPM, ['install', '--legacy-peer-deps'], SPAWNARG)
}
const angular = spawn(NG, ['serve'], SPAWNARG);
delete SPAWNARG.cwd;
process.on('SIGINT', () => {
console.log(`\n\n${R}${E}Killed${N}${N}:\n ${G}✔${N} ${E}ng serve${N} with pid: ${G}${angular.pid}${N} \n ${G}✔${N} ${E}spark serve${N} with pid: ${G}${codeigniter.pid}${N}`);
angular.kill;
codeigniter.kill;
});
}
const fixPath = e =>{
if (process.platform.startsWith('win')){
return '"'+e+'"';
} else {
return e.replace(/ /g, '\ ');
}
}
const buildAngular = e => {
if(!fs.existsSync('asrc')) return;
if (!fs.existsSync('vendor')) spawnSync(PHP, [path.join('aopm', 'update.php')], SPAWNARG);
if (e == 'all') {
files = fs.readdirSync('asrc');
for (let file of files) {
if (file.startsWith('.')) continue;
console.log(`${G}${E}Building ${Y}${E}${file}${N}`);
convertToModule(file);
SPAWNARG.cwd = path.join('asrc', file);
if (!fs.existsSync(path.join(SPAWNARG.cwd, 'node_modules'))) {
spawnSync(NPM, ['install', '--legacy-peer-deps'], SPAWNARG)
}
spawnSync(NG, ['build'], SPAWNARG);
}
} else {
console.log(`${G}${E}Building ${Y}${E}${MAINMODULE}${N}`);
SPAWNARG.cwd = path.join('asrc', e)
spawnSync(NG, ['build'], SPAWNARG);
}
delete SPAWNARG.cwd
}
const buildForApache = e => {
buildAngular(e);
console.log(`${Y}${E}Cleaning build folder...${N}`);
fs.rmSync('build', { recursive: true, force: true });
console.log(`${Y}${E}Coping all php files inside build${N}`);
copyInsideSourceRecursiveSync('public', 'build');
fs.mkdirSync(path.join('build', 'backend'));
copyFolderRecursiveSync('aopm', path.join('build', 'backend'));
copyFolderRecursiveSync('app', path.join('build', 'backend'));
copyFolderRecursiveSync(path.join('vendor', 'codeigniter4', 'framework', 'writable'), path.join('build', 'backend'));
copyFileSync(path.join('envs', 'production.env'), path.join('build', 'backend', '.env'));
copyFileSync('composer.json', path.join('build', 'backend'));
copyFileSync(path.join('app', '.htaccess'), path.join('build', 'backend'));
fs.writeFileSync(path.join('build', 'index.php'), fs.readFileSync(path.join('build', 'index.php'), 'utf-8').replace(/\.\.\//, 'backend/'));
fs.writeFileSync(path.join('build', 'backend', 'spark'), fs.readFileSync('spark', 'utf-8').replace(/\.\.\//, 'backend/').replace('public', '..'));
fs.mkdirSync(path.join('build', 'backend', 'cache'));
copyBuild();
}
const buildForOthers = e => {
buildAngular(e);
console.log(`${Y}${E}Cleaning build folder...${N}`);
fs.rmSync('build', { recursive: true, force: true });
fs.mkdirSync('build');
console.log(`${Y}${E}Coping all php files inside build${N}`);
copyFolderRecursiveSync('public', 'build');
copyFolderRecursiveSync('aopm', path.join('build'));
copyFolderRecursiveSync('app', path.join('build'));
copyFolderRecursiveSync(copyFolderRecursiveSync(path.join('vendor', 'codeigniter4', 'framework', 'writable')), path.join('build'));
copyFileSync(path.join('envs', 'production.env'), path.join('build', '.env'));
copyFileSync('composer.json', path.join('build'));
copyFileSync('.htaccess', path.join('build'));
fs.mkdirSync(path.join('build', 'cache'));
copyBuild();
}
const copyBuild = () => {
if(silent){
copyBuildReal('ok')
} else {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(`${Y}${E}Would yo like to pre-exec composer in build folder ${N}? [${G}${E}yes${N}]/${R}${E}no${N} `, ans => {
copyBuildReal((ans !== 'no') ? 'ok' : 'no');
});
}
}
const copyBuildReal = u => {
if (u == 'ok') {
let update = (fs.existsSync(path.join('build', 'backend'))) ? path.join('build', 'backend') : path.join('build');
delete SPAWNARG.cwd;
spawnSync(PHP, [path.join(update, 'aopm', 'update.php')], SPAWNARG);
fs.unlinkSync(path.join(update, 'writable', 'firstup.info.txt'));
fs.rmSync(path.join(update, 'cache'), { recursive: true, force: true });
fs.writeFileSync(path.join(update, 'writable', 'nocomposer.txt'), 'remove to reenable composer autoupdate');
}
if (params.hasOwnProperty('copy')) {
for (let rem of['public', 'index.php', 'main.html', '.env', '.htaccess'])
if (fs.existsSync(path.join(params.copy, rem)))
fs.rmSync(path.join(params.copy, rem), { recursive: true, force: true });
switch (params.copy.slice(0, 6)) {
case 'ftp://':
ftpSync('build', params.copy.slice(6));
break;
case 'sftp:/':
case 'ftps:/':
ftpSecure = true;
ftpSync('build', params.copy.slice(7));
break;
default:
copyInsideSourceRecursiveSync('build', params.copy, true);
let firstup = ['aopm', 'versions', 'firstup.info.txt'];
if (fs.existsSync(path.join(params.copy, 'backend', ...firstup))) {
fs.rmSync(path.join(params.copy, 'backend', ...firstup));
}
if (fs.existsSync(path.join(params.copy, ...firstup))) {
fs.rmSync(path.join(params.copy, ...firstup));
}
process.exit(0);
}
} else {
process.exit(0);
}
}
const installAOP = e => {
if (!fs.existsSync('.env')) copyFileSync(path.join('envs', 'development.env'), '.env');
let nodePath = path.normalize(path.join(NPM.replace(/"/, ''), '..'));
copyFileSync(path.join('aop'), nodePath, { overwrite: true | false });
if (process.platform.startsWith('win')) {
fs.writeFileSync(path.join(nodePath, 'aop.cmd'), `@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\\node.exe" (
SET "_prog=%dp0%\\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\aop" %*`);
} else {
fs.chmodSync(path.join(nodePath, 'aop'), '755');
}
}
const createNewModule = module => {
if(!fs.existsSync('asrc')) return;
let dest = path.join('asrc', module);
if (fs.existsSync(dest)) {
console.log(`The module already exists! I can't overwrite it!`);
return;
}
SPAWNARG.cwd = 'asrc';
spawnSync(NG, ['new', module, '--style', 'scss', '--routing', '--defaults'], SPAWNARG);
delete SPAWNARG.cwd;
convertToModule(module);
}
const convertToModule = module => {
if(!fs.existsSync('asrc')) return;
let file = path.join('asrc', module, 'angular.json');
let filebk = path.join('asrc', module, 'angular-no-module.json');
if (!fs.existsSync(file)) {
console.log(`The module doesn't exists!`);
return;
}
const data = JSON.parse(fs.readFileSync(file));
let dst = '../../public/amodules/' + module;
let firstkey = Object.keys(data.projects)[0];
let project = data.hasOwnProperty('defaultProject') ? data.defaultProject : firstkey;
if (data.projects.hasOwnProperty(project) && data.projects[project].architect.build.options.outputPath == dst) {
console.log(`Project already converted!`);
return;
}
copyFileSync(file, filebk);
data.projects[project].architect.build.options.outputPath = dst;
fs.writeFileSync(file, JSON.stringify(data, null, 4));
}
const getRecursive = (pArray, recursive = true) => {
let arr = [];
let ph = path.join(...pArray);
for (file of fs.readdirSync(ph)) {
let fss = path.join(ph, file);
if (!file.startsWith('.')) {
if (!fs.lstatSync(fss).isDirectory()) {
let un = [...pArray, file].join('/');
if (!arr.includes(un)) arr.push(un);
} else {
if (recursive)
for (fl of getRecursive([...pArray, file])) arr.push(fl);
}
}
}
return arr;
}
const loadAssets = asset => {
if (asset == MAINMODULE) return console.log(`to get asset you have to provide a valid npm module, for example: admin-lte@^3.2`);
let assetImport = { packages: {} };
let mod = (asset.includes('@')) ? asset.split('@')[0] : asset;
if (fs.existsSync('assets.json')) assetImport = JSON.parse(fs.readFileSync('assets.json'));
let dest = path.join('asset_modules', mod);
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true, force: true });
}
spawnSync(NPM, ['install', asset, '---prefix', dest], SPAWNARG);
assetImport.packages[mod] = JSON.parse(fs.readFileSync(path.join(dest, 'package.json')));
if (mod == '') return console.log(`you have to manually set what to import to asset`);
if (!assetImport.hasOwnProperty(mod)) assetImport[mod] = [];
for (let arr of getRecursive(['asset_modules', mod, 'node_modules', mod, 'dist'], false)) {
if (!assetImport[mod].includes(arr)) assetImport[mod].push(arr);
}
fs.writeFileSync('assets.json', JSON.stringify(assetImport, null, 4));
}
const composer = args =>{
let executable = path.join('writable', 'composer.phar');
if(! fs.existsSync(executable))
spawnSync(PHP, ["-r", `"copy('https://getcomposer.org/download/latest-stable/composer.phar', 'writable/composer.phar');"`], SPAWNARG);
spawnSync(PHP, [ executable, ...args ], SPAWNARG);
}
const runNode = (n,m)=>{
if(fs.existsSync('asrc')) {
m = (m == 'all') ? MAINMODULE : m;
SPAWNARG.cwd = path.join('asrc', m)
spawn(n, myArgs.splice(2), SPAWNARG);
} else {
if(params.command == 'ng') return;
m = (m == 'all') ? MAINMODULE : m;
spawn(n, myArgs.splice(1), SPAWNARG);
}
}
const menu = () => {
let arg = (myArgs[1]) ? myArgs[1] : 'all';
let module = (fs.existsSync(path.join('asrc', arg))) ? arg : 'all';
parseArguments(myArgs);
let ismodule = (fs.existsSync(path.join('asrc', params.command)));
if(ismodule){
let t = (myArgs[1])?myArgs[1]:'';
if(t.includes('ng') || t.includes('npm') || t.includes('npx') || t.includes('serve')) {
module = params.command;
params.command = t;
}
}
switch (params.command) {
case 'serve':
module = (module == 'all') ? MAINMODULE : module;
serve(module);
break;
case 'spark':
spawn(PHP, myArgs, SPAWNARG);
break;
case 'composer':
composer(myArgs.splice(1));
break;
case 'ng':
runNode(NG, module);
break;
case 'npm':
runNode(NPM, module);
break;
case 'npx':
runNode(NPX, module);
break;
case 'build':
module = (arg == 'all') ? arg : module;
buildForApache(module);
break;
case 'build:oth':
module = (arg == 'all') ? arg : module;
buildForOthers(module);
break;
case 'ma':
if (myArgs[1] !== undefined) createNewModule(arg);
break;
case 'mc':
if (myArgs[1] !== undefined) convertToModule(arg);
break;
case 'install':
installAOP();
break;
case 'copy':
params.copy = arg;
copyBuildReal();
break;
case 'assets:load':
loadAssets(arg);
break;
case 'hash':
process.stdout.write(`\n${E}One of possible hash for ${G}${E}${myArgs[1]}${N}${E} is ${N}${Y}${E}`);
spawnSync(PHP, ["-r", `"echo password_hash('${myArgs[1]}', PASSWORD_DEFAULT);"`], SPAWNARG);
process.stdout.write(`${N}\n\n`);
break;
default:
usage();
}
}
const getVersionOnPath = () => {
let a = 0;
let filePath = path.join(process.cwd(), 'aop');
let fileContent = fs.readFileSync(filePath, { encoding: 'utf-8' });
for (let line of fileContent.split('\n')) {
if (line.includes('version') && a++ < 5) {
let tmp = line.split('=');
if (tmp[1] !== undefined) {
let ver = parseFloat(tmp[1].split(';')[0].trim());
return (ver !== NaN) ? ver : 0;
}
}
}
return 0;
}
if(fs.existsSync(path.join(process.cwd(), 'backend'))){
process.chdir('backend');
}
if (fs.existsSync(path.join(process.cwd(), 'aop'))) {
let pathVersion = getVersionOnPath();
if (pathVersion > version) {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(`${Y}${E}Detected new aop version (${pathVersion}) in this folder, would you like to update ${N}? [${G}${E}yes${N}]/${R}${E}no${N} `, ans => {
if (ans !== 'no') {
check(() => {
installAOP();
console.log(`${R}${E}Reload this script${N}`);
process.exit(0);
});
} else {
myStart();
}
});
} else {
myStart();
}
} else {
myStart();
}
function myStart() {
if (myArgs.length == 0) {
usage();
} else {
check(menu);
}
}