@adinsure-ops/ops-cli 4.0.0-rc10
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/CHANGELOGS.md +56 -0
- package/LICENSE +1 -0
- package/README.md +725 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/command.base.d.ts +17 -0
- package/lib/command.base.jira.d.ts +11 -0
- package/lib/command.base.jira.js +37 -0
- package/lib/command.base.js +73 -0
- package/lib/commands/doctor.d.ts +54 -0
- package/lib/commands/doctor.js +311 -0
- package/lib/commands/download/client.d.ts +17 -0
- package/lib/commands/download/client.js +71 -0
- package/lib/commands/download/identity-server.d.ts +17 -0
- package/lib/commands/download/identity-server.js +71 -0
- package/lib/commands/download/platform.d.ts +18 -0
- package/lib/commands/download/platform.js +72 -0
- package/lib/commands/download/scheduler.d.ts +17 -0
- package/lib/commands/download/scheduler.js +71 -0
- package/lib/commands/download/server.d.ts +17 -0
- package/lib/commands/download/server.js +71 -0
- package/lib/commands/download/studio.d.ts +19 -0
- package/lib/commands/download/studio.js +88 -0
- package/lib/commands/gitlab/next-nightly-tag.d.ts +29 -0
- package/lib/commands/gitlab/next-nightly-tag.js +169 -0
- package/lib/commands/jira/issue.d.ts +17 -0
- package/lib/commands/jira/issue.js +31 -0
- package/lib/commands/jira/labels.d.ts +22 -0
- package/lib/commands/jira/labels.js +70 -0
- package/lib/commands/log/add.d.ts +17 -0
- package/lib/commands/log/add.js +107 -0
- package/lib/commands/log/generate.d.ts +22 -0
- package/lib/commands/log/generate.js +155 -0
- package/lib/commands/log/validate.d.ts +11 -0
- package/lib/commands/log/validate.js +58 -0
- package/lib/commands/login.d.ts +24 -0
- package/lib/commands/login.js +154 -0
- package/lib/commands/npm/check-publish.d.ts +16 -0
- package/lib/commands/npm/check-publish.js +77 -0
- package/lib/commands/npm/publish.d.ts +22 -0
- package/lib/commands/npm/publish.js +162 -0
- package/lib/commands/prepare-content.d.ts +29 -0
- package/lib/commands/prepare-content.js +386 -0
- package/lib/commands/sql.d.ts +24 -0
- package/lib/commands/sql.js +147 -0
- package/lib/commands/translate.d.ts +37 -0
- package/lib/commands/translate.js +149 -0
- package/lib/commands/version.d.ts +48 -0
- package/lib/commands/version.js +267 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +9 -0
- package/lib/hooks/init/version-override.d.ts +2 -0
- package/lib/hooks/init/version-override.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/lib/command.d.ts +9 -0
- package/lib/lib/command.js +71 -0
- package/lib/lib/npm.d.ts +15 -0
- package/lib/lib/npm.js +79 -0
- package/lib/lib/npmrc.d.ts +17 -0
- package/lib/lib/npmrc.js +44 -0
- package/lib/security/cache.d.ts +7 -0
- package/lib/security/cache.js +33 -0
- package/lib/security/context.d.ts +58 -0
- package/lib/security/context.js +228 -0
- package/lib/types/changelog.types.d.ts +6 -0
- package/lib/types/changelog.types.js +2 -0
- package/lib/types/npm.types.d.ts +34 -0
- package/lib/types/npm.types.js +2 -0
- package/oclif.manifest.json +1 -0
- package/package.json +116 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
const cli_ux_1 = require("cli-ux");
|
|
6
|
+
const fs = require("fs-extra");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const command_base_1 = require("../command.base");
|
|
9
|
+
class CopyTransformation {
|
|
10
|
+
constructor(srcPath, dstPath) {
|
|
11
|
+
this.name = this.constructor.name;
|
|
12
|
+
this.srcPath = srcPath;
|
|
13
|
+
this.dstPath = dstPath;
|
|
14
|
+
}
|
|
15
|
+
transform() {
|
|
16
|
+
try {
|
|
17
|
+
fs.accessSync(this.srcPath, fs.constants.R_OK);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (err.code === 'ENOENT') {
|
|
21
|
+
throw new Error(`${this.name}: source file does not exist <${this.srcPath}>`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
cli_ux_1.default.log(`Copying from ${this.srcPath} to ${this.dstPath}`);
|
|
28
|
+
try {
|
|
29
|
+
fs.copySync(this.srcPath, this.dstPath, { overwrite: true });
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class JavascriptTransformation {
|
|
37
|
+
constructor(srcPath, dstPath, javascriptFile, functionName) {
|
|
38
|
+
this.name = this.constructor.name;
|
|
39
|
+
this.srcPath = srcPath;
|
|
40
|
+
this.dstPath = dstPath;
|
|
41
|
+
this.jsFile = path.resolve(javascriptFile);
|
|
42
|
+
this.functionName = functionName;
|
|
43
|
+
}
|
|
44
|
+
importTransformationModule() {
|
|
45
|
+
try {
|
|
46
|
+
return require(this.jsFile);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
50
|
+
throw new Error(`${this.name}: module file ${this.jsFile} not found <${this.srcPath}>`);
|
|
51
|
+
}
|
|
52
|
+
else if (err instanceof SyntaxError) {
|
|
53
|
+
throw new Error(`${this.name}: ${err} in \'${this.jsFile}\' <${this.srcPath}>`);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
executeTransformationFunction(transformationModule) {
|
|
59
|
+
try {
|
|
60
|
+
let result = transformationModule[this.functionName](this.srcPath);
|
|
61
|
+
if (typeof (result) !== 'string') {
|
|
62
|
+
throw new Error(`${this.name}: transformation functions must return string, ${this.functionName} returned ${typeof (result)} <${this.srcPath}>`);
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
if (err instanceof TypeError) {
|
|
68
|
+
throw new Error(`${this.name}: invalid function \'${this.functionName}\' in ${this.jsFile} <${this.srcPath}>`);
|
|
69
|
+
}
|
|
70
|
+
/*
|
|
71
|
+
Rethrow anything errors that were thrown in the above try block
|
|
72
|
+
*/
|
|
73
|
+
if (err.message && err.message.search(`${this.name}`.length > 0)) {
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
transform() {
|
|
80
|
+
// Check if source exists, if not, issue a warning
|
|
81
|
+
try {
|
|
82
|
+
fs.accessSync(this.srcPath);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (err.code === 'ENOENT') {
|
|
86
|
+
let errMsg = `${this.name}: source does not exist, relying on transformation to find proper source file <${this.srcPath}>`;
|
|
87
|
+
cli_ux_1.default.log(`${chalk_1.default.yellow(errMsg)}`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
cli_ux_1.default.log(`Transforming from ${this.srcPath} to ${this.dstPath} using ${this.jsFile} function ${this.functionName}`);
|
|
94
|
+
// Import transformation module
|
|
95
|
+
let transModule = this.importTransformationModule();
|
|
96
|
+
// Execute transformation function
|
|
97
|
+
let transResult = this.executeTransformationFunction(transModule);
|
|
98
|
+
// Write output to destination file
|
|
99
|
+
try {
|
|
100
|
+
fs.outputFileSync(this.dstPath, transResult, { encoding: 'utf-8', mode: 0o644, flag: 'w' });
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
class RemovalTransformation {
|
|
108
|
+
constructor(srcPath) {
|
|
109
|
+
this.name = this.constructor.name;
|
|
110
|
+
this.srcPath = srcPath;
|
|
111
|
+
}
|
|
112
|
+
transform() {
|
|
113
|
+
try {
|
|
114
|
+
fs.accessSync(this.srcPath, fs.constants.W_OK);
|
|
115
|
+
cli_ux_1.default.log(`Removing ${this.srcPath}.`);
|
|
116
|
+
fs.removeSync(this.srcPath);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
if (err.code === 'ENOENT') {
|
|
120
|
+
let errMsg = `${this.name}: target does not exist, skipping removal <${this.srcPath}>`;
|
|
121
|
+
cli_ux_1.default.log(`${chalk_1.default.yellow(errMsg)}`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error(`${this.name}: ${err} <${this.srcPath}>`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class PrepareContent extends command_base_1.default {
|
|
130
|
+
async parseDotfileLine(line, sourceDirectory) {
|
|
131
|
+
const re = RegExp('^([!#]{1})?(.+?)({.*?})?$');
|
|
132
|
+
let m = line.match(re);
|
|
133
|
+
let dotfileLine = {
|
|
134
|
+
prefix: m[1],
|
|
135
|
+
source: path.join(sourceDirectory, path.normalize(m[2].trim())),
|
|
136
|
+
transformData: m[3]
|
|
137
|
+
};
|
|
138
|
+
/*
|
|
139
|
+
Sanity check on source file name. Should not contain "{", ":", or "}" characters
|
|
140
|
+
*/
|
|
141
|
+
const valRe = RegExp('[{:}]+');
|
|
142
|
+
let vm = dotfileLine.source.match(valRe);
|
|
143
|
+
if (vm !== null) {
|
|
144
|
+
throw new SyntaxError(`<${PrepareContent.dotfile}> source file name '${dotfileLine.source}' contains invalid character '${vm[0]}'`);
|
|
145
|
+
}
|
|
146
|
+
return dotfileLine;
|
|
147
|
+
}
|
|
148
|
+
async readDotfile(sourceDirectory) {
|
|
149
|
+
let file_content;
|
|
150
|
+
try {
|
|
151
|
+
file_content = fs.readFileSync(path.join(sourceDirectory, PrepareContent.dotfile), 'utf-8');
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
if (err.code === 'ENOENT') {
|
|
155
|
+
let errMsg = `.opsprepare file not found in ${path.resolve(sourceDirectory)}`;
|
|
156
|
+
throw new Error(errMsg);
|
|
157
|
+
}
|
|
158
|
+
throw new Error(err.message);
|
|
159
|
+
}
|
|
160
|
+
let lines = file_content.split(/\r?\n/).filter(line => line.length !== 0);
|
|
161
|
+
const lineParse = lines.map(line => {
|
|
162
|
+
return this.parseDotfileLine(line.trim(), sourceDirectory);
|
|
163
|
+
});
|
|
164
|
+
const parsedLines = Promise.all(lineParse).then(lines => lines.filter(line => line.prefix !== '#'));
|
|
165
|
+
return parsedLines;
|
|
166
|
+
}
|
|
167
|
+
async getTransformation(lineData, baseSourcedir, baseDestinationDir) {
|
|
168
|
+
const targetPath = path.join(baseDestinationDir, lineData.source);
|
|
169
|
+
/*
|
|
170
|
+
Anything prefixed with ! is a removal
|
|
171
|
+
*/
|
|
172
|
+
if (lineData.prefix === '!') {
|
|
173
|
+
return new RemovalTransformation(targetPath);
|
|
174
|
+
}
|
|
175
|
+
/*
|
|
176
|
+
In case transformation data is present, prepare transformations based on requested plugin.
|
|
177
|
+
*/
|
|
178
|
+
if (lineData.transformData) {
|
|
179
|
+
const re = RegExp('^{(.+?):.*}$');
|
|
180
|
+
const transformType = lineData.transformData.match(re)[1];
|
|
181
|
+
switch (transformType) {
|
|
182
|
+
case 'cp': {
|
|
183
|
+
const rePath = RegExp('^{cp:([^:]+)}$');
|
|
184
|
+
const mPath = lineData.transformData.match(rePath);
|
|
185
|
+
if (!mPath) {
|
|
186
|
+
throw new SyntaxError(`<${PrepareContent.dotfile}> syntax '${lineData.transformData}' is invalid for 'cp' transformation type`);
|
|
187
|
+
}
|
|
188
|
+
const tPath = path.join(baseDestinationDir, path.dirname(lineData.source), mPath[1]);
|
|
189
|
+
return new CopyTransformation(lineData.source, tPath);
|
|
190
|
+
}
|
|
191
|
+
case 'js': {
|
|
192
|
+
/* TODO: Some sanity checking will be required after regex matching
|
|
193
|
+
to make sure everything was matched and is defined
|
|
194
|
+
*/
|
|
195
|
+
// Parse transformation data
|
|
196
|
+
const reData = RegExp('^{js:(.+?):(.+)}$');
|
|
197
|
+
const mData = lineData.transformData.match(reData);
|
|
198
|
+
if (!mData) {
|
|
199
|
+
throw new SyntaxError(`<${PrepareContent.dotfile}> syntax '${lineData.transformData}' is invalid for 'js' transformation type`);
|
|
200
|
+
}
|
|
201
|
+
const jsFile = path.join(baseSourcedir, mData[1]);
|
|
202
|
+
const jsFunc = mData[2];
|
|
203
|
+
// File path absolute. Should it be relative to the transformation function?
|
|
204
|
+
const filePath = path.resolve(lineData.source);
|
|
205
|
+
return new JavascriptTransformation(filePath, targetPath, jsFile, jsFunc);
|
|
206
|
+
}
|
|
207
|
+
default: {
|
|
208
|
+
const p = lineData.prefix ? lineData.prefix : '';
|
|
209
|
+
const s = lineData.source;
|
|
210
|
+
const t = lineData.transformData ? lineData.transformData : '';
|
|
211
|
+
this.error(`No valid transformation can be extrapolated from ${p}${s}${t}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/*
|
|
216
|
+
Return default transformation
|
|
217
|
+
*/
|
|
218
|
+
return new CopyTransformation(lineData.source, targetPath);
|
|
219
|
+
}
|
|
220
|
+
async prepareTransformations(linesData, baseSourceDir, baseDestinationDir) {
|
|
221
|
+
const transformations = linesData.map(line => {
|
|
222
|
+
return this.getTransformation(line, baseSourceDir, baseDestinationDir);
|
|
223
|
+
});
|
|
224
|
+
return Promise.all(transformations);
|
|
225
|
+
}
|
|
226
|
+
/*
|
|
227
|
+
This function divides transformations into execution groups based on their class
|
|
228
|
+
and runs transformations for each group
|
|
229
|
+
*/
|
|
230
|
+
async runTransformations(transformations) {
|
|
231
|
+
let copyTransformList = [];
|
|
232
|
+
let modlueTransformList = [];
|
|
233
|
+
let excludeList = [];
|
|
234
|
+
// Sort transformation into two lists
|
|
235
|
+
transformations.forEach(t => {
|
|
236
|
+
if (t instanceof CopyTransformation) {
|
|
237
|
+
copyTransformList.push(t);
|
|
238
|
+
}
|
|
239
|
+
else if (t instanceof RemovalTransformation) {
|
|
240
|
+
excludeList.push(t);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
modlueTransformList.push(t);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const t = async (transformation) => {
|
|
247
|
+
try {
|
|
248
|
+
transformation.transform();
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
return Promise.reject(err.message);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const doCopyTransform = copyTransformList.map(t);
|
|
255
|
+
const doModuleTransform = modlueTransformList.map(t);
|
|
256
|
+
const doExclude = excludeList.map(t);
|
|
257
|
+
/* Copy first, then transform and finally remove files. This should
|
|
258
|
+
ensure that transformations can overwrite previous copies. Removals
|
|
259
|
+
can still erase transformations though. If needed, we can remove
|
|
260
|
+
before transforming.
|
|
261
|
+
*/
|
|
262
|
+
await Promise.all(doCopyTransform);
|
|
263
|
+
await Promise.all(doModuleTransform);
|
|
264
|
+
await Promise.all(doExclude);
|
|
265
|
+
}
|
|
266
|
+
/*
|
|
267
|
+
Validates file system on source repository by checking if files or directories exist
|
|
268
|
+
*/
|
|
269
|
+
/*
|
|
270
|
+
async validate(arr: string[][], source: string): Promise<boolean> {
|
|
271
|
+
//this.log(`${chalk.blue('Validating if files and directories exist.')}`);
|
|
272
|
+
cli.action.start(`${chalk.blue('Validating if files and directories exist')}`, '', {stdout: true});
|
|
273
|
+
for (let a of arr[0]) {
|
|
274
|
+
let element_path = path.join(source, a);
|
|
275
|
+
if(!(fs.existsSync(path.join(element_path)))) {
|
|
276
|
+
this.log(`${chalk.red('File or directory: ' + path.join(element_path) + ' could not be found')}`);
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (let a of arr[1]) {
|
|
281
|
+
let element_path = path.join(source, a);
|
|
282
|
+
if(!(fs.existsSync(element_path))) {
|
|
283
|
+
this.log(`${chalk.red('File or directory: ' + element_path + ' could not be found')}`);
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//this.log(`${chalk.green('Validation done.')}`);
|
|
289
|
+
cli.action.stop(`${chalk.green('done')}`);
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
*/
|
|
293
|
+
/*
|
|
294
|
+
This function copies elements and removes excluded ones.
|
|
295
|
+
*/
|
|
296
|
+
/*
|
|
297
|
+
async copyWorkspace(arr: string[][], dest: string, source: string): Promise<any> {
|
|
298
|
+
if (await this.validate(arr, source)) {
|
|
299
|
+
cli.action.start(`${chalk.blue('Preparing content')}`, '', {stdout: true});
|
|
300
|
+
arr[0].forEach(a => {
|
|
301
|
+
this.log('Copying: ', path.join(source, a));
|
|
302
|
+
fs.copySync(path.join(source, a), path.join(dest, a), {overwrite: true});
|
|
303
|
+
});
|
|
304
|
+
this.log(`${chalk.green('Copying done.')}`);
|
|
305
|
+
this.log(`${chalk.blue('Removing excluded elements.')}`);
|
|
306
|
+
arr[1].forEach(a => {
|
|
307
|
+
let curPath = path.join(dest, a);
|
|
308
|
+
if (fs.pathExistsSync(curPath)) {
|
|
309
|
+
if (fs.lstatSync(curPath).isFile()) {
|
|
310
|
+
try {
|
|
311
|
+
fs.removeSync(curPath);
|
|
312
|
+
this.log('Removing file: ', curPath);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
cli.action.stop(`${chalk.red('failed')}`);
|
|
315
|
+
this.error(error.message);
|
|
316
|
+
}
|
|
317
|
+
} else if (fs.lstatSync(curPath).isDirectory()) {
|
|
318
|
+
try {
|
|
319
|
+
fs.removeSync(curPath);
|
|
320
|
+
this.log('Removing dir: ', curPath);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
cli.action.stop(`${chalk.red('failed')}`);
|
|
323
|
+
this.error(error.message);
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
cli.action.stop(`${chalk.red('error')}`);
|
|
327
|
+
this.error('Type not file or directory');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
this.log(`${chalk.green('Removing done.')}`);
|
|
332
|
+
cli.action.stop(`${chalk.green('done')}`);
|
|
333
|
+
} else {
|
|
334
|
+
cli.action.stop(`${chalk.red('error')}`);
|
|
335
|
+
this.error('Content validation failed.');
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
*/
|
|
339
|
+
async run() {
|
|
340
|
+
const { flags } = this.parse(PrepareContent);
|
|
341
|
+
// read the flags and set paths relative to execution directory
|
|
342
|
+
let source = path.relative(process.cwd(), flags.source);
|
|
343
|
+
source = source ? source : '.';
|
|
344
|
+
let dest = flags.destination;
|
|
345
|
+
try {
|
|
346
|
+
let dotfileLines = await this.readDotfile(source);
|
|
347
|
+
this.log(`${chalk_1.default.blue('Content transformation started.')}`);
|
|
348
|
+
let transformations = await this.prepareTransformations(dotfileLines, source, dest);
|
|
349
|
+
await this.runTransformations(transformations);
|
|
350
|
+
this.log(`${chalk_1.default.green('Content prepared at: ', dest)}`);
|
|
351
|
+
}
|
|
352
|
+
catch (err) {
|
|
353
|
+
this.log(`${chalk_1.default.red(err)}`);
|
|
354
|
+
/*
|
|
355
|
+
In test mode, exit with status 0
|
|
356
|
+
*/
|
|
357
|
+
if (process.env.OPS_TEST_MODE === 'true') {
|
|
358
|
+
this.exit(0);
|
|
359
|
+
}
|
|
360
|
+
this.exit(1);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.default = PrepareContent;
|
|
365
|
+
PrepareContent.dotfile = '.opsprepare';
|
|
366
|
+
PrepareContent.description = `copies files as described in ${PrepareContent.dotfile} which is at root of source directory`;
|
|
367
|
+
PrepareContent.usage = 'prepare-content -d <destination> [-s <source>]';
|
|
368
|
+
PrepareContent.examples = [
|
|
369
|
+
`$ ops prepare-content -d .\\my_workspace`,
|
|
370
|
+
`$ ops prepare-content -d .\\my_workspace -s .\\my_repository`,
|
|
371
|
+
`$ ops prepare-content -d C:\\git\\my_workspace`,
|
|
372
|
+
`$ ops prepare-content -d C:\\git\\my_workspace -s C:\\git\\my_repository\\my_repository`
|
|
373
|
+
];
|
|
374
|
+
PrepareContent.flags = {
|
|
375
|
+
destination: command_1.flags.string({
|
|
376
|
+
char: 'd',
|
|
377
|
+
description: 'where to copy the workspace files',
|
|
378
|
+
required: true
|
|
379
|
+
}),
|
|
380
|
+
source: command_1.flags.string({
|
|
381
|
+
char: 's',
|
|
382
|
+
description: '[optional] source directory, default: current dir',
|
|
383
|
+
required: false,
|
|
384
|
+
default: '.'
|
|
385
|
+
})
|
|
386
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import CommandBase from '../command.base';
|
|
3
|
+
export default class Sql extends CommandBase {
|
|
4
|
+
static description: string;
|
|
5
|
+
static usage: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static args: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
options: string[];
|
|
11
|
+
}[];
|
|
12
|
+
static flags: {
|
|
13
|
+
version: flags.IOptionFlag<string | undefined>;
|
|
14
|
+
layer: flags.IOptionFlag<string | undefined>;
|
|
15
|
+
};
|
|
16
|
+
private readonly _moduleTypes;
|
|
17
|
+
private readonly _dbmsType;
|
|
18
|
+
/**
|
|
19
|
+
* Get unique scriptID by specified version
|
|
20
|
+
*/
|
|
21
|
+
getScriptId(version: string): Promise<string>;
|
|
22
|
+
handleLayer(scriptDbmsFolder: string, scriptLayer: string, scriptType: string, dbmsFormat: string): Promise<string>;
|
|
23
|
+
run(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const inquirer = require("inquirer");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const request = require("request-promise");
|
|
9
|
+
const command_base_1 = require("../command.base");
|
|
10
|
+
class Sql extends command_base_1.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this._moduleTypes = {
|
|
14
|
+
acc: 'Accounting',
|
|
15
|
+
claims: 'Claims',
|
|
16
|
+
core: 'Core',
|
|
17
|
+
pas: 'PAS',
|
|
18
|
+
reins: 'Reinsurance',
|
|
19
|
+
shared: 'Shared'
|
|
20
|
+
};
|
|
21
|
+
this._dbmsType = ['sql', 'oradc'];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get unique scriptID by specified version
|
|
25
|
+
*/
|
|
26
|
+
async getScriptId(version) {
|
|
27
|
+
let options = {
|
|
28
|
+
uri: `https://ops.adinsure.com/api/script/next?version=${version}`,
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: 'Bearer ' + await this.security.getToken()
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return request.get(options);
|
|
34
|
+
}
|
|
35
|
+
async handleLayer(scriptDbmsFolder, scriptLayer, scriptType, dbmsFormat) {
|
|
36
|
+
let scriptFolder = path.resolve(scriptDbmsFolder, scriptLayer, scriptType);
|
|
37
|
+
let layerFolder = path.resolve(scriptDbmsFolder, scriptLayer);
|
|
38
|
+
if (!await fs.pathExists(layerFolder)) {
|
|
39
|
+
let layers = '';
|
|
40
|
+
// printout only layer folders
|
|
41
|
+
for (let layer of fs.readdirSync(scriptDbmsFolder)) {
|
|
42
|
+
if (layer.toLowerCase() !== 'schema' && layer.toLowerCase() !== 'data') {
|
|
43
|
+
layers = layers + '\n' + layer;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (layers.length > 0) {
|
|
47
|
+
this.log(`Layer ${scriptLayer} for ${dbmsFormat} does not exist, did you mean: ${layers}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.log(`Layer ${scriptLayer} for ${dbmsFormat} does not exist.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return scriptFolder;
|
|
54
|
+
}
|
|
55
|
+
async run() {
|
|
56
|
+
const { args, flags } = this.parse(Sql);
|
|
57
|
+
// Validation of input parameters
|
|
58
|
+
let scriptType = args.type;
|
|
59
|
+
if (!scriptType) {
|
|
60
|
+
let responses = await inquirer.prompt([{
|
|
61
|
+
name: 'type',
|
|
62
|
+
message: 'select a sql type',
|
|
63
|
+
type: 'list',
|
|
64
|
+
choices: [{ name: 'schema' }, { name: 'data' }, { name: 'migration' }],
|
|
65
|
+
}]);
|
|
66
|
+
scriptType = responses.type;
|
|
67
|
+
}
|
|
68
|
+
let scriptModule = args.module;
|
|
69
|
+
if (!scriptModule && scriptType === 'data') {
|
|
70
|
+
let responses = await inquirer.prompt([{
|
|
71
|
+
name: 'module',
|
|
72
|
+
message: 'select a sql module for data type',
|
|
73
|
+
type: 'list',
|
|
74
|
+
choices: [{ name: 'acc' }, { name: 'claims' }, { name: 'core' }, { name: 'pas' }, { name: 'reins' }, { name: 'shared' }],
|
|
75
|
+
}]);
|
|
76
|
+
scriptModule = responses.module;
|
|
77
|
+
}
|
|
78
|
+
let scriptLayer = flags.layer;
|
|
79
|
+
this.log(`Generating on SQL script layer:'${scriptLayer}'`);
|
|
80
|
+
const fullVersion = flags.version || await this.getVersion('PLATFORM_VERSION', 'VERSION');
|
|
81
|
+
let version = fullVersion.split('-')[0];
|
|
82
|
+
let versionRegex = /\d+\.\d+\.\d+/;
|
|
83
|
+
if (!(versionRegex.test(version))) {
|
|
84
|
+
this.error(`Version in incorrect format. Got version: '${version}'`);
|
|
85
|
+
}
|
|
86
|
+
let scriptsRootFolder = path.resolve(await this.getGitRoot(), 'database');
|
|
87
|
+
if (!await fs.pathExists(scriptsRootFolder)) {
|
|
88
|
+
this.error(`Could not resolve database scripts folder: ${scriptsRootFolder}`);
|
|
89
|
+
}
|
|
90
|
+
let scriptFolderLocations = [];
|
|
91
|
+
for (let dbmsFormat of this._dbmsType) {
|
|
92
|
+
let scriptDbmsFolder = path.resolve(scriptsRootFolder, dbmsFormat);
|
|
93
|
+
if (await fs.pathExists(scriptDbmsFolder)) {
|
|
94
|
+
let scriptFolder = path.resolve(scriptDbmsFolder, scriptType);
|
|
95
|
+
if (scriptLayer !== undefined) {
|
|
96
|
+
scriptFolder = await this.handleLayer(scriptDbmsFolder, scriptLayer, scriptType, dbmsFormat);
|
|
97
|
+
}
|
|
98
|
+
if (scriptModule !== undefined) {
|
|
99
|
+
scriptFolder = path.resolve(scriptFolder, this._moduleTypes[scriptModule]);
|
|
100
|
+
}
|
|
101
|
+
if (!await fs.pathExists(scriptFolder)) {
|
|
102
|
+
this.warn(`Could not resolve existing database scripts folder. Creating folder: ${scriptFolder}`);
|
|
103
|
+
await fs.mkdir(scriptFolder);
|
|
104
|
+
}
|
|
105
|
+
scriptFolderLocations.push(scriptFolder);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Validation of parameters succeed. Requesting new SQL script ID and creating file.
|
|
109
|
+
this.log(`Requesting new id for '${version}'`);
|
|
110
|
+
let scriptId = await this.getScriptId(version);
|
|
111
|
+
this.log(`Got: '${chalk_1.default.green(scriptId)}'`);
|
|
112
|
+
for (let scriptFolder of scriptFolderLocations) {
|
|
113
|
+
let scriptsFilePath = path.resolve(scriptFolder, `${scriptId}.sql`);
|
|
114
|
+
await fs.writeFile(scriptsFilePath, '');
|
|
115
|
+
this.log(`${chalk_1.default.yellow(scriptsFilePath)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.default = Sql;
|
|
120
|
+
Sql.description = 'creates a new database script';
|
|
121
|
+
Sql.usage = 'sql <type> <module> [flags]';
|
|
122
|
+
Sql.examples = [
|
|
123
|
+
`$ ops sql schema `,
|
|
124
|
+
`$ ops sql data shared --layer basic`
|
|
125
|
+
];
|
|
126
|
+
Sql.args = [
|
|
127
|
+
{
|
|
128
|
+
name: 'type',
|
|
129
|
+
description: 'Type of database scripts',
|
|
130
|
+
options: ['schema', 'data', 'migration']
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'module',
|
|
134
|
+
description: 'Module of data database scripts',
|
|
135
|
+
options: ['acc', 'claims', 'core', 'pas', 'reins', 'shared']
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
Sql.flags = {
|
|
139
|
+
version: command_1.flags.string({
|
|
140
|
+
char: 'v',
|
|
141
|
+
description: 'version for which you\'re generating database script'
|
|
142
|
+
}),
|
|
143
|
+
layer: command_1.flags.string({
|
|
144
|
+
char: 'l',
|
|
145
|
+
description: 'name of the configuration layer for which you are generating database script'
|
|
146
|
+
})
|
|
147
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import CommandBase from '../command.base';
|
|
3
|
+
export default class Translate extends CommandBase {
|
|
4
|
+
static description: string;
|
|
5
|
+
static usage: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static args: {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
description: string;
|
|
11
|
+
}[];
|
|
12
|
+
static flags: {
|
|
13
|
+
format: flags.IOptionFlag<string>;
|
|
14
|
+
module: flags.IOptionFlag<string | undefined>;
|
|
15
|
+
output: flags.IOptionFlag<string>;
|
|
16
|
+
filename: flags.IOptionFlag<string | undefined>;
|
|
17
|
+
respectServerFilename: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
18
|
+
};
|
|
19
|
+
getFormat(format: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Gets resources, checks a response and returns a response stream.
|
|
22
|
+
* @param languages list of translations to download
|
|
23
|
+
* @param format format of translations
|
|
24
|
+
* @param modules list of modules to download
|
|
25
|
+
* @returns arhive as an byte array response stream
|
|
26
|
+
*/
|
|
27
|
+
getTranslations(languages: string, format: string, modules: string | undefined): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* Read from response stream and extract files into output directory.
|
|
30
|
+
* @param content zip file or a stream
|
|
31
|
+
* @param dest final destination to extract files
|
|
32
|
+
* @returns void
|
|
33
|
+
* @throws error message
|
|
34
|
+
*/
|
|
35
|
+
extractFiles(content: any, destinationDir: string, xmlFilename?: string): Promise<any>;
|
|
36
|
+
run(): Promise<void>;
|
|
37
|
+
}
|