@sasjs/cli 3.13.6 → 3.14.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.
@@ -97,6 +97,7 @@ var compile_1 = require("../compile/compile");
97
97
  var config_2 = require("./internal/config");
98
98
  var getLaunchPageCode_1 = require("./internal/getLaunchPageCode");
99
99
  var types_1 = require("@sasjs/utils/types");
100
+ var compressAndSave_1 = require("../../utils/compressAndSave");
100
101
  function build(target) {
101
102
  return __awaiter(this, void 0, void 0, function () {
102
103
  return __generator(this, function (_a) {
@@ -114,47 +115,48 @@ function build(target) {
114
115
  }
115
116
  exports.build = build;
116
117
  function createFinalSasFiles(target) {
117
- var _a, _b, _c, _d, _e, _f, _g;
118
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
118
119
  return __awaiter(this, void 0, void 0, function () {
119
- var streamConfig, streamWeb, buildConfig, serverType, name, macroFolders, buildOutputFileName, buildDestinationFolder, finalSasFileContent, finalFilePath, finalFilePathJSON, buildInfo, buildInit, buildTerm, macroCorePath, dependencyFilePaths, dependenciesContent, _h, folderContent, folderContentJSON, servicePackSASjs, servicePack;
120
- return __generator(this, function (_j) {
121
- switch (_j.label) {
120
+ var streamConfig, streamWeb, buildConfig, serverType, name, macroFolders, buildOutputFileName, buildDestinationFolder, finalSasFileContent, finalFilePath, finalFilePathJSON, finalFilePathZipped, buildInfo, buildInit, buildTerm, macroCorePath, dependencyFilePaths, dependenciesContent, _k, folderContent, folderContentJSON, servicePackSASjs, servicePack;
121
+ return __generator(this, function (_l) {
122
+ switch (_l.label) {
122
123
  case 0:
123
124
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info('Creating output SAS and JSON files.');
124
125
  return [4 /*yield*/, (0, config_1.getStreamConfig)(target)];
125
126
  case 1:
126
- streamConfig = _j.sent();
127
+ streamConfig = _l.sent();
127
128
  streamWeb = (_b = streamConfig.streamWeb) !== null && _b !== void 0 ? _b : false;
128
129
  buildConfig = target.buildConfig, serverType = target.serverType, name = target.name;
129
130
  return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
130
131
  case 2:
131
- macroFolders = _j.sent();
132
+ macroFolders = _l.sent();
132
133
  buildOutputFileName = (_c = buildConfig === null || buildConfig === void 0 ? void 0 : buildConfig.buildOutputFileName) !== null && _c !== void 0 ? _c : "".concat(name, ".sas");
133
134
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
134
135
  finalSasFileContent = '';
135
136
  finalFilePath = path_1.default.join(buildDestinationFolder, buildOutputFileName);
136
137
  finalFilePathJSON = path_1.default.join(buildDestinationFolder, "".concat(name, ".json"));
138
+ finalFilePathZipped = path_1.default.join(buildDestinationFolder, "".concat(name, ".json.zip"));
137
139
  return [4 /*yield*/, getBuildInfo(target, streamWeb)];
138
140
  case 3:
139
- buildInfo = _j.sent();
141
+ buildInfo = _l.sent();
140
142
  finalSasFileContent += "\n".concat(buildInfo);
141
143
  return [4 /*yield*/, (0, config_2.getBuildInit)(target)];
142
144
  case 4:
143
- buildInit = _j.sent();
145
+ buildInit = _l.sent();
144
146
  return [4 /*yield*/, (0, config_2.getBuildTerm)(target)];
145
147
  case 5:
146
- buildTerm = _j.sent();
148
+ buildTerm = _l.sent();
147
149
  macroCorePath = process.sasjsConstants.macroCorePath;
148
150
  return [4 /*yield*/, (0, utils_1.getDependencyPaths)("".concat(buildTerm, "\n").concat(buildInit), macroFolders, macroCorePath)];
149
151
  case 6:
150
- dependencyFilePaths = _j.sent();
152
+ dependencyFilePaths = _l.sent();
151
153
  return [4 /*yield*/, getDependencies(dependencyFilePaths)];
152
154
  case 7:
153
- dependenciesContent = _j.sent();
155
+ dependenciesContent = _l.sent();
154
156
  finalSasFileContent += "\n".concat(dependenciesContent, "\n\n").concat(buildInit, "\n");
155
157
  return [4 /*yield*/, getFolderContent(serverType)];
156
158
  case 8:
157
- _h = _j.sent(), folderContent = _h.folderContent, folderContentJSON = _h.folderContentJSON;
159
+ _k = _l.sent(), folderContent = _k.folderContent, folderContentJSON = _k.folderContentJSON;
158
160
  servicePackSASjs = {
159
161
  appLoc: target.appLoc,
160
162
  fileTree: folderContentJSON
@@ -176,7 +178,7 @@ function createFinalSasFiles(target) {
176
178
  (_d = process.logger) === null || _d === void 0 ? void 0 : _d.debug("Creating file ".concat(finalFilePath, " ."));
177
179
  return [4 /*yield*/, (0, utils_1.createFile)(finalFilePath, finalSasFileContent)];
178
180
  case 9:
179
- _j.sent();
181
+ _l.sent();
180
182
  (_e = process.logger) === null || _e === void 0 ? void 0 : _e.success("File ".concat(finalFilePath, " has been created."));
181
183
  (_f = process.logger) === null || _f === void 0 ? void 0 : _f.debug("Creating file ".concat(finalFilePathJSON, " ."));
182
184
  servicePack = target.serverType === utils_1.ServerType.Sasjs
@@ -184,8 +186,13 @@ function createFinalSasFiles(target) {
184
186
  : folderContentJSON;
185
187
  return [4 /*yield*/, (0, utils_1.createFile)(finalFilePathJSON, JSON.stringify(servicePack, null, 1))];
186
188
  case 10:
187
- _j.sent();
189
+ _l.sent();
188
190
  (_g = process.logger) === null || _g === void 0 ? void 0 : _g.success("File ".concat(finalFilePathJSON, " has been created."));
191
+ (_h = process.logger) === null || _h === void 0 ? void 0 : _h.debug("Creating file ".concat(finalFilePathZipped, " ."));
192
+ return [4 /*yield*/, (0, compressAndSave_1.compressAndSave)(finalFilePathZipped, JSON.stringify(servicePack, null, 1))];
193
+ case 11:
194
+ _l.sent();
195
+ (_j = process.logger) === null || _j === void 0 ? void 0 : _j.success("File ".concat(finalFilePathZipped, " has been created."));
189
196
  return [2 /*return*/];
190
197
  }
191
198
  });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a zip file.
3
+ * Having single JSON file in it.
4
+ * @param {string} saveTo - full path to save the file.
5
+ * @param {string} contents - contents of JSON file.
6
+ */
7
+ export declare const compressAndSave: (saveTo: string, contents: string) => Promise<void>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.compressAndSave = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var adm_zip_1 = __importDefault(require("adm-zip"));
45
+ /**
46
+ * Creates a zip file.
47
+ * Having single JSON file in it.
48
+ * @param {string} saveTo - full path to save the file.
49
+ * @param {string} contents - contents of JSON file.
50
+ */
51
+ var compressAndSave = function (saveTo, contents) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var zip, filenameInZip;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ zip = new adm_zip_1.default();
57
+ filenameInZip = path_1.default.basename(saveTo, path_1.default.extname(saveTo));
58
+ // add file directly
59
+ zip.addFile(filenameInZip, Buffer.from(contents, 'utf8'), 'entry comment goes here');
60
+ return [4 /*yield*/, zip.writeZipPromise(saveTo, { overwrite: true })];
61
+ case 1:
62
+ _a.sent();
63
+ return [2 /*return*/];
64
+ }
65
+ });
66
+ }); };
67
+ exports.compressAndSave = compressAndSave;
@@ -6,7 +6,8 @@ var builtFiles = function (buildFileName) {
6
6
  folderName: 'sasjsbuild',
7
7
  files: [
8
8
  { fileName: "".concat(buildFileName, ".sas") },
9
- { fileName: "".concat(buildFileName, ".json") }
9
+ { fileName: "".concat(buildFileName, ".json") },
10
+ { fileName: "".concat(buildFileName, ".json.zip") }
10
11
  ],
11
12
  subFolders: [
12
13
  {
@@ -6,7 +6,8 @@ var builtFilesCustom1 = function (buildFileName) {
6
6
  folderName: 'sasjsbuild',
7
7
  files: [
8
8
  { fileName: "".concat(buildFileName, ".sas") },
9
- { fileName: "".concat(buildFileName, ".json") }
9
+ { fileName: "".concat(buildFileName, ".json") },
10
+ { fileName: "".concat(buildFileName, ".json.zip") }
10
11
  ],
11
12
  subFolders: [
12
13
  {
@@ -3,7 +3,7 @@ export * from './config';
3
3
  export * from './displayResult';
4
4
  export * from './file';
5
5
  export * from './loadEnvVariables';
6
- export * from './setProjectDir';
7
6
  export * from './setConstants';
7
+ export * from './setProjectDir';
8
8
  export * from './utils';
9
9
  export * from './validateTargetName';
@@ -15,7 +15,7 @@ __exportStar(require("./config"), exports);
15
15
  __exportStar(require("./displayResult"), exports);
16
16
  __exportStar(require("./file"), exports);
17
17
  __exportStar(require("./loadEnvVariables"), exports);
18
- __exportStar(require("./setProjectDir"), exports);
19
18
  __exportStar(require("./setConstants"), exports);
19
+ __exportStar(require("./setProjectDir"), exports);
20
20
  __exportStar(require("./utils"), exports);
21
21
  __exportStar(require("./validateTargetName"), exports);
package/package.json CHANGED
@@ -51,6 +51,7 @@
51
51
  "@sasjs/core": "4.23.4",
52
52
  "@sasjs/lint": "1.11.2",
53
53
  "@sasjs/utils": "2.44.0",
54
+ "adm-zip": "0.5.9",
54
55
  "chalk": "4.1.2",
55
56
  "csv-stringify": "5.6.5",
56
57
  "dotenv": "10.0.0",
@@ -72,6 +73,7 @@
72
73
  "devDependencies": {
73
74
  "@babel/preset-env": "7.15.6",
74
75
  "@babel/preset-typescript": "7.15.0",
76
+ "@types/adm-zip": "0.5.0",
75
77
  "@types/find": "0.2.1",
76
78
  "@types/jest": "27.0.2",
77
79
  "@types/jsdom": "16.2.13",
@@ -94,5 +96,5 @@
94
96
  "typescript": "4.5.4",
95
97
  "util": "0.12.4"
96
98
  },
97
- "version": "3.13.6"
99
+ "version": "3.14.0"
98
100
  }