@sasjs/cli 3.15.1 → 3.16.1

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 (37) hide show
  1. package/README.md +3 -0
  2. package/build/commands/build/build.js +4 -4
  3. package/build/commands/compile/internal/spec/compileTestFile.spec.js +5 -3
  4. package/build/commands/deploy/spec/cbd.spec.js +38 -17
  5. package/build/commands/testing/spec/testing.spec.js +5 -0
  6. package/build/commands/web/internal/createAssetServices.d.ts +11 -2
  7. package/build/commands/web/internal/createAssetServices.js +83 -92
  8. package/build/commands/web/internal/getAssetPath.d.ts +2 -0
  9. package/build/commands/web/internal/getAssetPath.js +17 -0
  10. package/build/commands/web/internal/modifyLinksInContent.d.ts +2 -0
  11. package/build/commands/web/internal/modifyLinksInContent.js +11 -0
  12. package/build/commands/web/internal/sas9/createClickMeService.d.ts +6 -0
  13. package/build/commands/web/internal/sas9/createClickMeService.js +91 -0
  14. package/build/commands/web/internal/sas9/generateAssetService.d.ts +7 -0
  15. package/build/commands/web/internal/sas9/generateAssetService.js +75 -0
  16. package/build/commands/web/internal/sas9/getWebServiceContent.d.ts +7 -0
  17. package/build/commands/web/internal/{getWebServiceContent.js → sas9/getWebServiceContent.js} +12 -8
  18. package/build/commands/web/internal/sas9/index.d.ts +3 -0
  19. package/build/commands/web/internal/sas9/index.js +15 -0
  20. package/build/commands/web/internal/sasViya/createClickMeFile.d.ts +6 -0
  21. package/build/commands/web/internal/sasViya/createClickMeFile.js +63 -0
  22. package/build/commands/web/internal/sasViya/index.d.ts +1 -0
  23. package/build/commands/web/internal/sasViya/index.js +13 -0
  24. package/build/commands/web/internal/sasjsout.d.ts +1 -1
  25. package/build/commands/web/internal/sasjsout.js +2 -1
  26. package/build/commands/web/internal/updateAllTags.d.ts +7 -4
  27. package/build/commands/web/internal/updateAllTags.js +5 -0
  28. package/build/commands/web/internal/updateLinkTag.d.ts +2 -4
  29. package/build/commands/web/internal/updateScriptTag.d.ts +2 -4
  30. package/build/commands/web/internal/updateScriptTag.js +32 -32
  31. package/build/commands/web/internal/updateStyleTag.d.ts +2 -4
  32. package/build/commands/web/internal/updateStyleTag.js +32 -32
  33. package/build/commands/web/web.js +30 -79
  34. package/build/constants.d.ts +1 -0
  35. package/build/utils/setConstants.js +4 -2
  36. package/package.json +2 -2
  37. package/build/commands/web/internal/getWebServiceContent.d.ts +0 -2
package/README.md CHANGED
@@ -78,6 +78,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
78
78
  <td align="center"><a href="https://github.com/sabhas"><img src="https://avatars.githubusercontent.com/u/82647447?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sabir Hassan</b></sub></a><br /><a href="https://github.com/sasjs/cli/commits?author=sabhas" title="Code">💻</a> <a href="https://github.com/sasjs/cli/pulls?q=is%3Apr+reviewed-by%3Asabhas" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sasjs/cli/commits?author=sabhas" title="Tests">⚠️</a> <a href="#ideas-sabhas" title="Ideas, Planning, & Feedback">🤔</a></td>
79
79
  <td align="center"><a href="https://github.com/VladislavParhomchik"><img src="https://avatars.githubusercontent.com/u/83717836?v=4?s=100" width="100px;" alt=""/><br /><sub><b>VladislavParhomchik</b></sub></a><br /><a href="https://github.com/sasjs/cli/commits?author=VladislavParhomchik" title="Tests">⚠️</a> <a href="https://github.com/sasjs/cli/pulls?q=is%3Apr+reviewed-by%3AVladislavParhomchik" title="Reviewed Pull Requests">👀</a></td>
80
80
  </tr>
81
+ <tr>
82
+ <td align="center"><a href="http://rudvfaden.github.io/"><img src="https://avatars.githubusercontent.com/u/2445577?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rud Faden</b></sub></a><br /><a href="https://github.com/sasjs/cli/issues?q=author%3Arudvfaden" title="Bug reports">🐛</a></td>
83
+ </tr>
81
84
  </table>
82
85
 
83
86
  <!-- markdownlint-restore -->
@@ -200,12 +200,12 @@ function createFinalSasFiles(target) {
200
200
  }
