@sasjs/cli 3.11.0 → 3.12.2

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.
@@ -60,7 +60,7 @@ var addCredential_1 = require("./addCredential");
60
60
  function addTarget(insecure) {
61
61
  var _a, _b, _c;
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var _d, scope, serverType, name, appLoc, serverUrl, existingTarget, saveWithDefaultValues, targetJson, target, filePath, _e, _f, serverName, repositoryName, userName, password, _g, contextName, updatedViyaTarget, updatedSasjsTarget, isDefault;
63
+ var _d, scope, serverType, name, appLoc, serverUrl, existingTarget, targetJson, target, filePath, _e, _f, serverName, repositoryName, userName, password, _g, contextName, updatedViyaTarget, updatedSasjsTarget, isDefault;
64
64
  return __generator(this, function (_h) {
65
65
  switch (_h.label) {
66
66
  case 0:
@@ -69,10 +69,9 @@ function addTarget(insecure) {
69
69
  return [4 /*yield*/, (0, input_1.getCommonFields)()];
70
70
  case 1:
71
71
  _d = _h.sent(), scope = _d.scope, serverType = _d.serverType, name = _d.name, appLoc = _d.appLoc, serverUrl = _d.serverUrl, existingTarget = _d.existingTarget;
72
- saveWithDefaultValues = !existingTarget;
73
72
  targetJson = __assign(__assign({}, existingTarget), { name: name, serverType: serverType, serverUrl: serverUrl, appLoc: appLoc });
74
73
  target = new types_1.Target(targetJson);
75
- return [4 /*yield*/, (0, saveConfig_1.saveConfig)(scope, target, false, saveWithDefaultValues)];
74
+ return [4 /*yield*/, (0, saveConfig_1.saveConfig)(scope, target, false, false)];
76
75
  case 2:
77
76
  filePath = _h.sent();
78
77
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info("Target configuration has been saved to ".concat(filePath, " ."));
@@ -98,11 +97,7 @@ function addTarget(insecure) {
98
97
  case 6:
99
98
  _g = _h.sent(), contextName = _g.contextName, updatedViyaTarget = _g.target;
100
99
  targetJson = {
101
- contextName: contextName,
102
- deployConfig: {
103
- deployServicePack: true,
104
- deployScripts: []
105
- }
100
+ contextName: contextName
106
101
  };
107
102
  targetJson = __assign(__assign({}, updatedViyaTarget.toJson(false)), targetJson);
108
103
  return [3 /*break*/, 10];
@@ -115,7 +110,7 @@ function addTarget(insecure) {
115
110
  case 10: return [4 /*yield*/, (0, input_1.getIsDefault)()];
116
111
  case 11:
117
112
  isDefault = _h.sent();
118
- return [4 /*yield*/, (0, saveConfig_1.saveConfig)(scope, new types_1.Target(targetJson), isDefault, saveWithDefaultValues)];
113
+ return [4 /*yield*/, (0, saveConfig_1.saveConfig)(scope, new types_1.Target(targetJson), isDefault, false)];
119
114
  case 12:
120
115
  filePath = _h.sent();
121
116
  (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Target configuration has been saved to ".concat(filePath));
@@ -324,6 +324,7 @@ function recreateBuildFolder() {
324
324
  });
325
325
  });
326
326
  }
327
+ // REFACTOR: combine compileServiceFolder and compileJobFolder
327
328
  var compileServiceFolder = function (target, serviceFolder, macroFolders, programFolders, compileTree) { return __awaiter(void 0, void 0, void 0, function () {
328
329
  var destinationPath, subFolders, filesNamesInPath;
329
330
  return __generator(this, function (_a) {
@@ -333,9 +334,30 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
333
334
  return [4 /*yield*/, (0, utils_1.listSubFoldersInFolder)(destinationPath)];
334
335
  case 1:
335
336
  subFolders = _a.sent();
336
- return [4 /*yield*/, (0, utils_1.listFilesInFolder)(destinationPath)];
337
+ return [4 /*yield*/, (0, utils_1.listFilesInFolder)(destinationPath)
338
+ // Checks if file in sasjsbuild folder exists in source folder.
339
+ // If not, it means that the file shouldn't be compiled.
340
+ ];
337
341
  case 2:
338
342
  filesNamesInPath = _a.sent();
343
+ // Checks if file in sasjsbuild folder exists in source folder.
344
+ // If not, it means that the file shouldn't be compiled.
345
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
346
+ return __generator(this, function (_a) {
347
+ switch (_a.label) {
348
+ case 0: return [4 /*yield*/, (0, utils_1.fileExists)(path_1.default.join(serviceFolder, fileName))];
349
+ case 1:
350
+ if (!(_a.sent())) {
351
+ filesNamesInPath.splice(i, 1);
352
+ }
353
+ return [2 /*return*/];
354
+ }
355
+ });
356
+ }); })];
357
+ case 3:
358
+ // Checks if file in sasjsbuild folder exists in source folder.
359
+ // If not, it means that the file shouldn't be compiled.
360
+ _a.sent();
339
361
  return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
340
362
  var filePath;
341
363
  return __generator(this, function (_a) {
@@ -355,7 +377,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
355
377
  }
356
378
  });
357
379
  }); })];
