@adinsure-ops/ops-cli 4.8.3 → 5.0.0-rc4

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.
Files changed (89) hide show
  1. package/CHANGELOGS.md +52 -36
  2. package/LICENSE +1 -1
  3. package/README.md +32 -242
  4. package/bin/dev.cmd +3 -0
  5. package/bin/dev.js +6 -0
  6. package/bin/run.cmd +1 -1
  7. package/bin/run.js +8 -0
  8. package/lib/command.base.d.ts +9 -5
  9. package/lib/command.base.jira.d.ts +7 -8
  10. package/lib/command.base.jira.js +26 -24
  11. package/lib/command.base.js +69 -57
  12. package/lib/commands/docker/update-image-version.d.ts +6 -9
  13. package/lib/commands/docker/update-image-version.js +35 -34
  14. package/lib/commands/doctor.d.ts +15 -5
  15. package/lib/commands/doctor.js +219 -186
  16. package/lib/commands/download/client.d.ts +10 -7
  17. package/lib/commands/download/client.js +60 -52
  18. package/lib/commands/download/identity-server.d.ts +9 -7
  19. package/lib/commands/download/identity-server.js +59 -53
  20. package/lib/commands/download/jmeter.d.ts +5 -5
  21. package/lib/commands/download/jmeter.js +54 -49
  22. package/lib/commands/download/keycloak-scim.d.ts +6 -6
  23. package/lib/commands/download/keycloak-scim.js +56 -51
  24. package/lib/commands/download/platform.d.ts +9 -7
  25. package/lib/commands/download/platform.js +59 -53
  26. package/lib/commands/download/scheduler.d.ts +9 -7
  27. package/lib/commands/download/scheduler.js +59 -53
  28. package/lib/commands/download/server.d.ts +9 -7
  29. package/lib/commands/download/server.js +59 -53
  30. package/lib/commands/download/signalr.d.ts +9 -7
  31. package/lib/commands/download/signalr.js +59 -53
  32. package/lib/commands/download/studio.d.ts +12 -9
  33. package/lib/commands/download/studio.js +107 -82
  34. package/lib/commands/gitlab/get-tag-pipeline.d.ts +11 -14
  35. package/lib/commands/gitlab/get-tag-pipeline.js +95 -92
  36. package/lib/commands/gitlab/next-nightly-tag.d.ts +10 -12
  37. package/lib/commands/gitlab/next-nightly-tag.js +96 -98
  38. package/lib/commands/jira/issue.d.ts +6 -8
  39. package/lib/commands/jira/issue.js +25 -23
  40. package/lib/commands/jira/labels.d.ts +9 -12
  41. package/lib/commands/jira/labels.js +52 -51
  42. package/lib/commands/log/add.d.ts +6 -8
  43. package/lib/commands/log/add.js +92 -87
  44. package/lib/commands/log/generate.d.ts +9 -10
  45. package/lib/commands/log/generate.js +112 -107
  46. package/lib/commands/log/validate.d.ts +2 -2
  47. package/lib/commands/log/validate.js +47 -43
  48. package/lib/commands/login.d.ts +9 -10
  49. package/lib/commands/login.js +101 -97
  50. package/lib/commands/npm/check-publish.d.ts +7 -8
  51. package/lib/commands/npm/check-publish.js +59 -54
  52. package/lib/commands/npm/dependency-update.d.ts +14 -12
  53. package/lib/commands/npm/dependency-update.js +94 -86
  54. package/lib/commands/npm/publish.d.ts +8 -9
  55. package/lib/commands/npm/publish.js +154 -140
  56. package/lib/commands/nuget/dependency-update.d.ts +15 -10
  57. package/lib/commands/nuget/dependency-update.js +60 -49
  58. package/lib/commands/sql.d.ts +24 -20
  59. package/lib/commands/sql.js +245 -226
  60. package/lib/commands/translate.d.ts +15 -16
  61. package/lib/commands/translate.js +109 -104
  62. package/lib/commands/version.d.ts +29 -19
  63. package/lib/commands/version.js +215 -190
  64. package/lib/config.js +3 -6
  65. package/lib/hooks/init/version-override.d.ts +2 -2
  66. package/lib/hooks/init/version-override.js +15 -13
  67. package/lib/index.d.ts +1 -1
  68. package/lib/index.js +1 -4
  69. package/lib/lib/command.d.ts +2 -0
  70. package/lib/lib/command.js +65 -58
  71. package/lib/lib/gitlab.d.ts +8 -2
  72. package/lib/lib/gitlab.js +94 -82
  73. package/lib/lib/npm.d.ts +7 -3
  74. package/lib/lib/npm.js +72 -60
  75. package/lib/lib/npmrc.d.ts +5 -0
  76. package/lib/lib/npmrc.js +20 -13
  77. package/lib/lib/nuget.d.ts +2 -0
  78. package/lib/lib/nuget.js +20 -17
  79. package/lib/security/cache.js +31 -27
  80. package/lib/security/context.d.ts +2 -1
  81. package/lib/security/context.js +106 -103
  82. package/lib/types/changelog.types.js +1 -2
  83. package/lib/types/npm.types.d.ts +5 -5
  84. package/lib/types/npm.types.js +1 -2
  85. package/oclif.manifest.json +1223 -1
  86. package/package.json +50 -46
  87. package/bin/run +0 -5
  88. package/lib/commands/prepare-content.d.ts +0 -29
  89. package/lib/commands/prepare-content.js +0 -386