201
201
  function getBuildInfo(target, streamWeb) {
202
202
  return __awaiter(this, void 0, void 0, function () {
203
- var buildConfig, serverType, appLoc, macroFolders, createWebServiceScript, macroCorePath, dependencyFilePaths, createFileScript, dependencyFilePathsForCreateFile, gsubScript, dependencyFilePathsForGsubScript, dependenciesContent, buildVars;
203
+ var buildConfig, serverType, appLoc, serverName, macroFolders, createWebServiceScript, macroCorePath, dependencyFilePaths, createFileScript, dependencyFilePathsForCreateFile, gsubScript, dependencyFilePathsForGsubScript, dependenciesContent, buildVars;
204
204
  return __generator(this, function (_a) {
205
205
  switch (_a.label) {
206
206
  case 0:
207
207
  buildConfig = '';
208
- serverType = target.serverType, appLoc = target.appLoc;
208
+ serverType = target.serverType, appLoc = target.appLoc, serverName = target.serverName;
209
209
  return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
210
210
  case 1:
211
211
  macroFolders = _a.sent();
@@ -244,7 +244,7 @@ function getBuildInfo(target, streamWeb) {
244
244
  return [4 /*yield*/, getBuildVars(target)];
245
245
  case 10:
246
246
  buildVars = _a.sent();
247
- return [2 /*return*/, "\n/**\n * The appLoc represents the metadata or SAS Drive location of the app you\n * are about to deploy\n *\n * To set an alternative appLoc, simply populate the appLoc variable prior\n * to running this program, eg:\n *\n * %let apploc=/my/apploc;\n * %inc thisfile;\n *\n */\n\n%global appLoc;\n%let compiled_apploc=".concat(appLoc, ";\n\n%let appLoc=%sysfunc(coalescec(&appLoc,&compiled_apploc));\n\n%let sasjs_clickmeservice=clickme;\n%let syscc=0;\noptions ps=max nonotes nosgen nomprint nomlogic nosource2 nosource noquotelenmax;\n/* user supplied build vars */\n").concat(buildVars, "\n/* user supplied build vars end */\n/* system macro dependencies for build process */\n").concat(dependenciesContent, "\n/* system macro dependencies for build process end*/\n/* system macros for build process */\n").concat(buildConfig, "\n/* system macros for build process end */\n")];
247
+ return [2 /*return*/, "\n/**\n * The appLoc represents the metadata or SAS Drive location of the app you\n * are about to deploy\n *\n * To set an alternative appLoc, simply populate the appLoc variable prior\n * to running this program, eg:\n *\n * %let apploc=/my/apploc;\n * %inc thisfile;\n *\n */\n\n%global appLoc serverName;\n%let compiled_apploc=".concat(appLoc, ";\n\n").concat(serverType === utils_1.ServerType.Sas9 ? "%let serverName=".concat(serverName, ";") : '', "\n\n%let appLoc=%sysfunc(coalescec(&appLoc,&compiled_apploc));\n\n%let sasjs_clickmeservice=clickme;\n%let syscc=0;\noptions ps=max nonotes nosgen nomprint nomlogic nosource2 nosource noquotelenmax;\n/* user supplied build vars */\n").concat(buildVars, "\n/* user supplied build vars end */\n/* system macro dependencies for build process */\n").concat(dependenciesContent, "\n/* system macro dependencies for build process end*/\n/* system macros for build process */\n").concat(buildConfig, "\n/* system macros for build process end */\n")];
248
248
  }
249
249
  });
250
250
  });
@@ -314,7 +314,7 @@ function getWebServiceScriptInvocation(serverType, isSASFile, encoded) {
314
314
  ? "%mv_createwebservice(path=&appLoc/&path, name=&service, code=sascode ,replace=yes)"
315
315
  : "%mv_createfile(path=&appLoc/&path, name=&filename, inref=filecode".concat(encodedParam, ")");
316
316
  case utils_1.ServerType.Sas9:
317
- return "%mm_createwebservice(path=&appLoc/&path, name=&service, code=sascode ,replace=yes)";
317
+ return "%mm_createwebservice(path=&appLoc/&path, name=&service, code=sascode, server=&serverName, replace=yes)";
318
318
  case utils_1.ServerType.Sasjs:
319
319
  return isSASFile
320
320
  ? "%mv_createwebservice(path=&appLoc/&path, name=&service, code=sascode ,replace=yes)"
@@ -131,7 +131,7 @@ describe('compileTestFile', function () {
131
131
  testVar = replaceLineBreaks("* Test Variables start;\n\n%let ".concat(Object.keys(target.testConfig.macroVars)[0], "=").concat(Object.values(target.testConfig.macroVars)[0], ";\n\n* Test Variables end;"));
132
132
  testInit = replaceLineBreaks("* TestInit start;\n\n\n%put testing, init;\n* TestInit end;");
133
133
  testTerm = replaceLineBreaks("* TestTerm start;\n\n\n%put testing, termed;\n* TestTerm end;");
134
- mvWebout = "%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL<br> ,showmeta=NO<br>);";
134
+ mvWebout = "%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL<br> ,showmeta=N";
135
135
  expect(testFileContent.indexOf(testVar)).toBeGreaterThan(-1);
136
136
  expect(testFileContent.indexOf(testInit)).toBeGreaterThan(-1);
137
137
  expect(testFileContent.indexOf(testTerm)).toBeGreaterThan(-1);
@@ -315,6 +315,7 @@ describe('compileTestFile', function () {
315
315
  });
316
316
  }); });
317
317
  it('should not log 0/0 coverage', function () { return __awaiter(void 0, void 0, void 0, function () {
318
+ var totalCalls;
318
319
  return __generator(this, function (_a) {
319
320
  switch (_a.label) {
320
321
  case 0:
@@ -322,10 +323,11 @@ describe('compileTestFile', function () {
322
323
  return [4 /*yield*/, (0, compile_1.compile)(target)];
323
324
  case 1:
324
325
  _a.sent();
325
- expect(process.logger.info).toHaveBeenCalledTimes(15);
326
+ totalCalls = 16;
327
+ expect(process.logger.info).toHaveBeenCalledTimes(totalCalls);
326
328
  expect(process.logger.info).toHaveBeenNthCalledWith(13, "Test coverage:");
327
329
  expect(process.logger.info).toHaveBeenNthCalledWith(14, "Services coverage: 0/4 (".concat(chalk_1.default.greenBright('0%'), ")"));
328
- expect(process.logger.info).toHaveBeenLastCalledWith("Overall coverage: 0/4 (".concat(chalk_1.default.greenBright('0%'), ")"));
330
+ expect(process.logger.info).toHaveBeenNthCalledWith(totalCalls - 1, "Overall coverage: 0/4 (".concat(chalk_1.default.greenBright('0%'), ")"));
329
331
  return [2 /*return*/];
330
332
  }
331
333
  });
@@ -39,7 +39,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ var path_1 = __importDefault(require("path"));
42
43
  var node_1 = __importDefault(require("@sasjs/adapter/node"));
44
+ var js_base64_1 = require("js-base64");
43
45
  var utils_1 = require("@sasjs/utils");
44
46
  var test_1 = require("../../../utils/test");
45
47
  var types_1 = require("../../../types");
@@ -78,7 +80,7 @@ describe('sasjs cbd with server type SASJS', function () {
78
80
  });
79
81
  }); });
80
82
  it("should deploy compile and build to sasjs/server", function () { return __awaiter(void 0, void 0, void 0, function () {
81
- var sasjs, customTarget, macroCorePath, mf_getuser, mp_jsonout, ms_webout, webout, streamConfig;
83
+ var sasjs, customTarget, macroCorePath, mf_getuser, mp_jsonout, ms_webout, webout, mocksPath, appinitJSPath, getdataJSPath, appinitJSContents, getdataJSContents;
82
84
  return __generator(this, function (_a) {
83
85
  switch (_a.label) {
84
86
  case 0:
@@ -90,6 +92,13 @@ describe('sasjs cbd with server type SASJS', function () {
90
92
  message: 'message'
91
93
  });
92
94
  });
95
+ return [4 /*yield*/, (0, test_1.updateConfig)({
96
+ serviceConfig: {
97
+ serviceFolders: ['sasjs/services/common']
98
+ }
99
+ })];
100
+ case 1:
101
+ _a.sent();
93
102
  return [4 /*yield*/, (0, utils_2.updateLocalTarget)(target.name, {
94
103
  jobConfig: undefined,
95
104
  serviceConfig: undefined,
@@ -98,26 +107,26 @@ describe('sasjs cbd with server type SASJS', function () {
98
107
  deployScripts: ["sasjsbuild/".concat(target.name, ".sas")]
99
108
  }
100
109
  })];
101
- case 1:
110
+ case 2:
102
111
  _a.sent();
103
112
  return [4 /*yield*/, (0, config_1.findTargetInConfiguration)(target.name, types_1.TargetScope.Local)];
104
- case 2:
113
+ case 3:
105
114
  customTarget = (_a.sent()).target;
106
115
  return [4 /*yield*/, expect((0, build_1.build)(customTarget)).toResolve()];
107
- case 3:
116
+ case 4:
108
117
  _a.sent();
109
118
  return [4 /*yield*/, (0, deploy_1.deploy)(customTarget, true, sasjs)];
110
- case 4:
119
+ case 5:
111
120
  _a.sent();
112
121
  macroCorePath = process.sasjsConstants.macroCorePath;
113
122
  return [4 /*yield*/, (0, utils_1.readFile)("".concat(macroCorePath, "/base/mf_getuser.sas"))];
114
- case 5:
123
+ case 6:
115
124
  mf_getuser = _a.sent();
116
125
  return [4 /*yield*/, (0, utils_1.readFile)("".concat(macroCorePath, "/base/mp_jsonout.sas"))];
117
- case 6:
126
+ case 7:
118
127
  mp_jsonout = _a.sent();
119
128
  return [4 /*yield*/, (0, utils_1.readFile)("".concat(macroCorePath, "/server/ms_webout.sas"))];
120
- case 7:
129
+ case 8:
121
130
  ms_webout = _a.sent();
122
131
  webout = ' %macro webout(action,ds,dslabel=,fmt=,missing=NULL,showmeta=NO);\n' +
123
132
  ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt\n' +
@@ -125,13 +134,15 @@ describe('sasjs cbd with server type SASJS', function () {
125
134
  ' ,showmeta=&showmeta\n' +
126
135
  ' )' +
127
136
  ' %mend;\n';
128
- streamConfig = {
129
- assetPaths: [],
130
- streamServiceName: 'clickme',
131
- streamWeb: false,
132
- streamWebFolder: '',
133
- webSourcePath: ''
134
- };
137
+ mocksPath = path_1.default.join(__dirname, appName, 'sasjs', 'mocks');
138
+ appinitJSPath = path_1.default.join(mocksPath, 'services', 'common', 'appinit.js');
139
+ getdataJSPath = path_1.default.join(mocksPath, 'services', 'common', 'getdata.js');
140
+ return [4 /*yield*/, (0, utils_1.readFile)(appinitJSPath)];
141
+ case 9:
142
+ appinitJSContents = _a.sent();
143
+ return [4 /*yield*/, (0, utils_1.readFile)(getdataJSPath)];
144
+ case 10:
145
+ getdataJSContents = _a.sent();
135
146
  expect(sasjs.deployToSASjs).toHaveBeenCalledWith({
136
147
  appLoc: target.appLoc,
137
148
  fileTree: {
@@ -144,17 +155,27 @@ describe('sasjs cbd with server type SASJS', function () {
144
155
  name: 'common',
145
156
  type: 'folder',
146
157
  members: [
158
+ {
159
+ name: 'appinit.js',
160
+ type: 'file',
161
+ code: (0, js_base64_1.encode)(appinitJSContents)
162
+ },
147
163
  {
148
164
  name: 'appinit',
149
165
  type: 'service',
150
166
  code: (0, utils_3.removeComments)("".concat(mf_getuser).concat(mp_jsonout).concat(ms_webout).concat(webout) +
151
- '/* provide additional debug info */\n%global _program;\n%put &=syscc;\n%put user=%mf_getuser();\n%put pgm=&_program;\n%put timestamp=%sysfunc(datetime(),datetime19.);\n* Service Variables start;\n* Service Variables end;\n* SAS Macros start;\n* SAS Macros end;\n* SAS Includes start;\n* SAS Includes end;\n* Binary Files start;\n* Binary Files end;\n* Service start;\nproc sql;\ncreate table areas as select distinct area\n from sashelp.springs;\n%webout(OPEN)\n%webout(OBJ,areas)\n%webout(CLOSE)\n* Service end;')
167
+ '/* provide additional debug info */\n%global _program;\n%put &=syscc;\n%put user=%mf_getuser();\n%put pgm=&_program;\n%put timestamp=%sysfunc(datetime(),datetime19.);\n* Service Variables start;\n* Service Variables end;\n* SAS Macros start;\n* SAS Macros end;\n* SAS Includes start;\n* SAS Includes end;\n* Binary Files start;\n* Binary Files end;\n* Service start;\nproc sql;\ncreate table areas as select distinct area\n from mydb.springs;\n%webout(OPEN)\n%webout(OBJ,areas)\n%webout(CLOSE)\n* Service end;')
168
+ },
169
+ {
170
+ name: 'getdata.js',
171
+ type: 'file',
172
+ code: (0, js_base64_1.encode)(getdataJSContents)
152
173
  },
153
174
  {
154
175
  name: 'getdata',
155
176
  type: 'service',
156
177
  code: (0, utils_3.removeComments)("".concat(mf_getuser).concat(mp_jsonout).concat(ms_webout).concat(webout) +
157
- '/* provide additional debug info */\n%global _program;\n%put &=syscc;\n%put user=%mf_getuser();\n%put pgm=&_program;\n%put timestamp=%sysfunc(datetime(),datetime19.);\n* Service Variables start;\n* Service Variables end;\n* SAS Macros start;\n* SAS Macros end;\n* SAS Includes start;\n* SAS Includes end;\n* Binary Files start;\n* Binary Files end;\n* Service start;\n%webout(FETCH)\nproc sql;\ncreate table springs as select * from sashelp.springs\n where area in (select area from work.areas);\n%webout(OPEN)\n%webout(OBJ,springs)\n%webout(CLOSE)\n* Service end;')
178
+ '/* provide additional debug info */\n%global _program;\n%put &=syscc;\n%put user=%mf_getuser();\n%put pgm=&_program;\n%put timestamp=%sysfunc(datetime(),datetime19.);\n* Service Variables start;\n* Service Variables end;\n* SAS Macros start;\n* SAS Macros end;\n* SAS Includes start;\n* SAS Includes end;\n* Binary Files start;\n* Binary Files end;\n* Service start;\n%webout(FETCH)\nproc sql;\ncreate table springs as select * from mydb.springs\n where area in (select area from work.areas);\n%webout(OPEN)\n%webout(OBJ,springs)\n%webout(CLOSE)\n* Service end;')
158
179
  }
159
180
  ]
160
181
  }
@@ -81,7 +81,9 @@ var sasJsModules = __importStar(require("../../../utils/createSASjsInstance"));
81
81
  var testResponses_1 = require("./mockedAdapter/testResponses");
82
82
  var fileModule = __importStar(require("@sasjs/utils/file"));
83
83
  var utilsModule = __importStar(require("@sasjs/utils/utils"));
84
+ var configUtils = __importStar(require("../../../utils/config"));
84
85
  var chalk_1 = __importDefault(require("chalk"));
86
+ var mocks_1 = require("../../context/spec/mocks");
85
87
  describe('sasjs test', function () {
86
88
  var expectedCoverageLcov = "TN:testsetup.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:exampleprogram.test.sas\nSF:jobs/jobs/exampleprogram.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:standalone.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:examplemacro.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:shouldFail.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.0.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.1.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:testteardown.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record";
87
89
  describe('SASVIYA', function () {
@@ -701,6 +703,9 @@ var copyTestFiles = function (appName) { return __awaiter(void 0, void 0, void 0
701
703
  });
702
704
  }); };
703
705
  var setupMocksForSASVIYA = function () {
706
+ jest
707
+ .spyOn(configUtils, 'getAuthConfig')
708
+ .mockImplementation(function () { return Promise.resolve(mocks_1.mockAuthConfig); });
704
709
  jest
705
710
  .spyOn(sasJsModules, 'createSASjsInstance')
706
711
  .mockImplementation(function (config) {
@@ -1,5 +1,14 @@
1
1
  import { StreamConfig, Target } from '@sasjs/utils';
2
- export declare const createAssetServices: (target: Target, destinationPath: string, streamConfig: StreamConfig) => Promise<{
2
+ export interface AssetPathMap {
3
3
  source: string;
4
4
  target: string;
5
- }[]>;
5
+ }
6
+ /**
7
+ * Creates all the asset services for web streaming.
8
+ * Also prepares an asset-path Map based on server type.
9
+ * @param {Target} target the target to create asset service.
10
+ * @param {string} destinationPath the location of web streaming files.
11
+ * @param {StreamConfig} streamConfig stream configuration to be used.
12
+ * @returns {AssetPathMap[]} list of all the sources specified along server based paths.
13
+ */
14
+ export declare const createAssetServices: (target: Target, destinationPath: string, { webSourcePath, streamWebFolder, assetPaths }: StreamConfig) => Promise<AssetPathMap[]>;
@@ -68,47 +68,67 @@ exports.createAssetServices = void 0;
68
68
  var path_1 = __importDefault(require("path"));
69
69
  var utils_1 = require("@sasjs/utils");
70
70
  var lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
71
- var getWebServiceContent_1 = require("./getWebServiceContent");
72
- var createAssetServices = function (target, destinationPath, streamConfig) { return __awaiter(void 0, void 0, void 0, function () {
73
- var webSourcePath, streamWebFolder, assetPaths, assetPathMap;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- webSourcePath = streamConfig.webSourcePath, streamWebFolder = streamConfig.streamWebFolder, assetPaths = streamConfig.assetPaths;
78
- assetPathMap = [];
79
- return [4 /*yield*/, (0, utils_1.asyncForEach)(__spreadArray([path_1.default.join(process.projectDir, webSourcePath)], __read((assetPaths !== null && assetPaths !== void 0 ? assetPaths : [])), false), function (assetPath) { return __awaiter(void 0, void 0, void 0, function () {
80
- var fullAssetPath, assetPathExists, assetPathMapNested;
81
- var _a;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
84
- case 0:
85
- fullAssetPath = path_1.default.isAbsolute(assetPath)
86
- ? assetPath
87
- : path_1.default.isAbsolute(webSourcePath)
88
- ? path_1.default.join(webSourcePath, assetPath)
89
- : path_1.default.join(process.projectDir, webSourcePath, assetPath);
90
- return [4 /*yield*/, (0, utils_1.folderExists)(fullAssetPath)];
91
- case 1:
92
- assetPathExists = _b.sent();
93
- if (!assetPathExists) {
94
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Assets path '".concat(fullAssetPath, "' present in 'streamConfig' doesn't exist."));
71
+ var getAssetPath_1 = require("./getAssetPath");
72
+ var sas9_1 = require("./sas9");
73
+ /**
74
+ * Creates all the asset services for web streaming.
75
+ * Also prepares an asset-path Map based on server type.
76
+ * @param {Target} target the target to create asset service.
77
+ * @param {string} destinationPath the location of web streaming files.
78
+ * @param {StreamConfig} streamConfig stream configuration to be used.
79
+ * @returns {AssetPathMap[]} list of all the sources specified along server based paths.
80
+ */
81
+ var createAssetServices = function (target, destinationPath, _a) {
82
+ var webSourcePath = _a.webSourcePath, streamWebFolder = _a.streamWebFolder, assetPaths = _a.assetPaths;
83
+ return __awaiter(void 0, void 0, void 0, function () {
84
+ var assetPathMap;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
+ case 0:
88
+ assetPathMap = [];
89
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(__spreadArray([path_1.default.join(process.projectDir, webSourcePath)], __read((assetPaths !== null && assetPaths !== void 0 ? assetPaths : [])), false), function (assetPath) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var fullAssetPath, assetPathExists, assetPathMapNested;
91
+ var _a;
92
+ return __generator(this, function (_b) {
93
+ switch (_b.label) {
94
+ case 0:
95
+ fullAssetPath = path_1.default.isAbsolute(assetPath)
96
+ ? assetPath
97
+ : path_1.default.isAbsolute(webSourcePath)
98
+ ? path_1.default.join(webSourcePath, assetPath)
99
+ : path_1.default.join(process.projectDir, webSourcePath, assetPath);
100
+ return [4 /*yield*/, (0, utils_1.folderExists)(fullAssetPath)];
101
+ case 1:
102
+ assetPathExists = _b.sent();
103
+ if (!assetPathExists) {
104
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Assets path '".concat(fullAssetPath, "' present in 'streamConfig' doesn't exist."));
105
+ return [2 /*return*/];
106
+ }
107
+ return [4 /*yield*/, createAssetsServicesNested(target, streamWebFolder, fullAssetPath, destinationPath)];
108
+ case 2:
109
+ assetPathMapNested = _b.sent();
110
+ assetPathMap.push.apply(assetPathMap, __spreadArray([], __read(assetPathMapNested), false));
95
111
  return [2 /*return*/];
96
- }
97
- return [4 /*yield*/, createAssetsServicesNested(target, streamWebFolder, fullAssetPath, destinationPath)];
98
- case 2:
99
- assetPathMapNested = _b.sent();
100
- assetPathMap.push.apply(assetPathMap, __spreadArray([], __read(assetPathMapNested), false));
101
- return [2 /*return*/];
102
- }
103
- });
104
- }); })];
105
- case 1:
106
- _a.sent();
107
- return [2 /*return*/, (0, lodash_uniqby_1.default)(assetPathMap, 'source')];
108
- }
112
+ }
113
+ });
114
+ }); })];
115
+ case 1:
116
+ _b.sent();
117
+ return [2 /*return*/, (0, lodash_uniqby_1.default)(assetPathMap, 'source')];
118
+ }
119
+ });
109
120
  });
110
- }); };
121
+ };
111
122
  exports.createAssetServices = createAssetServices;
123
+ /**
124
+ * Creates all the asset services for web streaming for a specific folder.
125
+ * Also prepares an asset-path Map based on server type.
126
+ * @param {Target} target the target to create asset service.
127
+ * @param {string} streamWebFolder the location of web streaming files.
128
+ * @param {string} fullAssetPath path of the specific folder used to create all services for.
129
+ * @param {string} destinationPath path of the destination folder for services.
130
+ * @returns {AssetPathMap[]} list of all the sources specified along server based paths.
131
+ */
112
132
  var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPath, destinationPath) { return __awaiter(void 0, void 0, void 0, function () {
113
133
  var assetPathMap, filePaths, folderNames;
114
134
  return __generator(this, function (_a) {
@@ -119,37 +139,42 @@ var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPat
119
139
  case 1:
120
140
  filePaths = _a.sent();
121
141
  return [4 /*yield*/, (0, utils_1.asyncForEach)(filePaths, function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
122
- var fullFileName, fileName, fileExtension, sourcePath, assetServiceUrl, fileName_1, assetServiceUrl;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
142
+ var fullFileName, fileName, fileExtension, sourcePath, assetServiceUrl, _a, fileName_1;
143
+ return __generator(this, function (_b) {
144
+ switch (_b.label) {
125
145
  case 0:
126
146
  fullFileName = path_1.default.basename(filePath);
127
147
  fileName = fullFileName.substring(0, fullFileName.lastIndexOf('.'));
128
148
  fileExtension = path_1.default
129
149
  .basename(filePath)
130
150
  .substring(fullFileName.lastIndexOf('.') + 1, fullFileName.length);
131
- if (!(fileName && fileExtension)) return [3 /*break*/, 4];
151
+ if (!(fileName && fileExtension)) return [3 /*break*/, 7];
132
152
  sourcePath = path_1.default.join(fullAssetPath, filePath);
133
- if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 2];
134
- return [4 /*yield*/, (0, utils_1.copy)(sourcePath, path_1.default.join(destinationPath, fullFileName))];
135
- case 1:
136
- _a.sent();
137
- assetServiceUrl = getAssetPath(target.appLoc, target.serverType, streamWebFolder, fullFileName);
138
- assetPathMap.push({
139
- source: fullFileName,
140
- target: assetServiceUrl
141
- });
142
- return [3 /*break*/, 4];
143
- case 2: return [4 /*yield*/, generateAssetService(sourcePath, filePath, destinationPath, target.serverType)];
144
- case 3:
145
- fileName_1 = _a.sent();
146
- assetServiceUrl = getAssetPath(target.appLoc, target.serverType, streamWebFolder, fileName_1.replace('.sas', ''));
153
+ assetServiceUrl = void 0;
154
+ _a = target.serverType;
155
+ switch (_a) {
156
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 1];
157
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 3];
158
+ }
159
+ return [3 /*break*/, 5];
160
+ case 1: return [4 /*yield*/, (0, utils_1.copy)(sourcePath, path_1.default.join(destinationPath, fullFileName))];
161
+ case 2:
162
+ _b.sent();
163
+ assetServiceUrl = (0, getAssetPath_1.getAssetPath)(target.appLoc, target.serverType, streamWebFolder, fullFileName);
164
+ return [3 /*break*/, 6];
165
+ case 3: return [4 /*yield*/, (0, sas9_1.generateAssetService)(sourcePath, destinationPath)];
166
+ case 4:
167
+ fileName_1 = _b.sent();
168
+ assetServiceUrl = (0, getAssetPath_1.getAssetPath)(target.appLoc, target.serverType, streamWebFolder, fileName_1.replace('.sas', ''));
169
+ return [3 /*break*/, 6];
170
+ case 5: throw new Error("Server Type: ".concat(target.serverType, " is not supported for processing streaming file."));
171
+ case 6:
147
172
  assetPathMap.push({
148
173
  source: fullFileName,
149
174
  target: assetServiceUrl
150
175
  });
151
- _a.label = 4;
152
- case 4: return [2 /*return*/];
176
+ _b.label = 7;
177
+ case 7: return [2 /*return*/];
153
178
  }
154
179
  });
155
180
  }); })];
@@ -187,37 +212,3 @@ var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPat
187
212
  }
188
213
  });
189
214
  }); };
