@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
@@ -0,0 +1,75 @@
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.generateAssetService = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var _1 = require("./");
46
+ /**
47
+ * Creates service file for SAS9 server only.
48
+ * @param {string} sourcePath path of source file.
49
+ * @param {string} destinationPath path of destination service file.
50
+ * @returns {string} name of created service file.
51
+ */
52
+ var generateAssetService = function (sourcePath, destinationPath) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var fileExtension, fileType, fileName, base64string, serviceContent;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ fileExtension = path_1.default.extname(sourcePath);
58
+ fileType = fileExtension.replace('.', '').toUpperCase();
59
+ fileName = path_1.default
60
+ .basename(sourcePath)
61
+ .replace(new RegExp(fileExtension + '$'), fileExtension.replace('.', '-'));
62
+ return [4 /*yield*/, (0, utils_1.base64EncodeFile)(sourcePath)];
63
+ case 1:
64
+ base64string = _a.sent();
65
+ return [4 /*yield*/, (0, _1.getWebServiceContent)(base64string, fileType)];
66
+ case 2:
67
+ serviceContent = _a.sent();
68
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(fileName, ".sas")), serviceContent)];
69
+ case 3:
70
+ _a.sent();
71
+ return [2 /*return*/, "".concat(fileName, ".sas")];
72
+ }
73
+ });
74
+ }); };
75
+ exports.generateAssetService = generateAssetService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Prepares service code for SAS9 server only.
3
+ * @param {string} contentBase64 source code in base64.
4
+ * @param {string} type extension of source code's file in uppercase.
5
+ * @returns {string} service contents of provided source code.
6
+ */
7
+ export declare const getWebServiceContent: (contentBase64: string, type?: string) => Promise<string>;
@@ -38,8 +38,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getWebServiceContent = void 0;
40
40
  var utils_1 = require("@sasjs/utils");