package/package.json CHANGED
@@ -1,78 +1,80 @@
1
1
  {
2
2
  "name": "@adinsure-ops/ops-cli",
3
3
  "description": "Operations CLI for working with AdInsure",
4
- "version": "4.8.3",
4
+ "version": "5.0.0-rc4",
5
5
  "author": "Adacta Digital Service Department",
6
6
  "bin": {
7
- "ops": "./bin/run"
7
+ "ops": "./bin/run.js"
8
8
  },
9
+ "type": "module",
9
10
  "dependencies": {
10
11
  "@azure/msal-node": "^1.14.5",
11
- "@oclif/command": "^1",
12
- "@oclif/config": "^1",
13
- "@oclif/plugin-help": "^2",
14
- "@oclif/plugin-not-found": "^1.2.2",
15
- "@oclif/plugin-warn-if-update-available": "^1.7.0",
16
- "@types/semver": "7.5.0",
17
- "axios": "^0.27.2",
18
- "chalk": "^2.4.2",
19
- "cli-ux": "^5.2.1",
20
- "fs-extra": "^8.0.1",
21
- "globby": "^10.0.0",
22
- "gray-matter": "^4.0.2",
23
- "ini": "^3.0.0",
24
- "inquirer": "^7.3.3",
25
- "jira-client": "^8.2.2",
26
- "jszip": "^3.2.2",
27
- "lodash": "^4.17.11",
28
- "minimatch": "^3.0.4",
12
+ "@oclif/core": "^2.11.8",
13
+ "@oclif/plugin-help": "^5.2.17",
14
+ "@oclif/plugin-not-found": "^2.3.37",
15
+ "@oclif/plugin-warn-if-update-available": "^2.0.48",
16
+ "axios": "^1.4.0",
17
+ "chalk": "^5.3.0",
18
+ "fs-extra": "^11.1.1",
19
+ "globby": "^13.2.2",
20
+ "gray-matter": "^4.0.3",
21
+ "ini": "^4.1.1",
22
+ "inquirer": "^9.2.10",
23
+ "jira-client": "8.2.2",
24
+ "jszip": "^3.10.1",
25
+ "lodash-es": "^4.17.21",
26
+ "minimatch": "^9.0.3",
29
27
  "moment": "^2.24.0",
30
28
  "oauth": "^0.9.15",
31
- "open": "^6.4.0",
29
+ "open": "^9.1.0",
32
30
  "replace-in-file": "^4.3.1",
33
- "request": "^2.88.2",
34
- "request-promise": "^4.2.6",
35
- "rimraf": "^2.6.3",
31
+ "rimraf": "^5.0.1",
36
32
  "semver": "^7.5.4",
37
33
  "tough-cookie": "^4.1.3",
38
- "tslib": "^1",
39
- "yaml": "^2.1.1"
34
+ "tslib": "^2.6.2",
35
+ "typescript": "^5.2.2",
36
+ "yaml": "^2.3.1"
40
37
  },
41
38
  "devDependencies": {
42
39
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
43
- "@oclif/dev-cli": "^1",
44
- "@oclif/test": "^1",
45
- "@oclif/tslint": "^3",
40
+ "@oclif/test": "^2.4.8",
46
41
  "@testdeck/mocha": "^0.3.3",
47
- "@types/chai": "^4",
48
- "@types/fs-extra": "^7.0.0",
42
+ "@types/chai": "^4.3.5",
43
+ "@types/fs-extra": "^11.0.1",
49
44
  "@types/ini": "^1.3.31",
50
- "@types/inquirer": "^7.3.1",
45
+ "@types/inquirer": "^9.0.3",
51
46
  "@types/jira-client": "^6.21.3",
52
- "@types/jszip": "^3.4.1",
47
+ "@types/lodash-es": "^4.17.8",
53
48
  "@types/mocha": "^5.2.7",
54
49
  "@types/mock-fs": "^4.13.1",
55
- "@types/node": "^10",
50
+ "@types/normalize-package-data": "^2.4.1",
56
51
  "@types/oauth": "^0.9.1",
57
- "@types/request-promise": "^4.1.44",
58
- "@types/rimraf": "^2.0.2",
52
+ "@types/semver": "^7.5.0",
59
53
  "@types/sinon": "^10.0.15",
54
+ "@typescript-eslint/eslint-plugin": "^6.4.1",
55
+ "@typescript-eslint/parser": "^6.4.1",
60
56
  "chai": "^4.3.7",
57
+ "eslint": "^8.47.0",
58
+ "eslint-config-oclif": "^4.0.0",
59
+ "eslint-config-oclif-typescript": "^1.0.3",
60
+ "eslint-plugin-unicorn": "^48.0.1",
61
61
  "mocha": "^10.2.0",
62
62
  "mocha-typescript": "^1.1.17",
63
63
  "mock-fs": "^5.1.1",
64
64
  "mock-spawn": "^0.2.6",
65
65
  "nock": "^13.1.3",
66
66
  "nyc": "^15.1.0",
67
+ "oclif": "^3.11.3",
67
68
  "sinon": "^15.1.0",
68
69
  "timekeeper": "^2.2.0",
69
70
  "ts-mockito": "^2.6.1",
70
- "ts-node": "^8.10.2",
71
- "tslint": "^5",
72
- "typescript": "^3.3"
71
+ "ts-node": "^10.9.1"
72
+ },
73
+ "peerDependencies": {
74
+ "@types/node": "^20.5.7"
73
75
  },
74
76
  "engines": {
75
- "node": "^12 || ^14 || ^16"
77
+ "node": "^14 || ^16 || ^18"
76
78
  },
77
79
  "files": [
78
80
  "/bin",
@@ -86,12 +88,13 @@
86
88
  "cli"
87
89
  ],
88
90
  "license": "SEE LICENSE IN LICENSE",
89
- "main": "lib/index.js",
91
+ "main": "./lib/index.js",
90
92
  "oclif": {
91
- "commands": "./lib/commands",
92
93
  "bin": "ops",
93
- "hooks": {
94
- "init": "./lib/hooks/init/version-override"
94
+ "dirname": "ops",
95
+ "commands": "./lib/commands",
96
+ "hook": {
97
+ "init": "./lib/hooks/init/version-override.ts"
95
98
  },
96
99
  "plugins": [
97
100
  "@oclif/plugin-help",
@@ -111,13 +114,14 @@
111
114
  "repository": "ops/ops-cli",
112
115
  "scripts": {
113
116
  "postpack": "rimraf oclif.manifest.json",
114
- "prepack": "rimraf lib && tsc -b && oclif-dev manifest",
117
+ "prepack": "rimraf lib && tsc -b && oclif manifest",
115
118
  "test": "nyc --require ts-node/register --extension .ts mocha --timeout 20000 --forbid-only \"test/**/*.test.ts\"",
116
119
  "test-unit": "mocha \"./test/**/*.spec.ts\"",
120
+ "build": "tsc -b",
117
121
  "test-with-coverage": "nyc --require ts-node/register --extension .ts mocha --reporter=doc --timeout 20000 --forbid-only \"test/**/*.test.ts\"",
118
122
  "test-single": "nyc --require ts-node/register --extension .ts mocha --timeout 20000 --forbid-only",
119
123
  "test-single-with-coverage": "nyc --require ts-node/register --extension .ts mocha --reporter=doc --timeout 20000 --forbid-only",
120
- "lint": "tslint -p test -t stylish"
124
+ "eslint": "eslint ./src ./test --ext .ts --config .eslintrc"
121
125
  },
122
126
  "types": "lib/index.d.ts"
123
127
  }
package/bin/run DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('@oclif/command').run()
4
- .then(require('@oclif/command/flush'))
5
- .catch(require('@oclif/errors/handle'))
@@ -1,29 +0,0 @@
1
- import { flags } from '@oclif/command';
2
- import CommandBase from '../command.base';
3
- interface Transformation {
4
- name: string;
5
- srcPath: string;
6
- transform(): void;
7
- }
8
- interface DotfileLine {
9
- prefix: string;
10
- source: string;
11
- transformData: string;
12
- }
13
- export default class PrepareContent extends CommandBase {
14
- static readonly dotfile = ".opsprepare";
15
- static description: string;
16
- static usage: string;
17
- static examples: string[];
18
- static flags: {
19
- destination: flags.IOptionFlag<string>;
20
- source: flags.IOptionFlag<string>;
21
- };
22
- parseDotfileLine(line: string, sourceDirectory: string): Promise<DotfileLine>;
23
- readDotfile(sourceDirectory: string): Promise<DotfileLine[]>;
24
- getTransformation(lineData: DotfileLine, baseSourcedir: string, baseDestinationDir: string): Promise<Transformation>;
25
- prepareTransformations(linesData: DotfileLine[], baseSourceDir: string, baseDestinationDir: string): Promise<Transformation[]>;
26
- runTransformations(transformations: Transformation[]): Promise<void>;
27
- run(): Promise<void>;
28
- }
29
- export {};
@@ -1,386 +0,0 @@
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 (err) {
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 (err) {
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
- };