@cyklang/cli 0.5.1 → 0.5.3
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/build/Cmd.d.ts +21 -0
- package/build/Cmd.js +58 -0
- package/build/InstallCommand.d.ts +7 -2
- package/build/InstallCommand.js +68 -20
- package/package.json +2 -1
- package/src/Cmd.ts +62 -1
- package/src/InstallCommand.ts +71 -28
package/build/Cmd.d.ts
CHANGED
|
@@ -13,4 +13,25 @@ export declare class Cmd extends Command {
|
|
|
13
13
|
* @param options
|
|
14
14
|
*/
|
|
15
15
|
updateAuthAccess(tableName: string, prefix: string, id: string, options: any): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* method executeCommand
|
|
18
|
+
* @param command
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
executeCommand(command: string): Promise<{
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* method runShellCommand
|
|
27
|
+
* @param command
|
|
28
|
+
*/
|
|
29
|
+
runShellCommand(command: string, args: string[]): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param command
|
|
33
|
+
* @param args
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
spawnCommand(command: string, args: string[]): Promise<void>;
|
|
16
37
|
}
|
package/build/Cmd.js
CHANGED
|
@@ -10,6 +10,8 @@ const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
10
10
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
11
11
|
const NodeCrypto_1 = require("./NodeCrypto");
|
|
12
12
|
const DBClient_1 = require("./DBClient");
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const kolorist_1 = require("kolorist");
|
|
13
15
|
const logger = loglevel_1.default.getLogger('Cmd.ts');
|
|
14
16
|
logger.setLevel('debug');
|
|
15
17
|
class Cmd extends commander_1.Command {
|
|
@@ -82,5 +84,61 @@ class Cmd extends commander_1.Command {
|
|
|
82
84
|
throw err;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* method executeCommand
|
|
89
|
+
* @param command
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
executeCommand(command) {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
(0, child_process_1.exec)(command, (error, stdout, stderr) => {
|
|
95
|
+
if (error) {
|
|
96
|
+
reject(error);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
resolve({ stdout, stderr });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* method runShellCommand
|
|
105
|
+
* @param command
|
|
106
|
+
*/
|
|
107
|
+
async runShellCommand(command, args) {
|
|
108
|
+
try {
|
|
109
|
+
await this.spawnCommand(command, args);
|
|
110
|
+
// console.log(command)
|
|
111
|
+
// const result = await this.executeCommand(command);
|
|
112
|
+
// console.log(result.stdout);
|
|
113
|
+
// if (result.stderr && result.stderr.trim() !== '')
|
|
114
|
+
// console.error(result.stderr);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Error running "' + command + '":', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @param command
|
|
124
|
+
* @param args
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
127
|
+
spawnCommand(command, args) {
|
|
128
|
+
console.log();
|
|
129
|
+
console.log([command, ...args, '...'].join(' '));
|
|
130
|
+
const child_process = (0, child_process_1.spawn)(command, args, { stdio: 'inherit' });
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
child_process.on('close', (code) => {
|
|
133
|
+
if (code === 0) {
|
|
134
|
+
console.log((0, kolorist_1.green)('*') + ' ' + [command, ...args].join(' '));
|
|
135
|
+
resolve();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
reject(new Error([command, ...args].join(' ') + ' --> Error ' + code));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
85
143
|
}
|
|
86
144
|
exports.Cmd = Cmd;
|
|
@@ -3,8 +3,13 @@ export declare class InstallCommand extends Cmd {
|
|
|
3
3
|
constructor(name: string);
|
|
4
4
|
install(node_package: string, options: any): Promise<void>;
|
|
5
5
|
/**
|
|
6
|
-
* method
|
|
6
|
+
* method installNodePackage
|
|
7
7
|
* @param node_package
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
installNodePackage(node_package: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* method lookupInstallScript
|
|
12
|
+
* @param node_package
|
|
13
|
+
*/
|
|
14
|
+
lookupInstallScript(node_package: string): Promise<string | undefined>;
|
|
10
15
|
}
|
package/build/InstallCommand.js
CHANGED
|
@@ -30,6 +30,7 @@ exports.InstallCommand = void 0;
|
|
|
30
30
|
const Cmd_1 = require("./Cmd");
|
|
31
31
|
const fs = __importStar(require("fs"));
|
|
32
32
|
const path = __importStar(require("path"));
|
|
33
|
+
const kolorist_1 = require("kolorist");
|
|
33
34
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
34
35
|
const ModuleCommand_1 = require("./ModuleCommand");
|
|
35
36
|
const logger = loglevel_1.default.getLogger('InstallCommand.ts');
|
|
@@ -37,8 +38,8 @@ logger.setLevel('debug');
|
|
|
37
38
|
class InstallCommand extends Cmd_1.Cmd {
|
|
38
39
|
constructor(name) {
|
|
39
40
|
super(name);
|
|
40
|
-
this.description('upload
|
|
41
|
-
.argument('<node_package>', 'Node Package installed as dependency')
|
|
41
|
+
this.description('npm install and upload xml modules to Cyk server')
|
|
42
|
+
.argument('<node_package>', 'Node Package installed as dev dependency')
|
|
42
43
|
.action(async (node_package, options) => {
|
|
43
44
|
await this.install(node_package, options);
|
|
44
45
|
});
|
|
@@ -48,15 +49,46 @@ class InstallCommand extends Cmd_1.Cmd {
|
|
|
48
49
|
await this.prologue(options);
|
|
49
50
|
if (this.dbManager === undefined)
|
|
50
51
|
throw 'dbManager undefined';
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/**
|
|
53
|
+
* install the Node Package by npm
|
|
54
|
+
* and postinstall script will invoke this 'cyk install' command
|
|
55
|
+
*/
|
|
56
|
+
// await this.installNodePackage(node_package)
|
|
57
|
+
const installScript = await this.lookupInstallScript(node_package);
|
|
58
|
+
if (installScript) {
|
|
59
|
+
/**
|
|
60
|
+
* execute installScript
|
|
61
|
+
*/
|
|
62
|
+
const installPath = path.join('node_modules', node_package, 'scripts', installScript);
|
|
63
|
+
await this.runShellCommand(installPath, []);
|
|
55
64
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
else {
|
|
66
|
+
/**
|
|
67
|
+
* default install : upload modules and execute _init.xml
|
|
68
|
+
*/
|
|
69
|
+
console.log();
|
|
70
|
+
console.log('upload modules to server ...');
|
|
71
|
+
const xmlFolder = path.join('node_modules', node_package, 'xml');
|
|
72
|
+
if (!fs.existsSync(xmlFolder) || !fs.statSync(xmlFolder).isDirectory()) {
|
|
73
|
+
throw 'xml folder not found ( ' + xmlFolder + ' )';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* upload modules to the server
|
|
77
|
+
*/
|
|
78
|
+
let initModule;
|
|
79
|
+
const files = fs.readdirSync(xmlFolder);
|
|
80
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
81
|
+
const file = files[ind];
|
|
82
|
+
await (0, ModuleCommand_1.uploadModule)(path.join(xmlFolder, file), this.dbManager);
|
|
83
|
+
if (file.endsWith('_init.xml')) {
|
|
84
|
+
initModule = file;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log((0, kolorist_1.green)('*') + ' upload modules to server');
|
|
88
|
+
if (initModule) {
|
|
89
|
+
const initPath = path.join(xmlFolder, initModule);
|
|
90
|
+
await this.runShellCommand('npx', ['cyk', 'run', initPath]);
|
|
91
|
+
}
|
|
60
92
|
}
|
|
61
93
|
}
|
|
62
94
|
catch (err) {
|
|
@@ -64,23 +96,39 @@ class InstallCommand extends Cmd_1.Cmd {
|
|
|
64
96
|
}
|
|
65
97
|
}
|
|
66
98
|
/**
|
|
67
|
-
* method
|
|
99
|
+
* method installNodePackage
|
|
68
100
|
* @param node_package
|
|
69
101
|
*/
|
|
70
|
-
async
|
|
71
|
-
let packageJson;
|
|
102
|
+
async installNodePackage(node_package) {
|
|
72
103
|
try {
|
|
73
|
-
|
|
74
|
-
const packageJsonContent = fs.readFileSync('package.json', 'utf8');
|
|
75
|
-
// Analyse du contenu en tant qu'objet JSON
|
|
76
|
-
packageJson = JSON.parse(packageJsonContent);
|
|
104
|
+
await this.runShellCommand('npm', ['install', '--save-dev', node_package]);
|
|
77
105
|
}
|
|
78
106
|
catch (error) {
|
|
79
|
-
console.error('Error
|
|
107
|
+
console.error('Error installing ' + node_package + ' :', error);
|
|
80
108
|
throw error;
|
|
81
109
|
}
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* method lookupInstallScript
|
|
113
|
+
* @param node_package
|
|
114
|
+
*/
|
|
115
|
+
async lookupInstallScript(node_package) {
|
|
116
|
+
let result;
|
|
117
|
+
try {
|
|
118
|
+
const scriptsFolder = path.join('node_modules', node_package, 'scripts');
|
|
119
|
+
if (fs.existsSync(scriptsFolder) && fs.statSync(scriptsFolder).isDirectory()) {
|
|
120
|
+
const files = fs.readdirSync(scriptsFolder);
|
|
121
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
122
|
+
const file = files[ind];
|
|
123
|
+
if (file.startsWith('install.')) {
|
|
124
|
+
result = file;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
throw err;
|
|
84
132
|
}
|
|
85
133
|
}
|
|
86
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyklang/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "cyklang CLI",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dotenv": "^16.0.1",
|
|
23
23
|
"form-data": "^4.0.0",
|
|
24
24
|
"inquirer": "^8.2.5",
|
|
25
|
+
"kolorist": "^1.8.0",
|
|
25
26
|
"loglevel": "^1.8.0",
|
|
26
27
|
"mime-types": "^2.1.35",
|
|
27
28
|
"open": "^9.1.0",
|
package/src/Cmd.ts
CHANGED
|
@@ -4,6 +4,9 @@ import dotenv from 'dotenv'
|
|
|
4
4
|
import loglevel from 'loglevel'
|
|
5
5
|
import { NodeCrypto } from "./NodeCrypto";
|
|
6
6
|
import { DBClient } from "./DBClient";
|
|
7
|
+
import { exec, spawn } from 'child_process';
|
|
8
|
+
import {red, green, bold} from 'kolorist'
|
|
9
|
+
|
|
7
10
|
const logger = loglevel.getLogger('Cmd.ts')
|
|
8
11
|
logger.setLevel('debug')
|
|
9
12
|
|
|
@@ -84,7 +87,7 @@ export class Cmd extends Command {
|
|
|
84
87
|
</db.update>
|
|
85
88
|
`
|
|
86
89
|
|
|
87
|
-
if (!
|
|
90
|
+
if (!this.dbManager) throw 'prologue() has not been called before'
|
|
88
91
|
|
|
89
92
|
const dbClient = new DBClient(this.dbManager)
|
|
90
93
|
dbClient.execInstructions(inst)
|
|
@@ -94,4 +97,62 @@ export class Cmd extends Command {
|
|
|
94
97
|
throw err
|
|
95
98
|
}
|
|
96
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* method executeCommand
|
|
103
|
+
* @param command
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
executeCommand(command: string): Promise<{ stdout: string, stderr: string }> {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
exec(command, (error, stdout, stderr) => {
|
|
109
|
+
if (error) {
|
|
110
|
+
reject(error);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
resolve({ stdout, stderr });
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* method runShellCommand
|
|
120
|
+
* @param command
|
|
121
|
+
*/
|
|
122
|
+
async runShellCommand(command: string, args: string[]) {
|
|
123
|
+
try {
|
|
124
|
+
await this.spawnCommand(command, args)
|
|
125
|
+
// console.log(command)
|
|
126
|
+
// const result = await this.executeCommand(command);
|
|
127
|
+
// console.log(result.stdout);
|
|
128
|
+
// if (result.stderr && result.stderr.trim() !== '')
|
|
129
|
+
// console.error(result.stderr);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error('Error running "' + command + '":', error);
|
|
132
|
+
throw error
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @param command
|
|
139
|
+
* @param args
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
spawnCommand(command: string, args: string[]): Promise<void> {
|
|
143
|
+
console.log()
|
|
144
|
+
console.log([command, ...args, '...'].join(' '))
|
|
145
|
+
const child_process = spawn(command, args, { stdio: 'inherit' })
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
child_process.on('close', (code) => {
|
|
148
|
+
if (code === 0) {
|
|
149
|
+
console.log(green('*') + ' ' + [command, ...args].join(' '))
|
|
150
|
+
resolve()
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
reject(new Error([command, ...args].join(' ') + ' --> Error ' + code))
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
}
|
|
97
158
|
}
|
package/src/InstallCommand.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cmd } from "./Cmd";
|
|
2
2
|
import * as fs from "fs"
|
|
3
3
|
import * as path from "path"
|
|
4
|
+
import {green, red, bold} from 'kolorist'
|
|
4
5
|
|
|
5
6
|
import loglevel from 'loglevel'
|
|
6
7
|
import { uploadModule } from "./ModuleCommand";
|
|
@@ -10,8 +11,8 @@ logger.setLevel('debug')
|
|
|
10
11
|
export class InstallCommand extends Cmd {
|
|
11
12
|
constructor(name: string) {
|
|
12
13
|
super(name)
|
|
13
|
-
this.description('upload
|
|
14
|
-
.argument('<node_package>', 'Node Package installed as dependency')
|
|
14
|
+
this.description('npm install and upload xml modules to Cyk server')
|
|
15
|
+
.argument('<node_package>', 'Node Package installed as dev dependency')
|
|
15
16
|
.action(async (node_package: any, options: any) => {
|
|
16
17
|
await this.install(node_package, options)
|
|
17
18
|
})
|
|
@@ -21,18 +22,51 @@ export class InstallCommand extends Cmd {
|
|
|
21
22
|
try {
|
|
22
23
|
await this.prologue(options)
|
|
23
24
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
24
|
-
await this.verifyPackageJson(node_package)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
/**
|
|
27
|
+
* install the Node Package by npm
|
|
28
|
+
* and postinstall script will invoke this 'cyk install' command
|
|
29
|
+
*/
|
|
30
|
+
// await this.installNodePackage(node_package)
|
|
31
|
+
|
|
32
|
+
const installScript = await this.lookupInstallScript(node_package)
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (installScript) {
|
|
35
|
+
/**
|
|
36
|
+
* execute installScript
|
|
37
|
+
*/
|
|
38
|
+
const installPath = path.join('node_modules',node_package,'scripts',installScript)
|
|
39
|
+
await this.runShellCommand(installPath, [])
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
/**
|
|
43
|
+
* default install : upload modules and execute _init.xml
|
|
44
|
+
*/
|
|
45
|
+
console.log()
|
|
46
|
+
console.log('upload modules to server ...')
|
|
47
|
+
const xmlFolder = path.join('node_modules', node_package, 'xml')
|
|
48
|
+
if (!fs.existsSync(xmlFolder) || !fs.statSync(xmlFolder).isDirectory()) {
|
|
49
|
+
throw 'xml folder not found ( ' + xmlFolder + ' )'
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* upload modules to the server
|
|
53
|
+
*/
|
|
54
|
+
let initModule: string | undefined
|
|
55
|
+
const files = fs.readdirSync(xmlFolder)
|
|
56
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
57
|
+
const file = files[ind]
|
|
58
|
+
await uploadModule(path.join(xmlFolder, file), this.dbManager)
|
|
59
|
+
if (file.endsWith('_init.xml')) {
|
|
60
|
+
initModule = file
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
console.log(green('*') + ' upload modules to server' )
|
|
64
|
+
if (initModule) {
|
|
65
|
+
const initPath = path.join(xmlFolder, initModule)
|
|
66
|
+
await this.runShellCommand('npx', ['cyk', 'run', initPath])
|
|
67
|
+
}
|
|
35
68
|
}
|
|
69
|
+
|
|
36
70
|
}
|
|
37
71
|
catch (err) {
|
|
38
72
|
logger.error(err)
|
|
@@ -40,32 +74,41 @@ export class InstallCommand extends Cmd {
|
|
|
40
74
|
}
|
|
41
75
|
|
|
42
76
|
/**
|
|
43
|
-
* method
|
|
77
|
+
* method installNodePackage
|
|
44
78
|
* @param node_package
|
|
45
79
|
*/
|
|
46
|
-
async
|
|
47
|
-
|
|
48
|
-
let packageJson: any
|
|
80
|
+
async installNodePackage(node_package: string) {
|
|
49
81
|
|
|
50
82
|
try {
|
|
51
|
-
|
|
52
|
-
const packageJsonContent = fs.readFileSync('package.json', 'utf8');
|
|
53
|
-
|
|
54
|
-
// Analyse du contenu en tant qu'objet JSON
|
|
55
|
-
packageJson = JSON.parse(packageJsonContent);
|
|
56
|
-
|
|
83
|
+
await this.runShellCommand('npm', ['install', '--save-dev', node_package])
|
|
57
84
|
} catch (error) {
|
|
58
|
-
console.error('Error
|
|
85
|
+
console.error('Error installing ' + node_package + ' :', error);
|
|
59
86
|
throw error
|
|
60
87
|
}
|
|
88
|
+
}
|
|
61
89
|
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
/**
|
|
91
|
+
* method lookupInstallScript
|
|
92
|
+
* @param node_package
|
|
93
|
+
*/
|
|
94
|
+
async lookupInstallScript(node_package: string): Promise<string | undefined> {
|
|
95
|
+
let result: string | undefined
|
|
96
|
+
try {
|
|
97
|
+
const scriptsFolder = path.join('node_modules', node_package, 'scripts')
|
|
98
|
+
if (fs.existsSync(scriptsFolder) && fs.statSync(scriptsFolder).isDirectory()) {
|
|
99
|
+
const files = fs.readdirSync(scriptsFolder)
|
|
100
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
101
|
+
const file = files[ind]
|
|
102
|
+
if (file.startsWith('install.')) {
|
|
103
|
+
result = file
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
throw err
|
|
64
111
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
112
|
}
|
|
69
113
|
|
|
70
|
-
|
|
71
114
|
}
|