190
- var generateAssetService = function (sourcePath, filePath, destinationPath, serverType) { return __awaiter(void 0, void 0, void 0, function () {
191
- var fileExtension, fileType, fileName, base64string, serviceContent;
192
- return __generator(this, function (_a) {
193
- switch (_a.label) {
194
- case 0:
195
- fileExtension = path_1.default.extname(filePath);
196
- fileType = fileExtension.replace('.', '').toUpperCase();
197
- fileName = path_1.default
198
- .basename(filePath)
199
- .replace(new RegExp(fileExtension + '$'), fileExtension.replace('.', '-'));
200
- return [4 /*yield*/, (0, utils_1.base64EncodeFile)(sourcePath)];
201
- case 1:
202
- base64string = _a.sent();
203
- return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)(base64string, fileType, serverType)];
204
- case 2:
205
- serviceContent = _a.sent();
206
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(fileName, ".sas")), serviceContent)];
207
- case 3:
208
- _a.sent();
209
- return [2 /*return*/, "".concat(fileName, ".sas")];
210
- }
211
- });
212
- }); };
213
- var getAssetPath = function (appLoc, serverType, streamWebFolder, fileName) {
214
- var storedProcessPath =
215
- // the appLoc is inserted dynamically by SAS
216
- // using three forward slashes as a marker
217
- // for SAS 9 fileName is a program, with replacement in sasjsout.ts
218
- // for Viya, fileName is a FILE, with replacement in build.sas only
219
- serverType === utils_1.ServerType.SasViya
220
- ? "/SASJobExecution?_FILE=".concat(appLoc, "/services/").concat(streamWebFolder)
221
- : "/SASStoredProcess/?_PROGRAM=///".concat(streamWebFolder);
222
- return "".concat(storedProcessPath, "/").concat(fileName);
223
- };
@@ -0,0 +1,2 @@
1
+ import { ServerType } from '@sasjs/utils';
2
+ export declare const getAssetPath: (appLoc: string, serverType: ServerType, streamWebFolder: string, fileName: string) => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssetPath = void 0;
4
+ var utils_1 = require("@sasjs/utils");
5
+ var getAssetPath = function (appLoc, serverType, streamWebFolder, fileName) {
6
+ var sas9GUID = process.sasjsConstants.sas9GUID;
7
+ var storedProcessPath =
8
+ // the appLoc is inserted dynamically
9
+ // for SAS 9 files are Base 64 encoded into STPs, with
10
+ // dynamic runtime replacement of appLoc (see sasjsout.ts)
11
+ // for Viya, fileName is a FILE, with replacement harcoded in build.sas
12
+ serverType === utils_1.ServerType.SasViya
13
+ ? "/SASJobExecution?_FILE=".concat(appLoc, "/services")
14
+ : "/SASStoredProcess/?_PROGRAM=".concat(sas9GUID);
15
+ return "".concat(storedProcessPath, "/").concat(streamWebFolder, "/").concat(fileName);
16
+ };
17
+ exports.getAssetPath = getAssetPath;
@@ -0,0 +1,2 @@
1
+ import { AssetPathMap } from './createAssetServices';
2
+ export declare const modifyLinksInContent: (_content: string, assetPathMap: AssetPathMap[]) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifyLinksInContent = void 0;
4
+ var modifyLinksInContent = function (_content, assetPathMap) {
5
+ var content = _content;
6
+ assetPathMap.forEach(function (pathEntry) {
7
+ content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
8
+ });
9
+ return content;
10
+ };
11
+ exports.modifyLinksInContent = modifyLinksInContent;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates index service file for SAS9 server only.
3
+ * @param {string} indexHtmlContent contents of index source file.
4
+ * @param {string} fileName name of index service file.
5
+ */
6
+ export declare const createClickMeService: (indexHtmlContent: string, fileName: string) => Promise<void>;
@@ -0,0 +1,91 @@
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.createClickMeService = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var sasjsout_1 = require("../sasjsout");
46
+ /**
47
+ * Creates index service file for SAS9 server only.
48
+ * @param {string} indexHtmlContent contents of index source file.
49
+ * @param {string} fileName name of index service file.
50
+ */
51
+ var createClickMeService = function (indexHtmlContent, fileName) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var lines, clickMeServiceContent, buildDestinationServicesFolder;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ lines = indexHtmlContent.replace(/\r\n/g, '\n').split('\n');
57
+ clickMeServiceContent = "".concat((0, sasjsout_1.sasjsout)(), "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
58
+ lines.forEach(function (line) {
59
+ var chunkedLines = (0, utils_1.chunk)(line);
60
+ if (chunkedLines.length === 1) {
61
+ if (chunkedLines[0].length == 0)
62
+ chunkedLines[0] = ' ';
63
+ clickMeServiceContent += "put '".concat(chunkedLines[0]
64
+ .split("'")
65
+ .join("''"), "';\n");
66
+ }
67
+ else {
68
+ var combinedLines_1 = '';
69
+ chunkedLines.forEach(function (chunkedLine, index) {
70
+ var text = "put '".concat(chunkedLine.split("'").join("''"), "'");
71
+ if (index !== chunkedLines.length - 1) {
72
+ text += '@;\n';
73
+ }
74
+ else {
75
+ text += ';\n';
76
+ }
77
+ combinedLines_1 += text;
78
+ });
79
+ clickMeServiceContent += combinedLines_1;
80
+ }
81
+ });
82
+ clickMeServiceContent += 'run;\n%sasjsout(HTML)';
83
+ buildDestinationServicesFolder = process.sasjsConstants.buildDestinationServicesFolder;
84
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(buildDestinationServicesFolder, "".concat(fileName, ".sas")), clickMeServiceContent)];
85
+ case 1:
86
+ _a.sent();
87
+ return [2 /*return*/];
88
+ }
89
+ });
90
+ }); };
91
+ exports.createClickMeService = createClickMeService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates service file for SAS9 server only.
3
+ * @param {string} sourcePath path of source file.
4
+ * @param {string} destinationPath path of destination service file.
5
+ * @returns {string} name of created service file.
6
+ */
7
+ export declare const generateAssetService: (sourcePath: string, destinationPath: string) => Promise<string>;