358
- case 3:
380
+ case 4:
359
381
  _a.sent();
360
382
  return [4 /*yield*/, (0, utils_1.asyncForEach)(subFolders, function (subFolder) { return __awaiter(void 0, void 0, void 0, function () {
361
383
  var fileNames;
@@ -389,7 +411,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
389
411
  }
390
412
  });
391
413
  }); })];
392
- case 4:
414
+ case 5:
393
415
  _a.sent();
394
416
  compileTree.saveTree();
395
417
  return [2 /*return*/];
@@ -405,9 +427,30 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
405
427
  return [4 /*yield*/, (0, utils_1.listSubFoldersInFolder)(destinationPath)];
406
428
  case 1:
407
429
  subFolders = _a.sent();
408
- return [4 /*yield*/, (0, utils_1.listFilesInFolder)(destinationPath)];
430
+ return [4 /*yield*/, (0, utils_1.listFilesInFolder)(destinationPath)
431
+ // Checks if file in sasjsbuild folder exists in source folder.
432
+ // If not, it means that the file shouldn't be compiled.
433
+ ];
409
434
  case 2:
410
435
  filesNamesInPath = _a.sent();
436
+ // Checks if file in sasjsbuild folder exists in source folder.
437
+ // If not, it means that the file shouldn't be compiled.
438
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
439
+ return __generator(this, function (_a) {
440
+ switch (_a.label) {
441
+ case 0: return [4 /*yield*/, (0, utils_1.fileExists)(path_1.default.join(jobFolder, fileName))];
442
+ case 1:
443
+ if (!(_a.sent())) {
444
+ filesNamesInPath.splice(i, 1);
445
+ }
446
+ return [2 /*return*/];
447
+ }
448
+ });
449
+ }); })];
450
+ case 3:
451
+ // Checks if file in sasjsbuild folder exists in source folder.
452
+ // If not, it means that the file shouldn't be compiled.
453
+ _a.sent();
411
454
  return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
412
455
  var filePath;
413
456
  return __generator(this, function (_a) {
@@ -427,7 +470,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
427
470
  }
428
471
  });
429
472
  }); })];
430
- case 3:
473
+ case 4:
431
474
  _a.sent();
432
475
  return [4 /*yield*/, (0, utils_1.asyncForEach)(subFolders, function (subFolder) { return __awaiter(void 0, void 0, void 0, function () {
433
476
  var fileNames;
@@ -461,7 +504,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
461
504
  }
462
505
  });
463
506
  }); })];
464
- case 4:
507
+ case 5:
465
508
  _a.sent();
466
509
  return [2 /*return*/];
467
510
  }
