@sasjs/cli 4.0.1 → 4.0.3
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.
- package/build/commands/compile/internal/compileTestFile.d.ts +0 -1
- package/build/commands/compile/internal/compileTestFile.js +19 -58
- package/build/commands/compile/internal/spec/compileTestFile.spec.js +0 -58
- package/build/commands/deploy/internal/executeDeployScriptSas9.js +4 -8
- package/build/commands/deploy/internal/executeNonSasScript.js +3 -2
- package/build/commands/deploy/spec/deploy.spec.js +3 -3
- package/build/commands/fs/spec/fsCommand.spec.js +10 -0
- package/build/commands/request/request.js +2 -16
- package/build/utils/file.d.ts +10 -15
- package/build/utils/file.js +11 -78
- package/build/utils/spec/file.spec.js +0 -28
- package/package.json +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TestFlow } from '../../../types';
|
|
2
2
|
import { Target, Configuration, CompileTree } from '@sasjs/utils';
|
|
3
3
|
export declare function compileTestFile(target: Target, filePath: string, testVar: string | undefined, saveToRoot: boolean | undefined, removeOriginalFile: boolean | undefined, compileTree: CompileTree): Promise<void>;
|
|
4
|
-
export declare function moveTestFile(filePath: string): Promise<void>;
|
|
5
4
|
export declare function copyTestMacroFiles(folderAbsolutePath: string): Promise<void>;
|
|
6
5
|
export declare const compileTestFlow: (target: Target, config?: Configuration) => Promise<TestFlow | undefined>;
|
|
@@ -64,7 +64,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
64
64
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
65
|
};
|
|
66
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
-
exports.compileTestFlow = exports.copyTestMacroFiles = exports.
|
|
67
|
+
exports.compileTestFlow = exports.copyTestMacroFiles = exports.compileTestFile = void 0;
|
|
68
68
|
var types_1 = require("../../../types");
|
|
69
69
|
var path_1 = __importDefault(require("path"));
|
|
70
70
|
var utils_1 = require("@sasjs/utils");
|
|
@@ -72,99 +72,59 @@ var loadDependencies_1 = require("./loadDependencies");
|
|
|
72
72
|
var file_1 = require("../../../utils/file");
|
|
73
73
|
var chalk_1 = __importDefault(require("chalk"));
|
|
74
74
|
var config_1 = require("../../../utils/config");
|
|
75
|
-
var testsBuildFolder = function () {
|
|
76
|
-
return path_1.default.join(process.projectDir, 'sasjsbuild', 'tests');
|
|
77
|
-
};
|
|
78
75
|
var getFileName = function (filePath) { return path_1.default.parse(filePath).base; };
|
|
79
76
|
function compileTestFile(target, filePath, testVar, saveToRoot, removeOriginalFile, compileTree) {
|
|
80
77
|
if (testVar === void 0) { testVar = ''; }
|
|
81
78
|
if (saveToRoot === void 0) { saveToRoot = true; }
|
|
82
79
|
if (removeOriginalFile === void 0) { removeOriginalFile = true; }
|
|
83
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var dependencies, _a, _b, destinationPath;
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
81
|
+
var dependencies, _a, _b, _c, buildDestinationFolder, buildDestinationTestFolder, buildDestinationFolderName, destinationPath;
|
|
82
|
+
return __generator(this, function (_d) {
|
|
83
|
+
switch (_d.label) {
|
|
87
84
|
case 0:
|
|
88
85
|
_a = loadDependencies_1.loadDependencies;
|
|
89
86
|
_b = [target,
|
|
90
87
|
(0, utils_1.getAbsolutePath)(filePath, process.projectDir)];
|
|
91
88
|
return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
|
|
92
89
|
case 1:
|
|
93
|
-
_b = _b.concat([
|
|
90
|
+
_b = _b.concat([_d.sent()]);
|
|
94
91
|
return [4 /*yield*/, (0, config_1.getProgramFolders)(target)];
|
|
95
|
-
case 2: return [4 /*yield*/, _a.apply(void 0, _b.concat([
|
|
92
|
+
case 2: return [4 /*yield*/, _a.apply(void 0, _b.concat([_d.sent(), utils_1.SASJsFileType.test,
|
|
96
93
|
compileTree]))];
|
|
97
94
|
case 3:
|
|
98
|
-
dependencies =
|
|
95
|
+
dependencies = _d.sent();
|
|
99
96
|
dependencies = "".concat(testVar ? testVar + '\n' : '', "\n").concat(dependencies);
|
|
100
|
-
|
|
97
|
+
_c = process.sasjsConstants, buildDestinationFolder = _c.buildDestinationFolder, buildDestinationTestFolder = _c.buildDestinationTestFolder;
|
|
98
|
+
buildDestinationFolderName = buildDestinationFolder
|
|
99
|
+
.split(path_1.default.sep)
|
|
100
|
+
.pop();
|
|
101
|
+
destinationPath = path_1.default.join(buildDestinationTestFolder, saveToRoot
|
|
101
102
|
? filePath.split(path_1.default.sep).pop() || ''
|
|
102
103
|
: filePath
|
|
103
104
|
.split(path_1.default.sep)
|
|
104
105
|
.reduce(function (acc, item, i, arr) {
|
|
105
106
|
return acc.length
|
|
106
|
-
? __spreadArray(__spreadArray([], __read(acc), false), [item], false) : arr[i - 1] ===
|
|
107
|
+
? __spreadArray(__spreadArray([], __read(acc), false), [item], false) : arr[i - 1] === buildDestinationFolderName
|
|
107
108
|
? __spreadArray(__spreadArray([], __read(acc), false), [item], false) : acc;
|
|
108
109
|
}, [])
|
|
109
110
|
.join(path_1.default.sep));
|
|
110
111
|
return [4 /*yield*/, (0, utils_1.createFile)(destinationPath, dependencies)];
|
|
111
112
|
case 4:
|
|
112
|
-
|
|
113
|
+
_d.sent();
|
|
113
114
|
if (!removeOriginalFile) return [3 /*break*/, 6];
|
|
114
115
|
return [4 /*yield*/, (0, utils_1.deleteFile)(filePath)];
|
|
115
116
|
case 5:
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
_d.sent();
|
|
118
|
+
_d.label = 6;
|
|
118
119
|
case 6: return [2 /*return*/];
|
|
119
120
|
}
|
|
120
121
|
});
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
exports.compileTestFile = compileTestFile;
|
|
124
|
-
function moveTestFile(filePath) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
-
var fileName, destinationPath, testDestinationFolder, sourceFolder;
|
|
127
|
-
return __generator(this, function (_a) {
|
|
128
|
-
switch (_a.label) {
|
|
129
|
-
case 0:
|
|
130
|
-
fileName = filePath.split(path_1.default.sep).pop();
|
|
131
|
-
if (!(0, utils_1.isTestFile)(fileName))
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
destinationPath = filePath.replace('sasjsbuild', 'sasjsbuild/tests');
|
|
134
|
-
testDestinationFolder = destinationPath
|
|
135
|
-
.split(path_1.default.sep)
|
|
136
|
-
.slice(0, -1)
|
|
137
|
-
.join(path_1.default.sep);
|
|
138
|
-
return [4 /*yield*/, (0, utils_1.folderExists)(testDestinationFolder)];
|
|
139
|
-
case 1:
|
|
140
|
-
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
141
|
-
return [4 /*yield*/, (0, utils_1.createFolder)(testDestinationFolder)];
|
|
142
|
-
case 2:
|
|
143
|
-
_a.sent();
|
|
144
|
-
_a.label = 3;
|
|
145
|
-
case 3: return [4 /*yield*/, (0, utils_1.moveFile)(filePath, destinationPath)];
|
|
146
|
-
case 4:
|
|
147
|
-
_a.sent();
|
|
148
|
-
sourceFolder = filePath
|
|
149
|
-
.split(path_1.default.sep)
|
|
150
|
-
.slice(0, filePath.split(path_1.default.sep).length - 1)
|
|
151
|
-
.join(path_1.default.sep);
|
|
152
|
-
return [4 /*yield*/, (0, utils_1.listFilesInFolder)(sourceFolder)];
|
|
153
|
-
case 5:
|
|
154
|
-
if (!((_a.sent()).length === 0)) return [3 /*break*/, 7];
|
|
155
|
-
return [4 /*yield*/, (0, utils_1.deleteFolder)(sourceFolder)];
|
|
156
|
-
case 6:
|
|
157
|
-
_a.sent();
|
|
158
|
-
_a.label = 7;
|
|
159
|
-
case 7: return [2 /*return*/];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
exports.moveTestFile = moveTestFile;
|
|
165
125
|
function copyTestMacroFiles(folderAbsolutePath) {
|
|
166
126
|
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
-
var macroFiles, macroTestFiles;
|
|
127
|
+
var macroFiles, macroTestFiles, buildDestinationTestFolder;
|
|
168
128
|
var _this = this;
|
|
169
129
|
return __generator(this, function (_a) {
|
|
170
130
|
switch (_a.label) {
|
|
@@ -172,12 +132,13 @@ function copyTestMacroFiles(folderAbsolutePath) {
|
|
|
172
132
|
case 1:
|
|
173
133
|
macroFiles = _a.sent();
|
|
174
134
|
macroTestFiles = macroFiles.filter(function (item) { return utils_1.testFileRegExp.test(item); });
|
|
135
|
+
buildDestinationTestFolder = process.sasjsConstants.buildDestinationTestFolder;
|
|
175
136
|
return [4 /*yield*/, (0, utils_1.asyncForEach)(macroTestFiles, function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
176
137
|
var destinationFile;
|
|
177
138
|
return __generator(this, function (_a) {
|
|
178
139
|
switch (_a.label) {
|
|
179
140
|
case 0:
|
|
180
|
-
destinationFile = path_1.default.join(
|
|
141
|
+
destinationFile = path_1.default.join(buildDestinationTestFolder, 'macros', file);
|
|
181
142
|
return [4 /*yield*/, (0, utils_1.fileExists)(destinationFile)];
|
|
182
143
|
case 1:
|
|
183
144
|
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
@@ -160,64 +160,6 @@ describe('compileTestFile', function () {
|
|
|
160
160
|
});
|
|
161
161
|
}); });
|
|
162
162
|
});
|
|
163
|
-
describe('moveTestFile', function () {
|
|
164
|
-
it('should move service test', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
165
|
-
var relativePath, buildPath, originalFilePath, destinationFilePath;
|
|
166
|
-
return __generator(this, function (_a) {
|
|
167
|
-
switch (_a.label) {
|
|
168
|
-
case 0:
|
|
169
|
-
relativePath = path_1.default.join('services', 'services', 'admin', testFileName);
|
|
170
|
-
buildPath = path_1.default.join(__dirname, appName, 'sasjsbuild');
|
|
171
|
-
originalFilePath = path_1.default.join(buildPath, relativePath);
|
|
172
|
-
destinationFilePath = path_1.default.join(buildPath, 'tests', relativePath);
|
|
173
|
-
return [4 /*yield*/, (0, utils_1.createFile)(originalFilePath, testBody)];
|
|
174
|
-
case 1:
|
|
175
|
-
_a.sent();
|
|
176
|
-
return [4 /*yield*/, (0, compileTestFile_1.moveTestFile)(originalFilePath)];
|
|
177
|
-
case 2:
|
|
178
|
-
_a.sent();
|
|
179
|
-
return [4 /*yield*/, expect((0, utils_1.fileExists)(originalFilePath)).resolves.toEqual(false)];
|
|
180
|
-
case 3:
|
|
181
|
-
_a.sent();
|
|
182
|
-
return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationFilePath)).resolves.toEqual(true)];
|
|
183
|
-
case 4:
|
|
184
|
-
_a.sent();
|
|
185
|
-
return [4 /*yield*/, expect((0, utils_1.readFile)(destinationFilePath)).resolves.toEqual(testBody)];
|
|
186
|
-
case 5:
|
|
187
|
-
_a.sent();
|
|
188
|
-
return [2 /*return*/];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}); });
|
|
192
|
-
it('should move job test', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
-
var relativePath, buildPath, originalFilePath, destinationFilePath;
|
|
194
|
-
return __generator(this, function (_a) {
|
|
195
|
-
switch (_a.label) {
|
|
196
|
-
case 0:
|
|
197
|
-
relativePath = path_1.default.join('jobs', 'jobs', testFileName);
|
|
198
|
-
buildPath = path_1.default.join(__dirname, appName, 'sasjsbuild');
|
|
199
|
-
originalFilePath = path_1.default.join(buildPath, relativePath);
|
|
200
|
-
destinationFilePath = path_1.default.join(buildPath, 'tests', relativePath);
|
|
201
|
-
return [4 /*yield*/, (0, utils_1.createFile)(originalFilePath, testBody)];
|
|
202
|
-
case 1:
|
|
203
|
-
_a.sent();
|
|
204
|
-
return [4 /*yield*/, (0, compileTestFile_1.moveTestFile)(originalFilePath)];
|
|
205
|
-
case 2:
|
|
206
|
-
_a.sent();
|
|
207
|
-
return [4 /*yield*/, expect((0, utils_1.fileExists)(originalFilePath)).resolves.toEqual(false)];
|
|
208
|
-
case 3:
|
|
209
|
-
_a.sent();
|
|
210
|
-
return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationFilePath)).resolves.toEqual(true)];
|
|
211
|
-
case 4:
|
|
212
|
-
_a.sent();
|
|
213
|
-
return [4 /*yield*/, expect((0, utils_1.readFile)(destinationFilePath)).resolves.toEqual(testBody)];
|
|
214
|
-
case 5:
|
|
215
|
-
_a.sent();
|
|
216
|
-
return [2 /*return*/];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}); });
|
|
220
|
-
});
|
|
221
163
|
describe('compileTestFlow', function () {
|
|
222
164
|
it('should compile test flow', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
165
|
var testSetUp, testTearDown, testFlowPath, expectedTestFlow, _a, _b, _c;
|
|
@@ -38,8 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.executeDeployScriptSas9 = void 0;
|
|
40
40
|
var config_1 = require("../../../utils/config");
|
|
41
|
-
var utils_1 = require("
|
|
42
|
-
var utils_2 = require("@sasjs/utils");
|
|
41
|
+
var utils_1 = require("@sasjs/utils");
|
|
43
42
|
var _1 = require("./");
|
|
44
43
|
/**
|
|
45
44
|
* Execute deployScript on `SAS9` server.
|
|
@@ -61,7 +60,7 @@ function executeDeployScriptSas9(deployScriptName, target, linesToExecute, logFi
|
|
|
61
60
|
case 1:
|
|
62
61
|
_e = _f.sent(), sasjs = _e.sasjs, authConfigSas9 = _e.authConfigSas9;
|
|
63
62
|
userName = authConfigSas9.userName;
|
|
64
|
-
password = (0,
|
|
63
|
+
password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
|
|
65
64
|
completedWithError = false;
|
|
66
65
|
return [4 /*yield*/, sasjs
|
|
67
66
|
.executeScript({
|
|
@@ -70,10 +69,7 @@ function executeDeployScriptSas9(deployScriptName, target, linesToExecute, logFi
|
|
|
70
69
|
})
|
|
71
70
|
.catch(function (err) {
|
|
72
71
|
var _a;
|
|
73
|
-
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.
|
|
74
|
-
if (err && err.errorCode === 404) {
|
|
75
|
-
(0, utils_1.displaySasjsRunnerError)(userName);
|
|
76
|
-
}
|
|
72
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error((0, _1.formatErrorString)(err));
|
|
77
73
|
completedWithError = true;
|
|
78
74
|
return err;
|
|
79
75
|
})];
|
|
@@ -85,7 +81,7 @@ function executeDeployScriptSas9(deployScriptName, target, linesToExecute, logFi
|
|
|
85
81
|
logContent = completedWithError
|
|
86
82
|
? executionResult.result
|
|
87
83
|
: executionResult;
|
|
88
|
-
return [4 /*yield*/, (0,
|
|
84
|
+
return [4 /*yield*/, (0, utils_1.createFile)(logFilePath, logContent !== null && logContent !== void 0 ? logContent : '')];
|
|
89
85
|
case 3:
|
|
90
86
|
_f.sent();
|
|
91
87
|
if (completedWithError) {
|
|
@@ -46,12 +46,13 @@ var file_1 = require("../../../utils/file");
|
|
|
46
46
|
function executeNonSasScript(scriptPath) {
|
|
47
47
|
var _a, _b, _c, _d, _e;
|
|
48
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
-
var fileExtension, logPath;
|
|
49
|
+
var fileExtension, buildDestinationResultsLogsFolder, logPath;
|
|
50
50
|
return __generator(this, function (_f) {
|
|
51
51
|
switch (_f.label) {
|
|
52
52
|
case 0:
|
|
53
53
|
fileExtension = path_1.default.extname(scriptPath);
|
|
54
|
-
|
|
54
|
+
buildDestinationResultsLogsFolder = process.sasjsConstants.buildDestinationResultsLogsFolder;
|
|
55
|
+
logPath = path_1.default.join(buildDestinationResultsLogsFolder, path_1.default.basename(scriptPath).replace(fileExtension, '.log'));
|
|
55
56
|
if (!(0, file_1.isShellScript)(scriptPath)) return [3 /*break*/, 2];
|
|
56
57
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Executing shell script ".concat(scriptPath, " ..."));
|
|
57
58
|
return [4 /*yield*/, (0, utils_1.executeShellScript)(scriptPath, logPath)];
|
|
@@ -233,7 +233,7 @@ describe('deploy', function () {
|
|
|
233
233
|
case 1:
|
|
234
234
|
_a.sent();
|
|
235
235
|
expect(process.logger.info).toHaveBeenCalledWith("Executing shell script ".concat(path_1.default.join(process.projectDir, "script.sh"), " ..."));
|
|
236
|
-
expect(process.logger.success).toHaveBeenCalledWith("Shell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.
|
|
236
|
+
expect(process.logger.success).toHaveBeenCalledWith("Shell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.buildDestinationResultsLogsFolder, 'script.log')));
|
|
237
237
|
return [2 /*return*/];
|
|
238
238
|
}
|
|
239
239
|
});
|
|
@@ -253,7 +253,7 @@ describe('deploy', function () {
|
|
|
253
253
|
case 1:
|
|
254
254
|
_a.sent();
|
|
255
255
|
expect(process.logger.info).toHaveBeenCalledWith("Executing shell script ".concat(path_1.default.join(process.projectDir, "script.bat"), " ..."));
|
|
256
|
-
expect(process.logger.success).toHaveBeenCalledWith("Shell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.
|
|
256
|
+
expect(process.logger.success).toHaveBeenCalledWith("Shell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.buildDestinationResultsLogsFolder, 'script.log')));
|
|
257
257
|
return [2 /*return*/];
|
|
258
258
|
}
|
|
259
259
|
});
|
|
@@ -273,7 +273,7 @@ describe('deploy', function () {
|
|
|
273
273
|
case 1:
|
|
274
274
|
_a.sent();
|
|
275
275
|
expect(process.logger.info).toHaveBeenCalledWith("Executing powershell script ".concat(path_1.default.join(process.projectDir, "script.ps1"), " ..."));
|
|
276
|
-
expect(process.logger.success).toHaveBeenCalledWith("PowerShell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.
|
|
276
|
+
expect(process.logger.success).toHaveBeenCalledWith("PowerShell script execution completed! Log is here: ".concat(path_1.default.join(process.sasjsConstants.buildDestinationResultsLogsFolder, 'script.log')));
|
|
277
277
|
return [2 /*return*/];
|
|
278
278
|
}
|
|
279
279
|
});
|
|
@@ -126,6 +126,11 @@ describe('FSCommand', function () {
|
|
|
126
126
|
jest
|
|
127
127
|
.spyOn(FileModule, 'createFile')
|
|
128
128
|
.mockImplementation(function () { return Promise.resolve(); });
|
|
129
|
+
jest
|
|
130
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
131
|
+
.mockImplementation(function () {
|
|
132
|
+
return Promise.resolve({ target: target, isLocal: true });
|
|
133
|
+
});
|
|
129
134
|
return [4 /*yield*/, executeCommandWrapper([
|
|
130
135
|
'compile',
|
|
131
136
|
'localFolder',
|
|
@@ -147,6 +152,11 @@ describe('FSCommand', function () {
|
|
|
147
152
|
jest
|
|
148
153
|
.spyOn(FileModule, 'createFile')
|
|
149
154
|
.mockImplementation(function () { return Promise.reject(); });
|
|
155
|
+
jest
|
|
156
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
157
|
+
.mockImplementation(function () {
|
|
158
|
+
return Promise.resolve({ target: target, isLocal: true });
|
|
159
|
+
});
|
|
150
160
|
return [4 /*yield*/, executeCommandWrapper(['compile', 'localFolder'])];
|
|
151
161
|
case 1:
|
|
152
162
|
returnCode = _a.sent();
|
|
@@ -160,26 +160,12 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
|
|
|
160
160
|
});
|
|
161
161
|
}); })
|
|
162
162
|
.catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
163
|
-
var error;
|
|
164
163
|
return __generator(this, function (_a) {
|
|
165
164
|
switch (_a.label) {
|
|
166
|
-
case 0:
|
|
167
|
-
if (err && err.errorCode === 404) {
|
|
168
|
-
(0, utils_2.displaySasjsRunnerError)(configJson.username);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
error = {};
|
|
172
|
-
if (err.message)
|
|
173
|
-
error.message = err.message;
|
|
174
|
-
if (err.error.message)
|
|
175
|
-
error.message = err.error.message;
|
|
176
|
-
(0, displayResult_1.displayError)(error, "An error occurred while executing the request.");
|
|
177
|
-
}
|
|
178
|
-
return [4 /*yield*/, saveLogFile(sasjs, sasJobLocation, logFile, jobPath)];
|
|
165
|
+
case 0: return [4 /*yield*/, saveLogFile(sasjs, sasJobLocation, logFile, jobPath)];
|
|
179
166
|
case 1:
|
|
180
167
|
_a.sent();
|
|
181
|
-
|
|
182
|
-
return [2 /*return*/];
|
|
168
|
+
throw err;
|
|
183
169
|
}
|
|
184
170
|
});
|
|
185
171
|
}); })];
|
package/build/utils/file.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export function
|
|
3
|
-
export function isSasFile(filePath:
|
|
4
|
-
export function isJsonFile(filePath:
|
|
5
|
-
export function isCsvFile(filePath:
|
|
6
|
-
export function isShellScript(filePath:
|
|
7
|
-
export function isPowerShellScript(filePath:
|
|
8
|
-
export
|
|
9
|
-
export function
|
|
10
|
-
export
|
|
11
|
-
absolutePath: string;
|
|
12
|
-
relativePath: string;
|
|
13
|
-
}>;
|
|
14
|
-
export function sanitizeFileName(fileName: any): any;
|
|
15
|
-
export const sasFileRegExp: RegExp;
|
|
1
|
+
import { Folder } from '../types';
|
|
2
|
+
export declare function createFolderStructure(folder: Folder, parentFolderName?: string): Promise<void>;
|
|
3
|
+
export declare function isSasFile(filePath: string): boolean;
|
|
4
|
+
export declare function isJsonFile(filePath: string): boolean;
|
|
5
|
+
export declare function isCsvFile(filePath: string): boolean;
|
|
6
|
+
export declare function isShellScript(filePath: string): boolean;
|
|
7
|
+
export declare function isPowerShellScript(filePath: string): boolean;
|
|
8
|
+
export declare const sanitizeFileName: (fileName: string) => string;
|
|
9
|
+
export declare function getBrief(fileContent: string): string | undefined;
|
|
10
|
+
export declare const sasFileRegExp: RegExp;
|
package/build/utils/file.js
CHANGED
|
@@ -39,10 +39,11 @@ 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
|
-
exports.sasFileRegExp = exports.
|
|
42
|
+
exports.sasFileRegExp = exports.getBrief = exports.sanitizeFileName = exports.isPowerShellScript = exports.isShellScript = exports.isCsvFile = exports.isJsonFile = exports.isSasFile = exports.createFolderStructure = void 0;
|
|
43
43
|
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
44
45
|
var utils_1 = require("@sasjs/utils");
|
|
45
|
-
var
|
|
46
|
+
var displayResult_1 = require("./displayResult");
|
|
46
47
|
function createFolderStructure(folder, parentFolderName) {
|
|
47
48
|
if (parentFolderName === void 0) { parentFolderName = '.'; }
|
|
48
49
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -65,7 +66,7 @@ function createFolderStructure(folder, parentFolderName) {
|
|
|
65
66
|
switch (_a.label) {
|
|
66
67
|
case 0:
|
|
67
68
|
filePath = path_1.default.join(process.projectDir, parentFolderName, "".concat(folder.folderName, "/").concat(file.fileName));
|
|
68
|
-
return [4 /*yield*/, (0, utils_1.createFile)(filePath, file.content).catch(function () {
|
|
69
|
+
return [4 /*yield*/, (0, utils_1.createFile)(filePath, file.content || '').catch(function () {
|
|
69
70
|
var _a;
|
|
70
71
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error creating file: ', filePath);
|
|
71
72
|
})];
|
|
@@ -96,19 +97,6 @@ function createFolderStructure(folder, parentFolderName) {
|
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
exports.createFolderStructure = createFolderStructure;
|
|
99
|
-
function unifyFilePath(filePath, separator, replace) {
|
|
100
|
-
if (separator === void 0) { separator = path_1.default.sep; }
|
|
101
|
-
if (replace === void 0) { replace = '/'; }
|
|
102
|
-
var separators = { unix: '/', win: '\\' };
|
|
103
|
-
var osSeparator = Object.keys(separators).find(function (key) { return separators[key] === separator; });
|
|
104
|
-
if (osSeparator) {
|
|
105
|
-
var notValidSeparator = separators[Object.keys(separators).find(function (key) { return key !== osSeparator; })];
|
|
106
|
-
osSeparator = separators[osSeparator];
|
|
107
|
-
return filePath.split(notValidSeparator).join(osSeparator);
|
|
108
|
-
}
|
|
109
|
-
return filePath.split(replace).join(separator);
|
|
110
|
-
}
|
|
111
|
-
exports.unifyFilePath = unifyFilePath;
|
|
112
100
|
function isSasFile(filePath) {
|
|
113
101
|
return path_1.default.extname(filePath) === '.sas';
|
|
114
102
|
}
|
|
@@ -134,74 +122,19 @@ var sanitizeFileName = function (fileName) {
|
|
|
134
122
|
};
|
|
135
123
|
exports.sanitizeFileName = sanitizeFileName;
|
|
136
124
|
function getBrief(fileContent) {
|
|
137
|
-
var fileHeader;
|
|
138
125
|
try {
|
|
139
126
|
var hasFileHeader = fileContent.split('/**')[0] !== fileContent;
|
|
140
127
|
if (!hasFileHeader)
|
|
141
|
-
return
|
|
142
|
-
fileHeader = fileContent.split('/**')[1].split('**/')[0];
|
|
128
|
+
return;
|
|
129
|
+
var fileHeader = fileContent.split('/**')[1].split('**/')[0];
|
|
130
|
+
var lines = fileHeader.split('\n').map(function (s) { return (s ? s.trim() : s); });
|
|
131
|
+
var brief = lines.find(function (l) { return l.startsWith('@brief'); });
|
|
132
|
+
if (brief)
|
|
133
|
+
return brief.replace(/\@brief/g, '').trim();
|
|
143
134
|
}
|
|
144
135
|
catch (e) {
|
|
145
|
-
|
|
136
|
+
(0, displayResult_1.displayError)(e, chalk_1.default.redBright('File header parse error.\nPlease make sure your file header is in the correct format.'));
|
|
146
137
|
}
|
|
147
|
-
var lines = fileHeader.split('\n').map(function (s) { return (s ? s.trim() : s); });
|
|
148
|
-
var brief = lines.find(function (l) { return l.startsWith('@brief'); });
|
|
149
|
-
if (brief)
|
|
150
|
-
brief = brief.replace(/\@brief/g, '').trim();
|
|
151
|
-
return brief;
|
|
152
138
|
}
|
|
153
139
|
exports.getBrief = getBrief;
|
|
154
|
-
function getRelativePath(from, to) {
|
|
155
|
-
var fromFolders = from.split(path_1.default.sep);
|
|
156
|
-
var toFolders = to.split(path_1.default.sep);
|
|
157
|
-
var similarPath = [];
|
|
158
|
-
var relativePath = [];
|
|
159
|
-
fromFolders.forEach(function (fromFolder, i) {
|
|
160
|
-
if (toFolders[i] !== undefined && fromFolders[i] === toFolders[i]) {
|
|
161
|
-
similarPath.push(fromFolder);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
if (fromFolder)
|
|
165
|
-
relativePath.push(fromFolder);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
similarPath = similarPath.join(path_1.default.sep);
|
|
169
|
-
var leadingPathSepRegExp = new RegExp("^".concat(path_1.default.sep.replace(/\\/g, '\\\\')));
|
|
170
|
-
var trailingPathSepRegExp = new RegExp("".concat(path_1.default.sep.replace(/\\/g, '\\\\'), "$"));
|
|
171
|
-
relativePath =
|
|
172
|
-
(!path_1.default.sep.match(/\\/)
|
|
173
|
-
? relativePath.length
|
|
174
|
-
? "..".concat(path_1.default.sep).repeat(relativePath.length)
|
|
175
|
-
: ".".concat(path_1.default.sep)
|
|
176
|
-
: '') +
|
|
177
|
-
to
|
|
178
|
-
.replace(similarPath, '')
|
|
179
|
-
.replace(leadingPathSepRegExp, '')
|
|
180
|
-
.replace(trailingPathSepRegExp, '');
|
|
181
|
-
return relativePath;
|
|
182
|
-
}
|
|
183
|
-
exports.getRelativePath = getRelativePath;
|
|
184
|
-
function saveToDefaultLocation(filePath, data) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
-
var root, destination, relativePath;
|
|
187
|
-
return __generator(this, function (_a) {
|
|
188
|
-
switch (_a.label) {
|
|
189
|
-
case 0: return [4 /*yield*/, (0, config_1.getProjectRoot)()];
|
|
190
|
-
case 1:
|
|
191
|
-
root = _a.sent();
|
|
192
|
-
destination = path_1.default.join(root, 'sasjsbuild', filePath);
|
|
193
|
-
getRelativePath(process.cwd(), destination);
|
|
194
|
-
relativePath = getRelativePath(process.cwd(), destination);
|
|
195
|
-
return [4 /*yield*/, (0, utils_1.createFile)(destination, data)];
|
|
196
|
-
case 2:
|
|
197
|
-
_a.sent();
|
|
198
|
-
return [2 /*return*/, Promise.resolve({
|
|
199
|
-
absolutePath: destination,
|
|
200
|
-
relativePath: "".concat(relativePath)
|
|
201
|
-
})];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
exports.saveToDefaultLocation = saveToDefaultLocation;
|
|
207
140
|
exports.sasFileRegExp = /.sas$/i;
|
|
@@ -87,32 +87,4 @@ describe('file utility', function () {
|
|
|
87
87
|
});
|
|
88
88
|
}); });
|
|
89
89
|
});
|
|
90
|
-
describe('unifyFilePath', function () {
|
|
91
|
-
it('should unify file path in Unix-like systems', function () {
|
|
92
|
-
var filePath = '/folder/subFolder/file.txt';
|
|
93
|
-
expect((0, utils_1.unifyFilePath)(filePath, '/')).toEqual(filePath);
|
|
94
|
-
});
|
|
95
|
-
it('should unify file path in Windows system', function () {
|
|
96
|
-
var filePath = '/folder/subFolder/file.txt';
|
|
97
|
-
var expectedFilePath = filePath.replace(/\//g, '\\');
|
|
98
|
-
expect((0, utils_1.unifyFilePath)(filePath, '\\')).toEqual(expectedFilePath);
|
|
99
|
-
});
|
|
100
|
-
it('should unify file path with mixed separators', function () {
|
|
101
|
-
var filePath = '/folder/subFolder\\file.txt';
|
|
102
|
-
var unixSeparator = '/';
|
|
103
|
-
var winSeparator = '\\';
|
|
104
|
-
var expectedUnixPath = filePath.replace(/\\/g, unixSeparator);
|
|
105
|
-
var expectedWinPath = filePath.replace(/\//g, winSeparator);
|
|
106
|
-
expect((0, utils_1.unifyFilePath)(filePath, unixSeparator)).toEqual(expectedUnixPath);
|
|
107
|
-
expect((0, utils_1.unifyFilePath)(filePath, winSeparator)).toEqual(expectedWinPath);
|
|
108
|
-
});
|
|
109
|
-
it('should return file path with custom separator', function () {
|
|
110
|
-
var filePath = '/folder/subFolder/file.txt';
|
|
111
|
-
var expectedFilePath = filePath.replace(/\//g, '$');
|
|
112
|
-
expect((0, utils_1.unifyFilePath)(filePath, '$')).toEqual(expectedFilePath);
|
|
113
|
-
filePath = '\\folder\\subFolder\\file.txt';
|
|
114
|
-
expectedFilePath = filePath.replace(/\\/g, '$');
|
|
115
|
-
expect((0, utils_1.unifyFilePath)(filePath, '$', '\\')).toEqual(expectedFilePath);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
90
|
});
|
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@sasjs/adapter": "4.1.
|
|
53
|
+
"@sasjs/adapter": "4.1.6",
|
|
54
54
|
"@sasjs/core": "4.45.4",
|
|
55
55
|
"@sasjs/lint": "2.2.2",
|
|
56
56
|
"@sasjs/utils": "3.1.0",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"typescript": "4.9.5",
|
|
103
103
|
"util": "0.12.4"
|
|
104
104
|
},
|
|
105
|
-
"version": "4.0.
|
|
105
|
+
"version": "4.0.3"
|
|
106
106
|
}
|