@sasjs/cli 3.16.2 → 3.18.0

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 (39) hide show
  1. package/build/commands/build/build.js +42 -40
  2. package/build/commands/build/spec/build.spec.js +51 -0
  3. package/build/commands/build/spec/{cb.spec.server.d.ts → cb.spec.server.viya.d.ts} +0 -0
  4. package/build/commands/build/spec/{cb.spec.server.js → cb.spec.server.viya.js} +1 -1
  5. package/build/commands/compile/internal/compileFile.js +6 -3
  6. package/build/commands/compile/internal/loadDependencies.js +29 -21
  7. package/build/commands/deploy/spec/cbd.spec.js +24 -19
  8. package/build/commands/deploy/spec/{cbd.spec.server.d.ts → cbd.spec.server.viya.d.ts} +0 -0
  9. package/build/commands/deploy/spec/cbd.spec.server.viya.js +334 -0
  10. package/build/commands/flow/spec/{flow.spec.server.d.ts → flow.spec.server.viya.d.ts} +0 -0
  11. package/build/commands/flow/spec/{flow.spec.server.js → flow.spec.server.viya.js} +39 -55
  12. package/build/commands/folder/spec/{folder.spec.server.d.ts → folder.spec.server.viya.d.ts} +0 -0
  13. package/build/commands/folder/spec/{folder.spec.server.js → folder.spec.server.viya.js} +17 -23
  14. package/build/commands/init/init.js +7 -10
  15. package/build/commands/init/spec/{init.spec.server.d.ts → init.spec.d.ts} +0 -0
  16. package/build/commands/init/spec/{init.spec.server.js → init.spec.js} +0 -0
  17. package/build/commands/job/spec/{job.spec.server.d.ts → job.spec.server.viya.d.ts} +0 -0
  18. package/build/commands/job/spec/{job.spec.server.js → job.spec.server.viya.js} +45 -56
  19. package/build/commands/request/request.js +3 -2
  20. package/build/commands/request/spec/{request.spec.server.d.ts → request.spec.server.sas9.d.ts} +0 -0
  21. package/build/commands/request/spec/request.spec.server.sas9.js +283 -0
  22. package/build/commands/{run/spec/run.spec.server.d.ts → request/spec/request.spec.server.viya.d.ts} +0 -0
  23. package/build/commands/request/spec/request.spec.server.viya.js +460 -0
  24. package/build/commands/request/spec/utils.d.ts +23 -0
  25. package/build/commands/request/spec/utils.js +87 -0
  26. package/build/commands/{servicepack/spec/servicepack.spec.server.d.ts → run/spec/run.spec.server.sas9.d.ts} +0 -0
  27. package/build/commands/run/spec/run.spec.server.sas9.js +115 -0
  28. package/build/commands/run/spec/run.spec.server.viya.d.ts +1 -0
  29. package/build/commands/run/spec/{run.spec.server.js → run.spec.server.viya.js} +32 -101
  30. package/build/commands/servicepack/spec/servicepack.spec.server.viya.d.ts +1 -0
  31. package/build/commands/servicepack/spec/{servicepack.spec.server.js → servicepack.spec.server.viya.js} +1 -1
  32. package/build/utils/test.js +4 -2
  33. package/build/utils/utils.d.ts +0 -7
  34. package/build/utils/utils.js +92 -114
  35. package/package.json +6 -5
  36. package/build/commands/deploy/spec/cbd.spec.server.js +0 -331
  37. package/build/commands/request/spec/request.spec.server.js +0 -709
  38. package/build/utils/spec/removeComments.spec.d.ts +0 -1
  39. package/build/utils/spec/removeComments.spec.js +0 -47
@@ -86,7 +86,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
86
86
  return (mod && mod.__esModule) ? mod : { "default": mod };
87
87
  };
88
88
  Object.defineProperty(exports, "__esModule", { value: true });