@@ -739,10 +739,10 @@ describe('sasjs compile outside project', function () {
739
739
  return [4 /*yield*/, (0, config_1.saveGlobalRcFile)('')];
740
740
  case 1:
741
741
  _a.sent();
742
- process.projectDir = '';
743
742
  return [4 /*yield*/, (0, utils_2.setConstants)()];
744
743
  case 2:
745
744
  _a.sent();
745
+ process.projectDir = '';
746
746
  process.currentDir = path_1.default.join(__dirname, appName);
747
747
  return [4 /*yield*/, (0, utils_1.createFolder)(process.currentDir)];
748
748
  case 3:
@@ -785,6 +785,38 @@ describe('sasjs compile outside project', function () {
785
785
  }
786
786
  });
787
787
  }); });
788
+ it('should compile without duplicates', function () { return __awaiter(void 0, void 0, void 0, function () {
789
+ var testServicePath, appPath, command, compiledTestService;
790
+ var _a;
791
+ return __generator(this, function (_b) {
792
+ switch (_b.label) {
793
+ case 0:
794
+ testServicePath = path_1.default.join('services', 'admin', 'test.sas');
795
+ appPath = path_1.default.join(__dirname, appName);
796
+ return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)];
797
+ case 1:
798
+ _b.sent();
799
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(appPath, 'sasjs', 'targets', 'viya', testServicePath), '')];
800
+ case 2:
801
+ _b.sent();
802
+ command = new compileCommand_1.CompileCommand([
803
+ 'node',
804
+ 'sasjs',
805
+ 'compile',
806
+ '-t',
807
+ 'viya'
808
+ ]);
809
+ return [4 /*yield*/, command.executeCompile()];
810
+ case 3:
811
+ _b.sent();
812
+ return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(appPath, 'sasjsbuild', testServicePath))];
813
+ case 4:
814
+ compiledTestService = _b.sent();
815
+ expect((_a = compiledTestService.match(/^\*\sService start;$/gm)) === null || _a === void 0 ? void 0 : _a.length).toEqual(1);
816
+ return [2 /*return*/];
817
+ }
818
+ });
819
+ }); });
788
820
  });
789
821
  });
790
822
  var prefixConfigWithPath = function (prefixPath) { return ({
@@ -126,6 +126,11 @@ exports.angularAppFiles = {
126
126
  subFolders: []
127
127
  }
128
128
  ]
129
+ },
130
+ {
131
+ folderName: 'docs',
132
+ files: [{ fileName: 'index.html' }],
133
+ subFolders: []
129
134
  }
130
135
  ]
131
136
  };
@@ -140,6 +140,9 @@ describe('sasjs create', function () {
140
140
  _a.sent();
141
141
  return [4 /*yield*/, verifyCreateWeb('.', 'react')];
142
142
  case 4:
143
+ _a.sent();
144
+ return [4 /*yield*/, (0, test_1.verifyGitNotPresent)(process.projectDir)];
145
+ case 5:
143
146
  _a.sent();
144
147
  return [2 /*return*/];
145
148
  }
@@ -164,6 +167,9 @@ describe('sasjs create', function () {
164
167
  _a.sent();
165
168
  return [4 /*yield*/, verifyCreateWeb('test-react-app', 'react')];
166
169
  case 4:
170
+ _a.sent();
171
+ return [4 /*yield*/, (0, test_1.verifyGitNotPresent)(process.projectDir)];
172
+ case 5:
167
173
  _a.sent();
168
174
  return [2 /*return*/];
169
175
  }
@@ -212,6 +218,9 @@ describe('sasjs create', function () {
212
218
  _a.sent();
213
219
  return [4 /*yield*/, verifyCreateWeb('test-angular-app', 'angular')];
214
220
  case 4:
221
+ _a.sent();
222
+ return [4 /*yield*/, (0, test_1.verifyGitNotPresent)(process.projectDir)];
223
+ case 5:
215
224
  _a.sent();
216
225
  return [2 /*return*/];
217
226
  }
@@ -77,6 +77,17 @@ exports.reactAppFiles = {
77
77
  subFolders: []
78
78
  }
79
79
  ]
80
+ },
81
+ {
82
+ folderName: 'public',
83
+ files: [],
84
+ subFolders: [
85
+ {
86
+ folderName: 'docs',
87
+ files: [{ fileName: 'index.html' }],
88
+ subFolders: []
89
+ }
90
+ ]
80
91
  }
81
92
  ]