41
- var sasjsout_1 = require("./sasjsout");
42
- var getWebServiceContent = function (contentBase64, type, serverType) {
41
+ var sasjsout_1 = require("../sasjsout");
42
+ /**
43
+ * Prepares service code for SAS9 server only.
44
+ * @param {string} contentBase64 source code in base64.
45
+ * @param {string} type extension of source code's file in uppercase.
46
+ * @returns {string} service contents of provided source code.
47
+ */
48
+ var getWebServiceContent = function (contentBase64, type) {
43
49
  if (type === void 0) { type = 'JS'; }
44
50
  return __awaiter(void 0, void 0, void 0, function () {
45
51
  var lines, typesToEncode, serviceContent;
@@ -47,9 +53,10 @@ var getWebServiceContent = function (contentBase64, type, serverType) {
47
53
  lines = [contentBase64];
48
54
  typesToEncode = {
49
55
  JS: 'JS64',
50
- CSS: 'CSS64'
56
+ CSS: 'CSS64',
57
+ SVG: 'SVG64'
51
58
  };
52
- serviceContent = "".concat(sasjsout_1.sasjsout, "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
59
+ serviceContent = "".concat((0, sasjsout_1.sasjsout)(), "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
53
60
  lines.forEach(function (line) {
54
61
  var chunkedLines = (0, utils_1.chunk)(line);
55
62
  if (chunkedLines.length === 1) {
@@ -70,12 +77,9 @@ var getWebServiceContent = function (contentBase64, type, serverType) {
70
77
  serviceContent += combinedLines_1;
71
78
  }
72
79
  });
73
- if (serverType === utils_1.ServerType.Sas9 && typesToEncode.hasOwnProperty(type)) {
80
+ if (typesToEncode.hasOwnProperty(type)) {
74
81
  serviceContent += "\nrun;\n%sasjsout(".concat(typesToEncode[type], ")");
75
82
  }
76
- else {
77
- serviceContent += "\nrun;\n%sasjsout(".concat(type, ")");
78
- }
79
83
  return [2 /*return*/, serviceContent];
80
84
  });
81
85
  });
@@ -0,0 +1,3 @@
1
+ export * from './createClickMeService';
2
+ export * from './generateAssetService';
3
+ export * from './getWebServiceContent';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./createClickMeService"), exports);
14
+ __exportStar(require("./generateAssetService"), exports);
15
+ __exportStar(require("./getWebServiceContent"), exports);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates index file for SASVIYA server only.
3
+ * @param {string} indexHtmlContent contents of index file.
4
+ * @param {string} fileName name of index file.
5
+ */
6
+ export declare const createClickMeFile: (indexHtmlContent: string, fileName: string) => Promise<void>;
@@ -0,0 +1,63 @@
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.createClickMeFile = void 0;
43
+ var utils_1 = require("@sasjs/utils");
44
+ var path_1 = __importDefault(require("path"));
45
+ /**
46
+ * Creates index file for SASVIYA server only.
47
+ * @param {string} indexHtmlContent contents of index file.
48
+ * @param {string} fileName name of index file.
49
+ */
50
+ var createClickMeFile = function (indexHtmlContent, fileName) { return __awaiter(void 0, void 0, void 0, function () {
51
+ var buildDestinationServicesFolder;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ buildDestinationServicesFolder = process.sasjsConstants.buildDestinationServicesFolder;
56
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(buildDestinationServicesFolder, "".concat(fileName, ".html")), indexHtmlContent)];
57
+ case 1:
58
+ _a.sent();
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ }); };
63
+ exports.createClickMeFile = createClickMeFile;
@@ -0,0 +1 @@
1
+ export * from './createClickMeFile';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./createClickMeFile"), exports);
@@ -1 +1 @@
1
- export declare const sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&type)\";\n %end;\n %else %if &type=MP4 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"video/mp4\";\n %end;\n%end;\n%else %do;\n %if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n %end;\n %else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n %end;\n %else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n %end;\n %else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n %end;\n %else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n %end;\n %else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n %end;\n %else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n %end;\n%end;\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjs temp;\n data _null_;\n file _sjs lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n if symexist('_metaperson') then put ' serverType: \"SAS9\" ,';\n else put ' serverType: \"SASVIYA\" ,';\n end;\n else if find(_infile_,' serverUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n /* More recently, SASjs apps avoid inline JS to allow strict CSP */\n length infile in1 in2 $32767;\n infile=cats(_infile_);\n spos1=index(upcase(infile),'APPLOC=\"');\n if spos1>0 then do;\n in1=substr(infile,1,spos1+7);\n in2=subpad(infile,spos1+8);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,appLoc,in2);\n putlog \"new apploc: \" infile=;\n end;\n /* find & replace serverType in HTML attributes */\n spos2=index(upcase(infile),'SERVERTYPE=\"');\n if spos2>0 then do;\n in1=substr(infile,1,spos2+11);\n in2=subpad(infile,spos2+12);\n in2=substr(in2,index(in2,'\"'));\n if symexist('sasjsprocessmode') then infile=cats(in1,\"SASJS\",in2);\n else if \"&sysprocessmode\"=\"SAS Object Server\"\n or \"&sysprocessmode\"= \"SAS Compute Server\"\n then infile=cats(in1,\"SASVIYA\",in2);\n else infile=cats(in1,\"SAS9\",in2);\n putlog \"new servertype: \" infile=;\n end;\n /* find & replace serverUrl in HTML attributes */\n spos3=index(upcase(infile),'SERVERURL=\"');\n if spos3>0 then do;\n in1=substr(infile,1,spos3+10);\n in2=subpad(infile,spos3+11);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,in2);\n putlog \"new serverUrl: \" infile=;\n end;\n if sum(spos1,spos2,spos3)>0 then put infile;\n else do;\n /* during SAS9 sasjs compile, dependencies get three slashes /// */\n infile=tranwrd(_infile_,'?_PROGRAM=///',cats(expanded_path));\n put infile;\n end;\n end;\n run;\n %let fref=_sjs;\n%end;\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=JS64 or &type=CSS64 or &type=WAV or &type=OGG or &type=WOFF\nor &type=WOFF2 or &type=TTF or &type=MP4\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n data _null_;\n length filein 8 fileid 8;\n filein = fopen(\"&fref\",'I',1,'B');\n fileid = fopen(\"_webout\",'A',1,'B');\n rec = '20'x;\n do while(fread(filein)=0);\n rc = fget(filein,rec,1);\n rc = fput(fileid, rec);\n rc =fwrite(fileid);\n end;\n rc = fclose(filein);\n rc = fclose(fileid);\n run;\n%end;\n%mend;";
1
+ export declare const sasjsout: () => string;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sasjsout = void 0;
4
- exports.sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&type)\";\n %end;\n %else %if &type=MP4 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"video/mp4\";\n %end;\n%end;\n%else %do;\n %if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n %end;\n %else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n %end;\n %else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n %end;\n %else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n %end;\n %else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n %end;\n %else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n %end;\n %else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n %end;\n%end;\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjs temp;\n data _null_;\n file _sjs lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n if symexist('_metaperson') then put ' serverType: \"SAS9\" ,';\n else put ' serverType: \"SASVIYA\" ,';\n end;\n else if find(_infile_,' serverUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n /* More recently, SASjs apps avoid inline JS to allow strict CSP */\n length infile in1 in2 $32767;\n infile=cats(_infile_);\n spos1=index(upcase(infile),'APPLOC=\"');\n if spos1>0 then do;\n in1=substr(infile,1,spos1+7);\n in2=subpad(infile,spos1+8);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,appLoc,in2);\n putlog \"new apploc: \" infile=;\n end;\n /* find & replace serverType in HTML attributes */\n spos2=index(upcase(infile),'SERVERTYPE=\"');\n if spos2>0 then do;\n in1=substr(infile,1,spos2+11);\n in2=subpad(infile,spos2+12);\n in2=substr(in2,index(in2,'\"'));\n if symexist('sasjsprocessmode') then infile=cats(in1,\"SASJS\",in2);\n else if \"&sysprocessmode\"=\"SAS Object Server\"\n or \"&sysprocessmode\"= \"SAS Compute Server\"\n then infile=cats(in1,\"SASVIYA\",in2);\n else infile=cats(in1,\"SAS9\",in2);\n putlog \"new servertype: \" infile=;\n end;\n /* find & replace serverUrl in HTML attributes */\n spos3=index(upcase(infile),'SERVERURL=\"');\n if spos3>0 then do;\n in1=substr(infile,1,spos3+10);\n in2=subpad(infile,spos3+11);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,in2);\n putlog \"new serverUrl: \" infile=;\n end;\n if sum(spos1,spos2,spos3)>0 then put infile;\n else do;\n /* during SAS9 sasjs compile, dependencies get three slashes /// */\n infile=tranwrd(_infile_,'?_PROGRAM=///',cats(expanded_path));\n put infile;\n end;\n end;\n run;\n %let fref=_sjs;\n%end;\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=JS64 or &type=CSS64 or &type=WAV or &type=OGG or &type=WOFF\nor &type=WOFF2 or &type=TTF or &type=MP4\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n data _null_;\n length filein 8 fileid 8;\n filein = fopen(\"&fref\",'I',1,'B');\n fileid = fopen(\"_webout\",'A',1,'B');\n rec = '20'x;\n do while(fread(filein)=0);\n rc = fget(filein,rec,1);\n rc = fput(fileid, rec);\n rc =fwrite(fileid);\n end;\n rc = fclose(filein);\n rc = fclose(fileid);\n run;\n%end;\n%mend;";
4
+ var sasjsout = function () { return "\n/* this macro is derived from: https://core.sasjs.io/mp__replace_8sas.html */\noptions mprint;\n%macro mp_replace(infile,\n findvar=,\n replacevar=,\n outfile=0\n)/*/STORE SOURCE*/;\n\n%local inref outref dttm ds1 rc;\n/* create filerefs */\n%let rc=%sysfunc(filename(inref,,temp,lrecl=200));\n%let rc=%sysfunc(filename(outref,,temp,lrecl=200));\n\n%if &outfile=0 %then %let outfile=&infile;\n\n/* uniquely named 32 char datasets */\n%let ds1=all%substr(%sysfunc(compress(%sysfunc(uuidgen()),-)),1,29);\n%let ds2=start%substr(%sysfunc(compress(%sysfunc(uuidgen()),-)),1,27);\n\n/* START */\n%let dttm=%sysfunc(datetime());\n\nfilename &inref &infile lrecl=1 recfm=n;\n\ndata &ds1;\n infile &inref;\n input sourcechar $char1. @@;\n format sourcechar hex2.;\nrun;\n\ndata &ds2;\n /* set find string to length in bytes to cover trailing spaces */\n length string $ %length(%superq(&findvar));\n string =symget(\"&findvar\");\n drop string;\n\n firstchar=char(string,1);\n findlen=lengthm(string); /* <- for trailing bytes */\n\n do _N_=1 to nobs;\n set &ds1 nobs=nobs point=_N_;\n if sourcechar=firstchar then do;\n pos=1;\n s=0;\n do point=_N_ to min(_N_ + findlen -1,nobs);\n set &ds1 point=point;\n if sourcechar=char(string, pos) then s + 1;\n else goto _leave_;\n pos+1;\n end;\n _leave_:\n if s=findlen then do;\n START =_N_;\n _N_ =_N_+ s - 1;\n STOP =_N_;\n output;\n end;\n end;\n end;\n stop;\n keep START STOP;\nrun;\n\ndata &ds1;\n declare hash HS(dataset:\"&ds2(keep=start)\");\n HS.defineKey(\"start\");\n HS.defineDone();\n declare hash HE(dataset:\"&ds2(keep=stop)\");\n HE.defineKey(\"stop\");\n HE.defineDone();\n do until(eof);\n set &ds1 end=eof curobs =n;\n start = ^HS.check(key:n);\n stop = ^HE.check(key:n);\n length strt $ 1;\n strt =put(start,best. -L);\n retain out 1;\n if out then output;\n if start then out=0;\n if stop then out=1;\n end;\n stop;\n keep sourcechar strt;\nrun;\n\nfilename &outref &outfile recfm=n;\n\ndata _null_;\n length replace $ %length(%superq(&replacevar));\n replace=symget(\"&replacevar\");\n file &outref;\n do until(eof);\n set &ds1 end=eof;\n if strt =\"1\" then put replace char.;\n else put sourcechar char1.;\n end;\n stop;\nrun;\n\n/* END */\n%put &sysmacroname took %sysevalf(%sysfunc(datetime())-&dttm) seconds to run;\n\n%mend mp_replace;\n\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n\n%if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n%end;\n%else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n%end;\n%else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n%end;\n%else %if &type=SVG or &type=SVG64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/svg+xml));\n%end;\n%else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n%end;\n%else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n%end;\n%else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n%end;\n%else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n%end;\n%else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n%end;\n%else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n%end;\n%else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n%end;\n\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjsout temp;\n data _null_;\n file _sjsout lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n put ' serverType: \"SAS9\" ,';\n end;\n else if find(_infile_,' serverUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n /* More recently, SASjs apps avoid inline JS to allow strict CSP */\n length infile in1 in2 $32767;\n infile=cats(_infile_);\n spos1=index(upcase(infile),'APPLOC=\"');\n if spos1>0 then do;\n in1=substr(infile,1,spos1+7);\n in2=subpad(infile,spos1+8);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,appLoc,in2);\n putlog \"new apploc: \" infile=;\n end;\n /* find & replace serverType in HTML attributes */\n spos2=index(upcase(infile),'SERVERTYPE=\"');\n if spos2>0 then do;\n in1=substr(infile,1,spos2+11);\n in2=subpad(infile,spos2+12);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,\"SAS9\",in2);\n putlog \"new servertype: \" infile=;\n end;\n /* find & replace serverUrl in HTML attributes */\n spos3=index(upcase(infile),'SERVERURL=\"');\n if spos3>0 then do;\n in1=substr(infile,1,spos3+10);\n in2=subpad(infile,spos3+11);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,in2);\n putlog \"new serverUrl: \" infile=;\n end;\n if sum(spos1,spos2,spos3)>0 then put infile;\n else do;\n /* during SAS9 sasjs compile, dependencies get static GUID */\n infile=tranwrd(_infile_,'?_PROGRAM=".concat(process.sasjsConstants.sas9GUID, "',cats(expanded_path));\n put infile;\n end;\n end;\n run;\n %let fref=_sjsout;\n%end;\n%else %if &type=JS64 or &type=CSS64 %then %do;\n options nobomfile;\n %let fvar=").concat(process.sasjsConstants.sas9GUID, ";\n %let stgfile=\"%sysfunc(pathname(work))/stgfile.txt\";\n %let newfile=\"%sysfunc(pathname(work))/newfile.txt\";\n\n /* convert from base64 */\n filename _out64 &stgfile encoding='utf-8';\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_out64\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n\n /* get appLoc from _program */\n data _null_;\n pgm=\"&_program\";\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n call symputx('apploc',cats(appLoc,'/services/'));\n run;\n %put &=fvar;\n %put &=apploc;\n /* replace the GUID with appLoc */\n %mp_replace(&stgfile,\n findvar=fvar,\n replacevar=apploc,\n outfile=&newfile\n )\n filename &fref &newfile encoding='utf-8';\n%end;\n\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=WAV or &type=OGG or &type=WOFF or &type=WOFF2 or &type=TTF or &type=MP4\nor &type=SVG64\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char = '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc = fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n %put streaming to _webout;\n data _null_;\n infile &fref lrecl=1 recfm=n;\n file _webout mod lrecl=1 recfm=n;\n input sourcechar $char1. @@;\n format sourcechar hex2.;\n put sourcechar char1. @@;\n run;\n%end;\n%mend sasjsout;"); };
5
+ exports.sasjsout = sasjsout;
@@ -1,13 +1,16 @@
1
1
  import { JSDOM } from 'jsdom';
2
2
  import { ServerType } from '@sasjs/utils';
3
+ import { AssetPathMap } from './createAssetServices';
3
4
  interface paramsType {
4
5
  webSourcePathFull: string;
5
6
  destinationPath: string;
6
7
  serverType: ServerType;
7
- assetPathMap: {
8
- source: string;
9
- target: string;
10
- }[];
8
+ assetPathMap: AssetPathMap[];
11
9
  }
10
+ /**
11
+ * Updates HTML Tags with correct link.
12
+ * Also updates contents to update included asset references
13
+ * @param {JSDOM} parsedHtml- DOMWindow for index.html
14
+ */
12
15
  export declare const updateAllTags: (parsedHtml: JSDOM, { webSourcePathFull, destinationPath, serverType, assetPathMap }: paramsType) => Promise<void>;
13
16
  export {};
@@ -67,6 +67,11 @@ var getTags_1 = require("./getTags");
67
67
  var updateScriptTag_1 = require("./updateScriptTag");
68
68
  var updateLinkTag_1 = require("./updateLinkTag");
69
69
  var updateStyleTag_1 = require("./updateStyleTag");
70
+ /**
71
+ * Updates HTML Tags with correct link.
72
+ * Also updates contents to update included asset references
73
+ * @param {JSDOM} parsedHtml- DOMWindow for index.html
74
+ */
70
75
  var updateAllTags = function (parsedHtml, _a) {
71
76
  var webSourcePathFull = _a.webSourcePathFull, destinationPath = _a.destinationPath, serverType = _a.serverType, assetPathMap = _a.assetPathMap;
72
77
  return __awaiter(void 0, void 0, void 0, function () {
@@ -1,4 +1,2 @@
1
- export declare const updateLinkTag: (linkTag: HTMLLinkElement | HTMLSourceElement | HTMLImageElement, assetPathMap: {
2
- source: string;
3
- target: string;
4
- }[], tagType?: 'link' | 'src') => void;
1
+ import { AssetPathMap } from './createAssetServices';
2
+ export declare const updateLinkTag: (linkTag: HTMLLinkElement | HTMLSourceElement | HTMLImageElement, assetPathMap: AssetPathMap[], tagType?: 'link' | 'src') => void;
@@ -1,5 +1,3 @@
1
1
  import { ServerType } from '@sasjs/utils';
2
- export declare const updateScriptTag: (tag: HTMLScriptElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: {
3
- source: string;
4
- target: string;
5
- }[]) => Promise<void>;
2
+ import { AssetPathMap } from './createAssetServices';
3
+ export declare const updateScriptTag: (tag: HTMLScriptElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: AssetPathMap[]) => Promise<void>;
@@ -43,54 +43,54 @@ exports.updateScriptTag = void 0;
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var utils_1 = require("@sasjs/utils");
45
45
  var js_base64_1 = require("js-base64");
46
- var getWebServiceContent_1 = require("./getWebServiceContent");
46
+ var sas9_1 = require("./sas9");
47
+ var modifyLinksInContent_1 = require("./modifyLinksInContent");
47
48
  var updateScriptTag = function (tag, webSourcePathFull, destinationPath, serverType, assetPathMap) { return __awaiter(void 0, void 0, void 0, function () {
48
- var scriptPath, isUrl, _content, content, serviceContent, _content, content;
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
49
+ var scriptPath, isUrl, _content, content, _a, serviceContent, _content, content;
50
+ return __generator(this, function (_b) {
51
+ switch (_b.label) {
51
52
  case 0:
52
53
  scriptPath = tag.getAttribute('src');
53
- if (!scriptPath) return [3 /*break*/, 8];
54
+ if (!scriptPath) return [3 /*break*/, 10];
54
55
  isUrl = scriptPath.startsWith('http') || scriptPath.startsWith('//');
55
- if (!!isUrl) return [3 /*break*/, 7];
56
+ if (!!isUrl) return [3 /*break*/, 9];
56
57
  return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(webSourcePathFull, scriptPath)).catch(function (_) {
57
58
  throw new Error("Unable to find file: ".concat(scriptPath));
58
59
  })];
59
60
  case 1:
60
- _content = _a.sent();
61
- content = modifyLinksInContent(_content, assetPathMap);
62
- if (!(serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
63
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
64
- case 2:
65
- _a.sent();
66
- return [3 /*break*/, 6];
67
- case 3: return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'JS', serverType)];
68
- case 4:
69
- serviceContent = _a.sent();
70
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.js$/, '-js'), ".sas")), serviceContent)];
61
+ _content = _b.sent();
62
+ content = (0, modifyLinksInContent_1.modifyLinksInContent)(_content, assetPathMap);
63
+ _a = serverType;
64
+ switch (_a) {
65
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
66
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 4];
67
+ }
68
+ return [3 /*break*/, 7];
69
+ case 2: return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
70
+ case 3:
71
+ _b.sent();
72
+ return [3 /*break*/, 8];
73
+ case 4: return [4 /*yield*/, (0, sas9_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'JS')];
71
74
  case 5:
72
- _a.sent();
73
- _a.label = 6;
75
+ serviceContent = _b.sent();
76
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.js$/, '-js'), ".sas")), serviceContent)];
74
77
  case 6:
78
+ _b.sent();
79
+ return [3 /*break*/, 8];
80
+ case 7: throw new Error("Server Type: ".concat(serverType, " is not supported for updating script tag."));
81
+ case 8:
75
82
  tag.setAttribute('src', assetPathMap.find(function (entry) {
76
83
  return entry.source === scriptPath || "./".concat(entry.source) === scriptPath;
77
84
  }).target);
78
- _a.label = 7;
79
- case 7: return [3 /*break*/, 9];
80
- case 8:
85
+ _b.label = 9;
86
+ case 9: return [3 /*break*/, 11];
87
+ case 10:
81
88
  _content = tag.innerHTML;
82
- content = modifyLinksInContent(_content, assetPathMap);
89
+ content = (0, modifyLinksInContent_1.modifyLinksInContent)(_content, assetPathMap);
83
90
  tag.innerHTML = content;
84
- _a.label = 9;
85
- case 9: return [2 /*return*/];
91
+ _b.label = 11;
92
+ case 11: return [2 /*return*/];
86
93
  }
87
94
  });
88
95
  }); };
89
96
  exports.updateScriptTag = updateScriptTag;
90
- var modifyLinksInContent = function (_content, assetPathMap) {
91
- var content = _content;
92
- assetPathMap.forEach(function (pathEntry) {
93
- content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
94
- });
95
- return content;
96
- };
@@ -1,5 +1,3 @@
1
1
  import { ServerType } from '@sasjs/utils';
