@cyklang/cli 0.5.3 → 0.5.5
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/AssetCommand.d.ts +24 -0
- package/build/AssetCommand.js +207 -178
- package/build/Cmd.d.ts +17 -12
- package/build/Cmd.js +82 -39
- package/build/DBClient.js +1 -0
- package/build/InstallCommand.d.ts +8 -7
- package/build/InstallCommand.js +148 -73
- package/build/ModuleCommand.d.ts +6 -0
- package/build/ModuleCommand.js +12 -1
- package/build/UninstallCommand.d.ts +20 -0
- package/build/UninstallCommand.js +164 -0
- package/build/index.js +3 -1
- package/package.json +2 -2
- package/src/AssetCommand.ts +212 -197
- package/src/Cmd.ts +59 -38
- package/src/DBClient.ts +1 -0
- package/src/InstallCommand.ts +156 -75
- package/src/ModuleCommand.ts +12 -0
- package/src/UninstallCommand.ts +145 -0
- package/src/index.ts +3 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Cmd } from "./Cmd";
|
|
2
|
+
import { DBManager, DBRemote } from "@cyklang/core";
|
|
2
3
|
export declare class InstallCommand extends Cmd {
|
|
3
|
-
constructor(name: string);
|
|
4
|
-
install(node_package: string, options: any): Promise<void>;
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
5
|
+
* constructor
|
|
6
|
+
* @param name
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
constructor(name: string);
|
|
10
9
|
/**
|
|
11
|
-
* method
|
|
10
|
+
* method install
|
|
12
11
|
* @param node_package
|
|
12
|
+
* @param options
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
install(node_package: string, options: any): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export declare function installPackage(node_package: string, dbManager: DBManager, dbRemote: DBRemote): Promise<void>;
|
package/build/InstallCommand.js
CHANGED
|
@@ -26,110 +26,185 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.InstallCommand = void 0;
|
|
29
|
+
exports.installPackage = 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
33
|
const kolorist_1 = require("kolorist");
|
|
34
34
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
35
35
|
const ModuleCommand_1 = require("./ModuleCommand");
|
|
36
|
+
const UninstallCommand_1 = require("./UninstallCommand");
|
|
37
|
+
const AssetCommand_1 = require("./AssetCommand");
|
|
36
38
|
const logger = loglevel_1.default.getLogger('InstallCommand.ts');
|
|
37
39
|
logger.setLevel('debug');
|
|
38
40
|
class InstallCommand extends Cmd_1.Cmd {
|
|
41
|
+
/**
|
|
42
|
+
* constructor
|
|
43
|
+
* @param name
|
|
44
|
+
*/
|
|
39
45
|
constructor(name) {
|
|
40
46
|
super(name);
|
|
41
|
-
this.description('npm install and
|
|
47
|
+
this.description('npm install and run install script')
|
|
42
48
|
.argument('<node_package>', 'Node Package installed as dev dependency')
|
|
43
49
|
.action(async (node_package, options) => {
|
|
44
50
|
await this.install(node_package, options);
|
|
45
51
|
});
|
|
46
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* method install
|
|
55
|
+
* @param node_package
|
|
56
|
+
* @param options
|
|
57
|
+
*/
|
|
47
58
|
async install(node_package, options) {
|
|
48
59
|
try {
|
|
49
60
|
await this.prologue(options);
|
|
50
|
-
if (this.dbManager === undefined)
|
|
51
|
-
throw 'dbManager undefined';
|
|
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, []);
|
|
64
|
-
}
|
|
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
|
-
}
|
|
92
|
-
}
|
|
61
|
+
if (this.dbManager === undefined || !this.dbRemote)
|
|
62
|
+
throw 'dbManager or dbRemote undefined';
|
|
63
|
+
await installPackage(node_package, this.dbManager, this.dbRemote);
|
|
93
64
|
}
|
|
94
65
|
catch (err) {
|
|
95
66
|
logger.error(err);
|
|
96
67
|
}
|
|
97
68
|
}
|
|
69
|
+
}
|
|
70
|
+
exports.InstallCommand = InstallCommand;
|
|
71
|
+
async function installPackage(node_package, dbManager, dbRemote) {
|
|
98
72
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @param node_package
|
|
73
|
+
* install the Node Package
|
|
101
74
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
75
|
+
await installNodePackage(node_package, dbManager);
|
|
76
|
+
const installScript = await lookupInstallScript(node_package);
|
|
77
|
+
if (installScript) {
|
|
78
|
+
/**
|
|
79
|
+
* execute installScript
|
|
80
|
+
*/
|
|
81
|
+
const installPath = path.join('node_modules', node_package, 'scripts', installScript);
|
|
82
|
+
await (0, Cmd_1.runShellCommand)(installPath, []);
|
|
110
83
|
}
|
|
84
|
+
else {
|
|
85
|
+
/**
|
|
86
|
+
* default install : upload modules and execute _init.xml
|
|
87
|
+
*/
|
|
88
|
+
await defaultInstallScript(node_package, dbManager, dbRemote);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.installPackage = installPackage;
|
|
92
|
+
/**
|
|
93
|
+
* method defaultInstallScript
|
|
94
|
+
* @param node_package
|
|
95
|
+
*/
|
|
96
|
+
async function defaultInstallScript(node_package, dbManager, dbRemote) {
|
|
97
|
+
console.log();
|
|
98
|
+
console.log('Default install script');
|
|
111
99
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param node_package
|
|
100
|
+
* upload package assets
|
|
114
101
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
102
|
+
await uploadPackageAssets(node_package, dbManager, dbRemote);
|
|
103
|
+
/**
|
|
104
|
+
* upload package modules to the server
|
|
105
|
+
*/
|
|
106
|
+
await uploadPackageModules(node_package, dbManager);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* function uploadPackageAssets
|
|
110
|
+
* @param node_package
|
|
111
|
+
* @param dbManager
|
|
112
|
+
*/
|
|
113
|
+
async function uploadPackageAssets(node_package, dbManager, dbRemote) {
|
|
114
|
+
const assetFolder = path.join('node_modules', node_package, 'asset');
|
|
115
|
+
if (!fs.existsSync(assetFolder) || !fs.statSync(assetFolder).isDirectory()) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
console.log();
|
|
119
|
+
console.log('upload assets to server ...');
|
|
120
|
+
if (!dbManager)
|
|
121
|
+
throw 'dbManager undefined';
|
|
122
|
+
const items = fs.readdirSync(assetFolder);
|
|
123
|
+
for (let ind = 0; ind < items.length; ind++) {
|
|
124
|
+
const item = items[ind];
|
|
125
|
+
const itemPath = path.join(assetFolder, item);
|
|
126
|
+
if (fs.statSync(itemPath).isDirectory()) {
|
|
127
|
+
const dest = "/" + item + "/";
|
|
128
|
+
await (0, AssetCommand_1.uploadDirectory)(itemPath, dest, { yes: true }, dbManager, dbRemote);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const dest = "/" + item;
|
|
132
|
+
const fd = { path: path.join(assetFolder, item), mtime: new Date() };
|
|
133
|
+
await (0, AssetCommand_1.uploadAsset)(fd, dest, dbManager, dbRemote);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
console.log((0, kolorist_1.green)('*') + ' upload assets to server');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* function uploadModules
|
|
140
|
+
* @param node_package
|
|
141
|
+
* @param dbManager
|
|
142
|
+
*/
|
|
143
|
+
async function uploadPackageModules(node_package, dbManager) {
|
|
144
|
+
const moduleFolder = path.join('node_modules', node_package, 'module');
|
|
145
|
+
if (!fs.existsSync(moduleFolder) || !fs.statSync(moduleFolder).isDirectory()) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
console.log();
|
|
149
|
+
console.log('upload modules to server ...');
|
|
150
|
+
let initModule;
|
|
151
|
+
const files = fs.readdirSync(moduleFolder);
|
|
152
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
153
|
+
const file = files[ind];
|
|
154
|
+
if (!dbManager)
|
|
155
|
+
throw 'dbManager undefined';
|
|
156
|
+
await (0, ModuleCommand_1.uploadModule)(path.join(moduleFolder, file), dbManager);
|
|
157
|
+
if (file.endsWith('_init.xml')) {
|
|
158
|
+
initModule = file;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
console.log((0, kolorist_1.green)('*') + ' upload modules to server');
|
|
162
|
+
if (initModule) {
|
|
163
|
+
const initPath = path.join(moduleFolder, initModule);
|
|
164
|
+
await (0, Cmd_1.runShellCommand)('npx', ['cyk', 'run', initPath]);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* method installNodePackage
|
|
169
|
+
* @param node_package
|
|
170
|
+
*/
|
|
171
|
+
async function installNodePackage(node_package, dbManager) {
|
|
172
|
+
try {
|
|
173
|
+
const packageJson = await (0, Cmd_1.readPackageJson)();
|
|
174
|
+
if (packageJson.devDependencies && packageJson.devDependencies[node_package]
|
|
175
|
+
|| packageJson.dependencies && packageJson.dependencies[node_package]) {
|
|
176
|
+
console.log(node_package + ' already installed. We uninstall it first');
|
|
177
|
+
if (!dbManager)
|
|
178
|
+
throw 'dbManager undefined';
|
|
179
|
+
await (0, UninstallCommand_1.uninstallPackage)(node_package, dbManager);
|
|
180
|
+
}
|
|
181
|
+
await (0, Cmd_1.runShellCommand)('npm', ['install', '--save-dev', node_package]);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
console.error('Error installing ' + node_package + ' :', error);
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* function lookupInstallScript
|
|
190
|
+
* @param node_package
|
|
191
|
+
*/
|
|
192
|
+
async function lookupInstallScript(node_package) {
|
|
193
|
+
let result;
|
|
194
|
+
try {
|
|
195
|
+
const scriptsFolder = path.join('node_modules', node_package, 'scripts');
|
|
196
|
+
if (fs.existsSync(scriptsFolder) && fs.statSync(scriptsFolder).isDirectory()) {
|
|
197
|
+
const files = fs.readdirSync(scriptsFolder);
|
|
198
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
199
|
+
const file = files[ind];
|
|
200
|
+
if (file.startsWith('install.')) {
|
|
201
|
+
result = file;
|
|
126
202
|
}
|
|
127
203
|
}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
throw err;
|
|
132
204
|
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
throw err;
|
|
133
209
|
}
|
|
134
210
|
}
|
|
135
|
-
exports.InstallCommand = InstallCommand;
|
package/build/ModuleCommand.d.ts
CHANGED
|
@@ -10,3 +10,9 @@ export declare class ModuleCommand extends Command {
|
|
|
10
10
|
* @param dbManager
|
|
11
11
|
*/
|
|
12
12
|
export declare function uploadModule(file: string, dbManager: DBManager): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* function deleteModule
|
|
15
|
+
* @param dbname
|
|
16
|
+
* @param dbManager
|
|
17
|
+
*/
|
|
18
|
+
export declare function deleteModule(dbname: string, dbManager: DBManager): Promise<void>;
|
package/build/ModuleCommand.js
CHANGED
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.uploadModule = exports.ModuleCommand = void 0;
|
|
30
|
+
exports.deleteModule = exports.uploadModule = exports.ModuleCommand = void 0;
|
|
31
31
|
const core_1 = require("@cyklang/core");
|
|
32
32
|
const fs = __importStar(require("fs"));
|
|
33
33
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
@@ -166,6 +166,7 @@ async function uploadModule(file, dbManager) {
|
|
|
166
166
|
logger.info('module ' + dbname + ' added with ID ' + id);
|
|
167
167
|
}
|
|
168
168
|
else {
|
|
169
|
+
logger.debug('module exists : ' + dbModuleExist.dbname + ', id ' + dbModuleExist.id);
|
|
169
170
|
// update
|
|
170
171
|
dbModuleExist.source = source;
|
|
171
172
|
dbModuleExist.access = tag.attributes.ACCESS;
|
|
@@ -280,3 +281,13 @@ class ModuleDelete extends Cmd_1.Cmd {
|
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* function deleteModule
|
|
286
|
+
* @param dbname
|
|
287
|
+
* @param dbManager
|
|
288
|
+
*/
|
|
289
|
+
async function deleteModule(dbname, dbManager) {
|
|
290
|
+
const dbClient = new DBClient_1.DBClient(dbManager);
|
|
291
|
+
await dbClient.deleteModule(dbname);
|
|
292
|
+
}
|
|
293
|
+
exports.deleteModule = deleteModule;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Cmd } from "./Cmd";
|
|
2
|
+
import { DBManager } from "@cyklang/core";
|
|
3
|
+
export declare class UninstallCommand extends Cmd {
|
|
4
|
+
/**
|
|
5
|
+
* constructor
|
|
6
|
+
* @param name
|
|
7
|
+
*/
|
|
8
|
+
constructor(name: string);
|
|
9
|
+
/**
|
|
10
|
+
* method uninstall
|
|
11
|
+
* @param node_package
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
uninstall(node_package: string, options: any): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* function uninstallPackage
|
|
18
|
+
* @param node_package
|
|
19
|
+
*/
|
|
20
|
+
export declare function uninstallPackage(node_package: string, dbManager: DBManager): Promise<void>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.uninstallPackage = exports.UninstallCommand = void 0;
|
|
30
|
+
const Cmd_1 = require("./Cmd");
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const kolorist_1 = require("kolorist");
|
|
34
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
35
|
+
const ModuleCommand_1 = require("./ModuleCommand");
|
|
36
|
+
const logger = loglevel_1.default.getLogger('UninstallCommand.ts');
|
|
37
|
+
logger.setLevel('debug');
|
|
38
|
+
class UninstallCommand extends Cmd_1.Cmd {
|
|
39
|
+
/**
|
|
40
|
+
* constructor
|
|
41
|
+
* @param name
|
|
42
|
+
*/
|
|
43
|
+
constructor(name) {
|
|
44
|
+
super(name);
|
|
45
|
+
this.description('run uninstall script and npm uninstall command')
|
|
46
|
+
.argument('<node_package>', 'Node Package installed as dev dependency')
|
|
47
|
+
.action(async (node_package, options) => {
|
|
48
|
+
await this.uninstall(node_package, options);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* method uninstall
|
|
53
|
+
* @param node_package
|
|
54
|
+
* @param options
|
|
55
|
+
*/
|
|
56
|
+
async uninstall(node_package, options) {
|
|
57
|
+
try {
|
|
58
|
+
await this.prologue(options);
|
|
59
|
+
if (this.dbManager === undefined)
|
|
60
|
+
throw 'dbManager undefined';
|
|
61
|
+
await uninstallPackage(node_package, this.dbManager);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
logger.error(err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.UninstallCommand = UninstallCommand;
|
|
69
|
+
/**
|
|
70
|
+
* function uninstallPackage
|
|
71
|
+
* @param node_package
|
|
72
|
+
*/
|
|
73
|
+
async function uninstallPackage(node_package, dbManager) {
|
|
74
|
+
const uninstallScript = await lookupUninstallScript(node_package);
|
|
75
|
+
if (uninstallScript) {
|
|
76
|
+
/**
|
|
77
|
+
* run scripts/uninstall
|
|
78
|
+
*/
|
|
79
|
+
const uninstallPath = path.join('node_modules', node_package, 'scripts', uninstallScript);
|
|
80
|
+
await (0, Cmd_1.runShellCommand)(uninstallPath, []);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
/**
|
|
84
|
+
* default uninstall :
|
|
85
|
+
*/
|
|
86
|
+
await defaultUninstallScript(node_package, dbManager);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* uninstall the node package
|
|
90
|
+
*/
|
|
91
|
+
await uninstallNodePackage(node_package);
|
|
92
|
+
}
|
|
93
|
+
exports.uninstallPackage = uninstallPackage;
|
|
94
|
+
/**
|
|
95
|
+
* method defaultUninstallScript
|
|
96
|
+
* @param node_package
|
|
97
|
+
*/
|
|
98
|
+
async function defaultUninstallScript(node_package, dbManager) {
|
|
99
|
+
console.log();
|
|
100
|
+
console.log('Default uninstall script');
|
|
101
|
+
/**
|
|
102
|
+
* delete package modules from server
|
|
103
|
+
*/
|
|
104
|
+
await deletePackageModules(node_package, dbManager);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* function deletePackageModules
|
|
108
|
+
* @param node_package
|
|
109
|
+
* @param dbManager
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
async function deletePackageModules(node_package, dbManager) {
|
|
113
|
+
const moduleFolder = path.join('node_modules', node_package, 'module');
|
|
114
|
+
if (!fs.existsSync(moduleFolder) || !fs.statSync(moduleFolder).isDirectory()) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log();
|
|
118
|
+
console.log('delete modules from server ...');
|
|
119
|
+
const files = fs.readdirSync(moduleFolder);
|
|
120
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
121
|
+
const file = files[ind];
|
|
122
|
+
if (!dbManager)
|
|
123
|
+
throw 'dbManager undefined';
|
|
124
|
+
const fileInfo = path.parse(file);
|
|
125
|
+
await (0, ModuleCommand_1.deleteModule)(fileInfo.name, dbManager);
|
|
126
|
+
}
|
|
127
|
+
console.log((0, kolorist_1.green)('*') + ' delete modules from server');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* function uninstallNodePackage
|
|
131
|
+
* @param node_package
|
|
132
|
+
*/
|
|
133
|
+
async function uninstallNodePackage(node_package) {
|
|
134
|
+
try {
|
|
135
|
+
await (0, Cmd_1.runShellCommand)('npm', ['uninstall', '--save-dev', node_package]);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Error uninstalling ' + node_package + ' :', error);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* function lookupUninstallScript
|
|
144
|
+
* @param node_package
|
|
145
|
+
*/
|
|
146
|
+
async function lookupUninstallScript(node_package) {
|
|
147
|
+
let result;
|
|
148
|
+
try {
|
|
149
|
+
const scriptsFolder = path.join('node_modules', node_package, 'scripts');
|
|
150
|
+
if (fs.existsSync(scriptsFolder) && fs.statSync(scriptsFolder).isDirectory()) {
|
|
151
|
+
const files = fs.readdirSync(scriptsFolder);
|
|
152
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
153
|
+
const file = files[ind];
|
|
154
|
+
if (file.startsWith('uninstall.')) {
|
|
155
|
+
result = file;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
164
|
+
}
|
package/build/index.js
CHANGED
|
@@ -15,13 +15,15 @@ const RunCommand_1 = require("./RunCommand");
|
|
|
15
15
|
const InstallCommand_1 = require("./InstallCommand");
|
|
16
16
|
const AssetCommand_1 = require("./AssetCommand");
|
|
17
17
|
const OpenCommand_1 = require("./OpenCommand");
|
|
18
|
+
const UninstallCommand_1 = require("./UninstallCommand");
|
|
18
19
|
const logger = loglevel_1.default.getLogger("index.ts");
|
|
19
20
|
logger.setLevel("debug");
|
|
20
21
|
const program = new commander_1.Command();
|
|
21
22
|
program.name('cyk').description('cyklang CLI')
|
|
22
|
-
.version('0.
|
|
23
|
+
.version('0.5.5');
|
|
23
24
|
program.addCommand(new InstallCommand_1.InstallCommand('install'));
|
|
24
25
|
program.addCommand(new InstallCommand_1.InstallCommand('i'));
|
|
26
|
+
program.addCommand(new UninstallCommand_1.UninstallCommand('uninstall'));
|
|
25
27
|
program.addCommand(new AssetCommand_1.AssetCommand('asset', 'manage assets'));
|
|
26
28
|
program.addCommand(new AssetCommand_1.AssetCommand('a', 'manage assets'));
|
|
27
29
|
program.addCommand(new ModuleCommand_1.ModuleCommand('module'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyklang/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "cyklang CLI",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cyklang/core": "^0.5.
|
|
20
|
+
"@cyklang/core": "^0.5.3",
|
|
21
21
|
"commander": "^9.4.0",
|
|
22
22
|
"dotenv": "^16.0.1",
|
|
23
23
|
"form-data": "^4.0.0",
|