82
93
  };
@@ -21,3 +21,4 @@ export declare const verifyDotFiles: (docsFolder: string) => Promise<void>;
21
21
  export declare const verifyDotFilesNotGenerated: (docsFolder: string) => Promise<void>;
22
22
  export declare const verifyCompiledService: (compiledContent: string, macrosToTest: string[], checkInit?: boolean, checkTerm?: boolean) => Promise<void>;
23
23
  export declare const verifyCompiledJob: (compiledContent: string, macrosToTest: string[], checkInit?: boolean, checkTerm?: boolean) => Promise<void>;
24
+ export declare const verifyGitNotPresent: (folder: string) => Promise<void>;
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.verifyCompiledJob = exports.verifyCompiledService = exports.verifyDotFilesNotGenerated = exports.verifyDotFiles = exports.verifyDocs = exports.updateConfig = exports.updateTarget = exports.removeAllTargetsFromConfigs = exports.verifyPackageJsonContent = exports.verifyFolder = exports.mockProcessExit = exports.verifyStep = exports.createTestGlobalTarget = exports.generateTestTarget = exports.removeTestServerFolder = exports.removeTestApp = exports.createTestMinimalApp = exports.createTestJobsApp = exports.createTestApp = void 0;
53
+ exports.verifyGitNotPresent = exports.verifyCompiledJob = exports.verifyCompiledService = exports.verifyDotFilesNotGenerated = exports.verifyDotFiles = exports.verifyDocs = exports.updateConfig = exports.updateTarget = exports.removeAllTargetsFromConfigs = exports.verifyPackageJsonContent = exports.verifyFolder = exports.mockProcessExit = exports.verifyStep = exports.createTestGlobalTarget = exports.generateTestTarget = exports.removeTestServerFolder = exports.removeTestApp = exports.createTestMinimalApp = exports.createTestJobsApp = exports.createTestApp = void 0;
54
54
  var path_1 = __importDefault(require("path"));
55
55
  var dotenv_1 = __importDefault(require("dotenv"));
56
56
  var utils_1 = require("@sasjs/utils");
@@ -629,3 +629,20 @@ var verifyCompile = function (compiledContent, macrosToTest, checkInit, checkTer
629
629
  return [2 /*return*/];
630
630
  });
631
631
  }); };