89
- exports.isSasJsServerInServerMode = exports.getNodeModulePath = exports.isSASjsProject = exports.terminateProcess = exports.prefixAppLoc = exports.loadEnvVariables = exports.displaySasjsRunnerError = exports.getAdapterInstance = exports.checkNodeVersion = exports.millisecondsToDdHhMmSs = exports.arrToObj = exports.parseLogLines = exports.executeShellScript = exports.getUniqServicesObj = exports.removeComments = exports.setupDoxygen = exports.setupGhooks = exports.setupGitIgnore = exports.setupNpmProject = exports.createTemplateApp = exports.createMinimalApp = exports.createAngularApp = exports.createReactApp = exports.diff = exports.inExistingProject = void 0;
89
+ exports.isSasJsServerInServerMode = exports.getNodeModulePath = exports.isSASjsProject = exports.terminateProcess = exports.prefixAppLoc = exports.loadEnvVariables = exports.displaySasjsRunnerError = exports.getAdapterInstance = exports.checkNodeVersion = exports.millisecondsToDdHhMmSs = exports.arrToObj = exports.parseLogLines = exports.executeShellScript = exports.getUniqServicesObj = exports.setupDoxygen = exports.setupGitIgnore = exports.setupNpmProject = exports.createTemplateApp = exports.createMinimalApp = exports.createAngularApp = exports.createReactApp = exports.diff = exports.inExistingProject = void 0;
90
90
  var shelljs_1 = __importDefault(require("shelljs"));
91
91
  var path_1 = __importDefault(require("path"));
92
92
  var ora_1 = __importDefault(require("ora"));
@@ -95,6 +95,7 @@ var utils_1 = require("@sasjs/utils");
95
95
  var node_1 = __importDefault(require("@sasjs/adapter/node"));
96
96
  var displayResult_1 = require("./displayResult");
97
97
  var dotenv_1 = __importDefault(require("dotenv"));