2
- export declare const updateStyleTag: (tag: HTMLStyleElement | HTMLLinkElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: {
3
- source: string;
4
- target: string;
5
- }[]) => Promise<void>;
2
+ import { AssetPathMap } from './createAssetServices';
3
+ export declare const updateStyleTag: (tag: HTMLStyleElement | HTMLLinkElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: AssetPathMap[]) => Promise<void>;
@@ -43,54 +43,54 @@ exports.updateStyleTag = void 0;
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var utils_1 = require("@sasjs/utils");
45
45
  var js_base64_1 = require("js-base64");
46
- var getWebServiceContent_1 = require("./getWebServiceContent");
46
+ var sas9_1 = require("./sas9");
47
+ var modifyLinksInContent_1 = require("./modifyLinksInContent");
47
48
  var updateStyleTag = function (tag, webSourcePathFull, destinationPath, serverType, assetPathMap) { return __awaiter(void 0, void 0, void 0, function () {
48
- var scriptPath, isUrl, _content, content, serviceContent, _content, content;
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
49
+ var scriptPath, isUrl, _content, content, _a, serviceContent, _content, content;
50
+ return __generator(this, function (_b) {
51
+ switch (_b.label) {
51
52
  case 0:
52
53
  scriptPath = tag.getAttribute('href');
53
- if (!scriptPath) return [3 /*break*/, 8];
54
+ if (!scriptPath) return [3 /*break*/, 10];
54
55
  isUrl = scriptPath.startsWith('http') || scriptPath.startsWith('//');
55
- if (!!isUrl) return [3 /*break*/, 7];
56
+ if (!!isUrl) return [3 /*break*/, 9];
56
57
  return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(webSourcePathFull, scriptPath)).catch(function (_) {
57
58
  throw new Error("Unable to find file: ".concat(scriptPath));
58
59
  })];
59
60
  case 1:
60
- _content = _a.sent();
61
- content = modifyLinksInContent(_content, assetPathMap);
62
- if (!(serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
63
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
64
- case 2:
65
- _a.sent();
66
- return [3 /*break*/, 6];
67
- case 3: return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'CSS', serverType)];
68
- case 4:
69
- serviceContent = _a.sent();
70
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.js$/, '-js'), ".sas")), serviceContent)];
61
+ _content = _b.sent();
62
+ content = (0, modifyLinksInContent_1.modifyLinksInContent)(_content, assetPathMap);
63
+ _a = serverType;
64
+ switch (_a) {
65
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
66
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 4];
67
+ }
68
+ return [3 /*break*/, 7];
69
+ case 2: return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
70
+ case 3:
71
+ _b.sent();
72
+ return [3 /*break*/, 8];
73
+ case 4: return [4 /*yield*/, (0, sas9_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'CSS')];
71
74
  case 5:
72
- _a.sent();
73
- _a.label = 6;
75
+ serviceContent = _b.sent();
76
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.css$/, '-css'), ".sas")), serviceContent)];
74
77
  case 6:
78
+ _b.sent();
79
+ return [3 /*break*/, 8];
80
+ case 7: throw new Error("Server Type: ".concat(serverType, " is not supported for updating style tag."));
81
+ case 8:
75
82
  tag.setAttribute('href', assetPathMap.find(function (entry) {
76
83
  return entry.source === scriptPath || "./".concat(entry.source) === scriptPath;
77
84
  }).target);
78
- _a.label = 7;
79
- case 7: return [3 /*break*/, 9];
80
- case 8:
85
+ _b.label = 9;
86
+ case 9: return [3 /*break*/, 11];
87
+ case 10:
81
88
  _content = tag.innerHTML;
82
- content = modifyLinksInContent(_content, assetPathMap);
89
+ content = (0, modifyLinksInContent_1.modifyLinksInContent)(_content, assetPathMap);
83
90
  tag.innerHTML = content;
84
- _a.label = 9;
85
- case 9: return [2 /*return*/];
91
+ _b.label = 11;
92
+ case 11: return [2 /*return*/];
86
93
  }
87
94
  });
88
95
  }); };
89
96
  exports.updateStyleTag = updateStyleTag;
90
- var modifyLinksInContent = function (_content, assetPathMap) {
91
- var content = _content;
92
- assetPathMap.forEach(function (pathEntry) {
93
- content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
94
- });
95
- return content;
96
- };