632
+ var verifyGitNotPresent = function (folder) { return __awaiter(void 0, void 0, void 0, function () {
633
+ var gitFolderOrModules;
634
+ return __generator(this, function (_a) {
635
+ switch (_a.label) {
636
+ case 0: return [4 /*yield*/, (0, utils_1.listFilesAndSubFoldersInFolder)(folder, true)];
637
+ case 1:
638
+ gitFolderOrModules = (_a.sent()).filter(function (sub) {
639
+ return /\.git$/.test(sub) ||
640
+ new RegExp(".git".concat(utils_1.pathSepEscaped)).test(sub) ||
641
+ /\.gitmodules/.test(sub);
642
+ });
643
+ expect(gitFolderOrModules.length).toEqual(0);
644
+ return [2 /*return*/];
645
+ }
646
+ });
647
+ }); };
648
+ exports.verifyGitNotPresent = verifyGitNotPresent;
@@ -191,8 +191,19 @@ function createApp(folderPath, repoUrl, installDependencies) {
191
191
  var spinner = (0, ora_1.default)("Creating SASjs project in ".concat(folderPath, "."));
192
192
  spinner.start();
193
193
  var gitBranch = repoUrl.includes('template_sasonly') ? 'master' : 'main';
194
- shelljs_1.default.exec("cd \"".concat(folderPath, "\" && git clone --depth 1 -b ").concat(gitBranch, " ").concat(repoUrl, " ."), { silent: true });
195
- shelljs_1.default.rm('-rf', path_1.default.join(folderPath, '.git'));
194
+ var gitVersion = (shelljs_1.default
195
+ .exec("git version", { silent: true })
196
+ .stdout.match(/(?<!git version)\d+\.\d+\.\d+/) || '')[0].replace(/\./g, '');
197
+ // NOTE: git version 2.13 and greater are using '--recurse-submodules' instead of '--recurse' attribute to clone submodules
198
+ shelljs_1.default.exec("cd \"".concat(folderPath, "\" && git clone --recurse").concat(parseInt(gitVersion) > 2130 ? '-submodules' : '', " --depth 1 -b ").concat(gitBranch, " ").concat(repoUrl, " ."), { silent: true });
199
+ deleteGitFolder(folderPath);
200
+ shelljs_1.default.rm('-f', [path_1.default.join(folderPath, '.gitmodules')]);
201
+ if (repoUrl.includes('react-seed-app')) {
202
+ deleteGitFolder(path_1.default.join(folderPath, 'public', 'docs'));
203
+ }
204
+ else if (repoUrl.includes('angular-seed-app')) {
205
+ deleteGitFolder(path_1.default.join(folderPath, 'docs'));
206
+ }
196
207
  spinner.stop();
197
208
  if (installDependencies) {
198
209
  spinner.text = 'Installing dependencies...';
@@ -203,6 +214,9 @@ function createApp(folderPath, repoUrl, installDependencies) {
203
214
  spinner.stop();
204
215
  }
205
216
  }
217
+ var deleteGitFolder = function (folderPath) {
218
+ return shelljs_1.default.rm('-rf', path_1.default.join(folderPath, '.git'));
219
+ };
206
220
  function setupNpmProject(folderName) {
207
221
  return __awaiter(this, void 0, void 0, function () {
208
222
  var folderPath;
@@ -241,7 +255,7 @@ exports.setupNpmProject = setupNpmProject;
241
255
  function setupGitIgnore(folderName) {
242
256
  var _a, _b;
243
257
  return __awaiter(this, void 0, void 0, function () {
244
- var gitIgnoreFilePath, gitIgnoreExists, gitIgnoreContent, newgitIgnoreContent, regExpSasjsBuild, regExpSasjsResults, regExpNodeModules, folderPath, gitDirectoryExists;
258
+ var gitIgnoreFilePath, gitIgnoreExists, gitIgnoreContent, newgitIgnoreContent, regExpSasjsBuild, regExpSasjsResults, regExpNodeModules;
245
259
  return __generator(this, function (_c) {
246
260
  switch (_c.label) {
247
261
  case 0:
@@ -278,17 +292,7 @@ function setupGitIgnore(folderName) {
278
292
  _c.sent();
279
293
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.success('.gitignore file has been created.');
280
294
  _c.label = 7;
281
- case 7:
282
- folderPath = path_1.default.join(process.projectDir, folderName);
283
- return [4 /*yield*/, (0, utils_1.folderExists)(path_1.default.join(folderPath, '.git'))];
284
- case 8:
285
- gitDirectoryExists = _c.sent();
286
- if (!gitDirectoryExists) {
287
- shelljs_1.default.exec("cd ".concat(folderName, " && git init"), {
288
- silent: true
289
- });
290
- }
291
- return [2 /*return*/];
295
+ case 7: return [2 /*return*/];
292
296
  }
293
297
  });
294
298
  });
package/package.json CHANGED
@@ -50,7 +50,7 @@
50
50
  "@sasjs/adapter": "3.8.0",
51
51
  "@sasjs/core": "4.15.3",
52
52
  "@sasjs/lint": "1.11.2",
53
- "@sasjs/utils": "2.40.0",
53
+ "@sasjs/utils": "2.40.1",
54
54
  "chalk": "4.1.2",
55
55
  "csv-stringify": "5.6.5",
56
56
  "dotenv": "10.0.0",
@@ -94,5 +94,5 @@
94
94
  "typescript": "4.5.4",
95
95
  "util": "0.12.4"
96
96
  },
97
- "version": "3.11.0"
97
+ "version": "3.12.2"
98
98
  }