98
+ var adm_zip_1 = __importDefault(require("adm-zip"));
98
99
  function inExistingProject(folderPath) {
99
100
  return __awaiter(this, void 0, void 0, function () {
100
101
  var packageJsonExists;
@@ -127,9 +128,11 @@ function createReactApp(folderPath) {
127
128
  return __awaiter(this, void 0, void 0, function () {
128
129
  var _this = this;
129
130
  return __generator(this, function (_a) {
130
- return [2 /*return*/, new Promise(function (resolve, _) { return __awaiter(_this, void 0, void 0, function () {
131
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
131
132
  return __generator(this, function (_a) {
132
- createApp(folderPath, 'https://github.com/sasjs/react-seed-app.git');
133
+ createApp(folderPath, 'https://github.com/sasjs/react-seed-app', 'https://github.com/sasjs/docs', function (err) {
134
+ return reject(new Error(err));
135
+ });
133
136
  return [2 /*return*/, resolve()];
134
137
  });
135
138
  }); })];
@@ -141,9 +144,11 @@ function createAngularApp(folderPath) {
141
144
  return __awaiter(this, void 0, void 0, function () {
142
145
  var _this = this;
143
146
  return __generator(this, function (_a) {
144
- return [2 /*return*/, new Promise(function (resolve, _) { return __awaiter(_this, void 0, void 0, function () {
147
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
145
148
  return __generator(this, function (_a) {
146
- createApp(folderPath, 'https://github.com/sasjs/angular-seed-app.git');
149
+ createApp(folderPath, 'https://github.com/sasjs/angular-seed-app', 'https://github.com/sasjs/docs', function (err) {
150
+ return reject(new Error(err));
151
+ });
147
152
  return [2 /*return*/, resolve()];
148
153
  });
149
154
  }); })];
@@ -155,9 +160,11 @@ function createMinimalApp(folderPath) {
155
160
  return __awaiter(this, void 0, void 0, function () {
156
161
  var _this = this;
157
162
  return __generator(this, function (_a) {
158
- return [2 /*return*/, new Promise(function (resolve, _) { return __awaiter(_this, void 0, void 0, function () {
163
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
159
164
  return __generator(this, function (_a) {
160
- createApp(folderPath, 'https://github.com/sasjs/minimal-seed-app.git');
165
+ createApp(folderPath, 'https://github.com/sasjs/minimal-seed-app', 'https://github.com/sasjs/docs', function (err) {
166
+ return reject(new Error(err));
167
+ });
161
168
  return [2 /*return*/, resolve()];
162
169
  });
163
170
  }); })];
@@ -172,14 +179,13 @@ function createTemplateApp(folderPath, template) {
172
179
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
173
180
  var _a, stdout, stderr, code;
174
181
  return __generator(this, function (_b) {
175
- _a = shelljs_1.default.exec("git ls-remote https://username:password@github.com/sasjs/template_".concat(template, ".git"), { silent: true }), stdout = _a.stdout, stderr = _a.stderr, code = _a.code;
176
- if (stderr.includes('Repository not found') || code) {
182
+ _a = downloadFile("https://username:password@github.com/sasjs/template_".concat(template)), stdout = _a.stdout, stderr = _a.stderr, code = _a.code;
183
+ if (stderr.includes('404: Not Found') || code) {
177
184
  return [2 /*return*/, reject(new Error("Template \"".concat(template, "\" is not a SASjs template")))];
178
185
  }
179
- if (!stdout) {
180
- return [2 /*return*/, reject(new Error("Unable to fetch template \"".concat(template, "\"")))];
181
- }
182
- createApp(folderPath, "https://github.com/sasjs/template_".concat(template, ".git"));
186
+ createApp(folderPath, "https://github.com/sasjs/template_".concat(template), 'https://github.com/sasjs/docs', function (err) {
187
+ return reject(new Error(err));
188
+ });
183
189
  return [2 /*return*/, resolve()];
184
190
  });
185
191
  }); })];
@@ -187,37 +193,88 @@ function createTemplateApp(folderPath, template) {
187
193
  });
188
194
  }
189
195
  exports.createTemplateApp = createTemplateApp;
190
- function createApp(folderPath, repoUrl, installDependencies) {
196
+ /**
197
+ * This function will first download / unzip the target app from repoUrl, then download / unzip the sasjs/docs repo into a subdirectory named 'docs'.
198
+ * Finally, if installDependencies is true, the npm install command will be executed.
199
+ * @param folderPath full path of the directory where desired seed app will be created
200
+ * @param repoUrl sasjs/{seed-app} repo url
201
+ * @param docsUrl sasjs/docs repo url
202
+ * @params installDependencies whether or not to do `npm install`
203
+ */
204
+ function createApp(folderPath, repoUrl, docsUrl, errorCallback, installDependencies) {
191
205
  if (installDependencies === void 0) { installDependencies = true; }
206
+ //In past we used GIT to clone the repos. But many users potentially won't have GIT installed.
207
+ //So we will use shell tools to set up the apps.
208
+ var zipName = 'main.zip';
209
+ var zipPath = "/archive/refs/heads/";
210
+ var fullZipPath = "".concat(zipPath).concat(zipName);
192
211
  var spinner = (0, ora_1.default)("Creating SASjs project in ".concat(folderPath, "."));
193
212
  spinner.start();
194
- var gitBranch = repoUrl.includes('template_sasonly') ? 'master' : 'main';
195
- var gitVersion = (shelljs_1.default
196
- .exec("git version", { silent: true })
197
- .stdout.match(/(?<!git version)\d+\.\d+\.\d+/) || '')[0].replace(/\./g, '');
198
- // NOTE: git version 2.13 and greater are using '--recurse-submodules' instead of '--recurse' attribute to clone submodules
199
- shelljs_1.default.exec("cd \"".concat(folderPath, "\" && git clone --recurse").concat(parseInt(gitVersion) > 2130 ? '-submodules' : '', " --depth 1 -b ").concat(gitBranch, " ").concat(repoUrl, " ."), { silent: true });
200
- deleteGitFolder(folderPath);
201
- shelljs_1.default.rm('-f', [path_1.default.join(folderPath, '.gitmodules')]);
202
- if (repoUrl.includes('react-seed-app')) {
203
- deleteGitFolder(path_1.default.join(folderPath, 'public', 'docs'));
204
- }
205
- else if (repoUrl.includes('angular-seed-app')) {
206
- deleteGitFolder(path_1.default.join(folderPath, 'docs'));
213
+ //Get repo zip, assuming main branch is called `main`
214
+ var _a = downloadFile("".concat(repoUrl).concat(fullZipPath)), stdout = _a.stdout, stderr = _a.stderr, code = _a.code;
215
+ // If doesn't exist, we try again, but with master.zip for the zip name.
216
+ // Since that's the name generated from branch name.
217
+ if (stderr.includes('404: Not Found') || code) {
218
+ zipName = 'master.zip';
219
+ var _b = downloadFile("".concat(repoUrl).concat(zipPath).concat(zipName)), stdout_1 = _b.stdout, stderr_1 = _b.stderr, code_1 = _b.code;
220
+ if (stderr_1.includes('404: Not Found') || code_1) {
221
+ errorCallback("".concat(repoUrl).concat(zipPath, " is not SASjs repository!"));
222
+ return;
223
+ }
207
224
  }
225
+ var zipWithoutExtension = zipName.replace('.zip', '');
226
+ var zip = new adm_zip_1.default(zipName);
227
+ zip.extractAllTo("./", true);
228
+ shelljs_1.default.cp('-r', "./*".concat(zipWithoutExtension, "/."), folderPath);
229
+ shelljs_1.default.rm('-rf', ["./*".concat(zipWithoutExtension)]);
230
+ shelljs_1.default.rm('-rf', ["./".concat(zipName)]);
231
+ loadDocsSubmodule(docsUrl, folderPath, fullZipPath);
232
+ shelljs_1.default.rm('-f', [path_1.default.join(folderPath, '.gitmodules')]);
208
233
  spinner.stop();
209
234
  if (installDependencies) {
210
235
  spinner.text = 'Installing dependencies...';
211
236
  spinner.start();
212
- shelljs_1.default.exec("cd \"".concat(folderPath, "\" && git init && npm install"), {
237
+ shelljs_1.default.exec("cd \"".concat(folderPath, "\" && npm install"), {
213
238
  silent: true
214
239
  });
215
240
  spinner.stop();
216
241
  }
217
242
  }
218
- var deleteGitFolder = function (folderPath) {
219
- return shelljs_1.default.rm('-rf', path_1.default.join(folderPath, '.git'));
220
- };
243
+ /**
244
+ * It will download and unzip `sasjs/docs` into newly created folder into `docs` subfolder
245
+ * @param docsUrl sasjs/docs repo url
246
+ * @param folderPath full path to the newly created folder that contains the seed app
247
+ * @param zipPath fixed path of where github puts zip for repo download
248
+ */
249
+ var loadDocsSubmodule = function (docsUrl, folderPath, zipPath) { return __awaiter(void 0, void 0, void 0, function () {
250
+ var docsFolderPath, zip;
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0:
254
+ docsFolderPath = "".concat(folderPath, "/public/docs") //We first look if docs submodule is inside `public` folder. (react-seed-app for example)
255
+ ;
256
+ return [4 /*yield*/, (0, utils_1.fileExists)(docsFolderPath)];
257
+ case 1:
258
+ if (!(_a.sent()))
259
+ docsFolderPath = "".concat(folderPath, "/docs"); //If not, we load submodule in root
260
+ downloadFile("".concat(docsUrl).concat(zipPath));
261
+ zip = new adm_zip_1.default('main.zip');
262
+ zip.extractAllTo('./', true);
263
+ shelljs_1.default.cp('-r', "./*-main/.", docsFolderPath);
264
+ shelljs_1.default.rm('-rf', ["./*-main"]);
265
+ shelljs_1.default.rm('-rf', ["./main.zip"]);
266
+ return [2 /*return*/];
267
+ }
268
+ });
269
+ }); };
270
+ function downloadFile(url) {
271
+ if ((0, utils_1.isLinux)()) {
272
+ return shelljs_1.default.exec("wget ".concat(url), { silent: true });
273
+ }
274
+ else {
275
+ return shelljs_1.default.exec("curl ".concat(url, " -LO -f"), { silent: true });
276
+ }
277
+ }
221
278
  function setupNpmProject(folderName) {
222
279
  return __awaiter(this, void 0, void 0, function () {
223
280
  var folderPath;
@@ -299,52 +356,6 @@ function setupGitIgnore(folderName) {
299
356
  });
300
357
  }
301
358
  exports.setupGitIgnore = setupGitIgnore;
302
- function setupGhooks(folderName) {
303
- var _a;
304
- return __awaiter(this, void 0, void 0, function () {
305
- var folderPath, packageJsonPath, packageJsonContent, packageJson, preCommitCmd, e_1;
306
- return __generator(this, function (_b) {
307
- switch (_b.label) {
308
- case 0:
309
- folderPath = path_1.default.join(process.projectDir, folderName);
310
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info('Installing ghooks');
311
- shelljs_1.default.exec("cd \"".concat(folderPath, "\" && npm i ghooks --save-dev"), {
312
- silent: true
313
- });
314
- _b.label = 1;
315
- case 1:
316
- _b.trys.push([1, 4, , 5]);
317
- packageJsonPath = path_1.default.join(folderPath, 'package.json');
318
- return [4 /*yield*/, (0, utils_1.readFile)(packageJsonPath)];
319
- case 2:
320
- packageJsonContent = _b.sent();
321
- packageJson = JSON.parse(packageJsonContent);
322
- if (!packageJson.config)
323
- packageJson.config = {};
324
- if (!packageJson.config.ghooks)
325
- packageJson.config.ghooks = {};
326
- preCommitCmd = 'sasjs lint';
327
- if (packageJson.config.ghooks['pre-commit']) {
328
- preCommitCmd = ' && sasjs lint';
329
- }
330
- else {
331
- packageJson.config.ghooks['pre-commit'] = '';
332
- }
333
- if (!/sasjs lint/.test(packageJson.config.ghooks['pre-commit']))
334
- packageJson.config.ghooks['pre-commit'] += preCommitCmd;
335
- return [4 /*yield*/, (0, utils_1.createFile)(packageJsonPath, JSON.stringify(packageJson, null, 2))];
336
- case 3:
337
- _b.sent();
338
- return [3 /*break*/, 5];
339
- case 4:
340
- e_1 = _b.sent();
341
- return [3 /*break*/, 5];
342
- case 5: return [2 /*return*/];
343
- }
344
- });
345
- });
346
- }
347
- exports.setupGhooks = setupGhooks;
348
359
  function setupDoxygen(folderPath) {
349
360
  return __awaiter(this, void 0, void 0, function () {
350
361
  var doxyFilesPath, doxyFolderPathSource, doxyFolderPath;
@@ -363,39 +374,6 @@ function setupDoxygen(folderPath) {
363
374
  });
364
375
  }
365
376
  exports.setupDoxygen = setupDoxygen;
366
- /**
367
- * Removes comments from a given block of text.
368
- * Preserves single line block comments and inline comments.
369
- * @param {string} text - the text to remove comments from.
370
- */
371
- function removeComments(text) {
372
- if (!text)
373
- return '';
374
- var lines = text
375
- .replace(/\r\n/g, '\n')
376
- .split('\n')
377
- .map(function (l) { return l.trimEnd(); });
378
- var linesWithoutComment = [];
379
- var inCommentBlock = false;
380
- lines.forEach(function (line) {
381
- if (line.includes('/*') && line.includes('*/')) {
382
- linesWithoutComment.push(line);
383
- }
384
- else {
385
- if (line.startsWith('/*') && !line.endsWith('*/')) {
386
- inCommentBlock = true;
387
- }
388
- if (!inCommentBlock) {
389
- linesWithoutComment.push(line);
390
- }
391
- if (line.endsWith('*/') && !line.includes('/*') && inCommentBlock) {
392
- inCommentBlock = false;
393
- }
394
- }
395
- });
396
- return linesWithoutComment.filter(function (l) { return !!l.trim(); }).join('\n');
397
- }
398
- exports.removeComments = removeComments;
399
377
  function getUniqServicesObj(services) {
400
378
  var returnObj = {};
401
379
  if (!services)
@@ -419,7 +397,7 @@ function executeShellScript(filePath, logFilePath) {
419
397
  return __generator(this, function (_b) {
420
398
  switch (_b.label) {
421
399
  case 0:
422
- shellCommand = (0, utils_1.isWindows)() ? "sh ".concat(filePath) : "bash ".concat(filePath);
400
+ shellCommand = (0, utils_1.isWindows)() ? "".concat(filePath) : "bash ".concat(filePath);
423
401
  result = shelljs_1.default.exec(shellCommand, { silent: true });
424
402
  if (!result.code) return [3 /*break*/, 1];
425
403
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("Error: ".concat(result.stderr));
@@ -447,7 +425,7 @@ exports.executeShellScript = executeShellScript;
447
425
  * @param {object} logJson
448
426
  */
449
427
  function parseLogLines(logJson) {
450
- var e_2, _a;
428
+ var e_1, _a;
451
429
  var logLines = '';
452
430
  try {
453
431
  for (var _b = __values(logJson.items), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -455,12 +433,12 @@ function parseLogLines(logJson) {
455
433
  logLines += "".concat(item.line, "\n");
456
434
  }
457
435
  }
458
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
436
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
459
437
  finally {
460
438
  try {
461
439
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
462
440
  }
463
- finally { if (e_2) throw e_2.error; }
441
+ finally { if (e_1) throw e_1.error; }
464
442
  }
465
443
  return logLines;
466
444
  }
package/package.json CHANGED
@@ -20,6 +20,7 @@
20
20
  "preinstall": "npm run checkNodeVersion -s",
21
21
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
22
22
  },
23
+ "testServerTypes": "viya,sas9,sasjs",
23
24
  "release": {
24
25
  "branches": [
25
26
  "main"
@@ -47,10 +48,10 @@
47
48
  "access": "public"
48
49
  },
49
50
  "dependencies": {
50
- "@sasjs/adapter": "3.9.4",
51
- "@sasjs/core": "4.32.2",
51
+ "@sasjs/adapter": "3.10.11",
52
+ "@sasjs/core": "4.35.0",
52
53
  "@sasjs/lint": "1.11.2",
53
- "@sasjs/utils": "2.45.0",
54
+ "@sasjs/utils": "2.47.0",
54
55
  "adm-zip": "0.5.9",
55
56
  "chalk": "4.1.2",
56
57
  "csv-stringify": "5.6.5",
@@ -88,7 +89,7 @@
88
89
  "jest": "27.4.7",
89
90
  "jest-cli": "27.4.7",
90
91
  "jest-extended": "1.1.0",
91
- "nodemon": "2.0.15",
92
+ "nodemon": "2.0.19",
92
93
  "prettier": "2.6.2",
93
94
  "ts-jest": "27.1.2",
94
95
  "ts-node": "10.4.0",
@@ -96,5 +97,5 @@
96
97
  "typescript": "4.5.4",
97
98
  "util": "0.12.4"
98
99
  },
99
- "version": "3.16.2"
100
+ "version": "3.18.0"
100
101
  }