@sasjs/cli 6.4.7 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,7 @@
16
16
 
17
17
  - Scaffold a new SAS App in seconds (`sasjs create myApp -t jobs`)
18
18
  - Compile / Build SAS Jobs, Services & Macros _locally_ and deploy / execute _remotely_, in isolation from other developers (`sasjs cbd`)
19
+ - Build and deploy without recompiling - for when the services on disk are already the ones you want to ship (`sasjs bd`)
19
20
  - Compile a single Job, Service or Test without touching the rest of the build (`sasjs compile identify --source sasjs/jobs/daily/load.sas`)
20
21
  - Write the test coverage report to `sasjsbuild/coverage.json` on every compile, ready for a CI job to publish
21
22
  - No dependency on the server filesystem
@@ -0,0 +1,6 @@
1
+ import { ReturnCode } from '../../types/command';
2
+ import { TargetCommand } from '../../types/command/targetCommand';
3
+ export declare class BuildDeployCommand extends TargetCommand {
4
+ constructor(args: string[]);
5
+ execute(): Promise<ReturnCode>;
6
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.BuildDeployCommand = void 0;
55
+ var command_1 = require("../../types/command");
56
+ var targetCommand_1 = require("../../types/command/targetCommand");
57
+ var utils_1 = require("../../utils");
58
+ var build_1 = require("./build");
59
+ var deploy_1 = require("../deploy/deploy");
60
+ var syntax = 'builddeploy';
61
+ var aliases = ['bd'];
62
+ var usage = 'sasjs builddeploy [options]';
63
+ var description = 'Builds the project and deploys the result to the server configured in the specified target. Unlike compilebuilddeploy it does not recompile first: it ships the compiled services already in the build folder, and the compile step only runs when that folder is missing.';
64
+ var examples = [
65
+ {
66
+ command: 'sasjs builddeploy -t myTarget',
67
+ description: ''
68
+ },
69
+ {
70
+ command: 'sasjs bd -t myTarget',
71
+ description: ''
72
+ }
73
+ ];
74
+ var BuildDeployCommand = /** @class */ (function (_super) {
75
+ __extends(BuildDeployCommand, _super);
76
+ function BuildDeployCommand(args) {
77
+ return _super.call(this, args, { syntax: syntax, usage: usage, aliases: aliases, description: description, examples: examples }) || this;
78
+ }
79
+ BuildDeployCommand.prototype.execute = function () {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var _a, target, isLocal, buildReturnCode;
82
+ return __generator(this, function (_b) {
83
+ switch (_b.label) {
84
+ case 0: return [4 /*yield*/, this.getTargetInfo()];
85
+ case 1:
86
+ _a = _b.sent(), target = _a.target, isLocal = _a.isLocal;
87
+ return [4 /*yield*/, (0, build_1.build)(target)
88
+ .then(function () {
89
+ var _a;
90
+ var buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
91
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully built!\nThe build output is located in the ".concat(buildDestinationFolder, " directory."));
92
+ return command_1.ReturnCode.Success;
93
+ })
94
+ .catch(function (err) {
95
+ (0, utils_1.displayError)(err, 'An error has occurred when building services.');
96
+ return command_1.ReturnCode.InternalError;
97
+ })];
98
+ case 2:
99
+ buildReturnCode = _b.sent();
100
+ if (buildReturnCode === command_1.ReturnCode.InternalError)
101
+ return [2 /*return*/, buildReturnCode];
102
+ return [4 /*yield*/, (0, deploy_1.deploy)(target, isLocal)
103
+ .then(function () {
104
+ var _a;
105
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully deployed to ".concat(target.serverUrl, "."));
106
+ return command_1.ReturnCode.Success;
107
+ })
108
+ .catch(function (err) {
109
+ var _a;
110
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred when deploying services: ".concat(err));
111
+ return command_1.ReturnCode.InternalError;
112
+ })];
113
+ case 3: return [2 /*return*/, _b.sent()];
114
+ }
115
+ });
116
+ });
117
+ };
118
+ return BuildDeployCommand;
119
+ }(targetCommand_1.TargetCommand));
120
+ exports.BuildDeployCommand = BuildDeployCommand;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __generator = (this && this.__generator) || function (thisArg, body) {
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
+ function verb(n) { return function (v) { return step([n, v]); }; }
48
+ function step(op) {
49
+ if (f) throw new TypeError("Generator is already executing.");
50
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
+ 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;
52
+ if (y = 0, t) op = [op[0] & 2, t.value];
53
+ switch (op[0]) {
54
+ case 0: case 1: t = op; break;
55
+ case 4: _.label++; return { value: op[1], done: false };
56
+ case 5: _.label++; y = op[1]; op = [0]; continue;
57
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
+ default:
59
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
+ if (t[2]) _.ops.pop();
64
+ _.trys.pop(); continue;
65
+ }
66
+ op = body.call(thisArg, _);
67
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
+ }
70
+ };
71
+ var __read = (this && this.__read) || function (o, n) {
72
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
73
+ if (!m) return o;
74
+ var i = m.call(o), r, ar = [], e;
75
+ try {
76
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
77
+ }
78
+ catch (error) { e = { error: error }; }
79
+ finally {
80
+ try {
81
+ if (r && !r.done && (m = i["return"])) m.call(i);
82
+ }
83
+ finally { if (e) throw e.error; }
84
+ }
85
+ return ar;
86
+ };
87
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
88
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
89
+ if (ar || !(i in from)) {
90
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
91
+ ar[i] = from[i];
92
+ }
93
+ }
94
+ return to.concat(ar || Array.prototype.slice.call(from));
95
+ };
96
+ Object.defineProperty(exports, "__esModule", { value: true });
97
+ var buildModule = __importStar(require("../../build/build"));
98
+ var deployModule = __importStar(require("../../deploy/deploy"));
99
+ var buildDeployCommand_1 = require("../buildDeployCommand");
100
+ var utils_1 = require("@sasjs/utils");
101
+ var configUtils = __importStar(require("../../../utils/config"));
102
+ var setConstantsUtils = __importStar(require("../../../utils/setConstants"));
103
+ var utils_2 = require("../../../utils");
104
+ var command_1 = require("../../../types/command");
105
+ describe('BuildDeployCommand', function () {
106
+ var defaultArgs = ['node', 'sasjs'];
107
+ var target = new utils_1.Target({
108
+ name: 'test',
109
+ appLoc: '/Public/test/',
110
+ serverType: utils_1.ServerType.SasViya,
111
+ contextName: 'test context'
112
+ });
113
+ beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
114
+ return __generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0: return [4 /*yield*/, (0, utils_2.setConstants)(false)];
117
+ case 1:
118
+ _a.sent();
119
+ return [2 /*return*/];
120
+ }
121
+ });
122
+ }); });
123
+ beforeEach(function () {
124
+ jest.resetAllMocks();
125
+ jest.mock('../../build/build');
126
+ jest.mock('../../deploy/deploy');
127
+ jest.mock('../../../utils/config');
128
+ jest.spyOn(buildModule, 'build').mockImplementation(function () { return Promise.resolve(); });
129
+ jest
130
+ .spyOn(deployModule, 'deploy')
131
+ .mockImplementation(function () { return Promise.resolve(); });
132
+ jest
133
+ .spyOn(configUtils, 'findTargetInConfiguration')
134
+ .mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
135
+ jest
136
+ .spyOn(configUtils, 'getLocalConfig')
137
+ .mockImplementation(function () { return Promise.resolve({}); });
138
+ jest
139
+ .spyOn(setConstantsUtils, 'setConstants')
140
+ .mockImplementation(function () { return Promise.resolve(); });
141
+ process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
142
+ jest.spyOn(process.logger, 'success');
143
+ jest.spyOn(process.logger, 'error');
144
+ });
145
+ it('should parse a simple sasjs builddeploy command', function () {
146
+ var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy'], false);
147
+ var command = new buildDeployCommand_1.BuildDeployCommand(args);
148
+ expect(command.name).toEqual('builddeploy');
149
+ expect(command.subCommand).toEqual('');
150
+ });
151
+ it('should parse the bd shorthand', function () {
152
+ var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd'], false);
153
+ var command = new buildDeployCommand_1.BuildDeployCommand(args);
154
+ expect(command.name).toEqual('builddeploy');
155
+ expect(command.subCommand).toEqual('');
156
+ });
157
+ it('should parse a sasjs builddeploy command with a target', function () {
158
+ var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '--target', 'test'], false);
159
+ var command = new buildDeployCommand_1.BuildDeployCommand(args);
160
+ expect(command.name).toEqual('builddeploy');
161
+ expect(command.subCommand).toEqual('');
162
+ });
163
+ it('should build and then deploy against the resolved target', function () { return __awaiter(void 0, void 0, void 0, function () {
164
+ var args, command;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd', '-t', 'test'], false);
169
+ command = new buildDeployCommand_1.BuildDeployCommand(args);
170
+ return [4 /*yield*/, command.execute()];
171
+ case 1:
172
+ _a.sent();
173
+ expect(buildModule.build).toHaveBeenCalledWith(target);
174
+ expect(deployModule.deploy).toHaveBeenCalledWith(target, true);
175
+ return [2 /*return*/];
176
+ }
177
+ });
178
+ }); });
179
+ it('should not deploy when the build fails', function () { return __awaiter(void 0, void 0, void 0, function () {
180
+ var args, command, returnCode;
181
+ return __generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0:
184
+ args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd', '-t', 'test'], false);
185
+ jest
186
+ .spyOn(buildModule, 'build')
187
+ .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
188
+ command = new buildDeployCommand_1.BuildDeployCommand(args);
189
+ return [4 /*yield*/, command.execute()];
190
+ case 1:
191
+ returnCode = _a.sent();
192
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
193
+ expect(deployModule.deploy).not.toHaveBeenCalled();
194
+ expect(process.logger.error).toHaveBeenCalledWith(expect.stringContaining('An error has occurred when building services'), 'Test Error');
195
+ return [2 /*return*/];
196
+ }
197
+ });
198
+ }); });
199
+ it('should return the success code when build and deploy succeed', function () { return __awaiter(void 0, void 0, void 0, function () {
200
+ var args, command, returnCode;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0:
204
+ args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '-t', 'test'], false);
205
+ command = new buildDeployCommand_1.BuildDeployCommand(args);
206
+ return [4 /*yield*/, command.execute()];
207
+ case 1:
208
+ returnCode = _a.sent();
209
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
210
+ expect(process.logger.success).toHaveBeenCalledWith(expect.stringContaining('Services have been successfully deployed'));
211
+ return [2 /*return*/];
212
+ }
213
+ });
214
+ }); });
215
+ it('should log the error and return the error code when deploy is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
216
+ var args, command, returnCode;
217
+ return __generator(this, function (_a) {
218
+ switch (_a.label) {
219
+ case 0:
220
+ args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '-t', 'test'], false);
221
+ jest
222
+ .spyOn(deployModule, 'deploy')
223
+ .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
224
+ command = new buildDeployCommand_1.BuildDeployCommand(args);
225
+ return [4 /*yield*/, command.execute()];
226
+ case 1:
227
+ returnCode = _a.sent();
228
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
229
+ expect(process.logger.error).toHaveBeenCalledWith(expect.stringContaining('An error has occurred when deploying services'));
230
+ return [2 /*return*/];
231
+ }
232
+ });
233
+ }); });
234
+ });
@@ -1,6 +1,6 @@
1
1
  import { ReturnCode } from '../../types/command';
2
- import { CommandBase } from '../../types';
3
- export declare class DbCommand extends CommandBase {
2
+ import { TargetCommand } from '../../types/command/targetCommand';
3
+ export declare class DbCommand extends TargetCommand {
4
4
  constructor(args: string[]);
5
5
  execute(): Promise<ReturnCode>;
6
6
  }
@@ -54,7 +54,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.DbCommand = void 0;
55
55
  var db_1 = require("./db");
56
56
  var command_1 = require("../../types/command");
57
- var types_1 = require("../../types");
57
+ var targetCommand_1 = require("../../types/command/targetCommand");
58
58
  var syntax = 'db';
59
59
  var aliases = ['build-DB', 'build-db'];
60
60
  var usage = 'sasjs db';
@@ -80,22 +80,30 @@ var DbCommand = /** @class */ (function (_super) {
80
80
  return __awaiter(this, void 0, void 0, function () {
81
81
  return __generator(this, function (_a) {
82
82
  switch (_a.label) {
83
- case 0: return [4 /*yield*/, (0, db_1.buildDB)()
84
- .then(function () {
85
- var _a;
86
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('DB build completed!');
87
- return command_1.ReturnCode.Success;
88
- })
89
- .catch(function (err) {
90
- var _a;
91
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error building DB: ', err);
92
- return command_1.ReturnCode.InternalError;
93
- })];
94
- case 1: return [2 /*return*/, _a.sent()];
83
+ case 0:
84
+ // Resolving the target is what sets process.sasjsConstants - buildDB reads
85
+ // the source and destination db folders from there.
86
+ return [4 /*yield*/, this.getTargetInfo()];
87
+ case 1:
88
+ // Resolving the target is what sets process.sasjsConstants - buildDB reads
89
+ // the source and destination db folders from there.
90
+ _a.sent();
91
+ return [4 /*yield*/, (0, db_1.buildDB)()
92
+ .then(function () {
93
+ var _a;
94
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('DB build completed!');
95
+ return command_1.ReturnCode.Success;
96
+ })
97
+ .catch(function (err) {
98
+ var _a;
99
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error building DB: ', err);
100
+ return command_1.ReturnCode.InternalError;
101
+ })];
102
+ case 2: return [2 /*return*/, _a.sent()];
95
103
  }
96
104
  });
97
105
  });
98
106
  };
99
107
  return DbCommand;
100
- }(types_1.CommandBase));
108
+ }(targetCommand_1.TargetCommand));
101
109
  exports.DbCommand = DbCommand;
@@ -94,10 +94,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
94
94
  return to.concat(ar || Array.prototype.slice.call(from));
95
95
  };
96
96
  Object.defineProperty(exports, "__esModule", { value: true });
97
- var logger_1 = require("@sasjs/utils/logger");
97
+ var utils_1 = require("@sasjs/utils");
98
98
  var command_1 = require("../../../types/command");
99
99
  var dbModule = __importStar(require("../db"));
100
100
  var dbCommand_1 = require("../dbCommand");
101
+ var configUtils = __importStar(require("../../../utils/config"));
102
+ var setConstantsUtils = __importStar(require("../../../utils/setConstants"));
103
+ var target = new utils_1.Target({
104
+ name: 'test-target',
105
+ serverUrl: 'https://sas.example.com',
106
+ serverType: utils_1.ServerType.SasViya,
107
+ appLoc: '/Public/app'
108
+ });
101
109
  describe('DbCommand', function () {
102
110
  var defaultArgs = ['node', 'sasjs'];
103
111
  beforeEach(function () {
@@ -125,6 +133,32 @@ describe('DbCommand', function () {
125
133
  }
126
134
  });
127
135
  }); });
136
+ it('should resolve the target - and so set the constants - before building', function () { return __awaiter(void 0, void 0, void 0, function () {
137
+ var calls;
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0:
141
+ calls = [];
142
+ setConstantsUtils.setConstants.mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () {
143
+ return __generator(this, function (_a) {
144
+ calls.push('setConstants');
145
+ return [2 /*return*/];
146
+ });
147
+ }); });
148
+ jest.spyOn(dbModule, 'buildDB').mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ calls.push('buildDB');
151
+ return [2 /*return*/];
152
+ });
153
+ }); });
154
+ return [4 /*yield*/, new dbCommand_1.DbCommand(__spreadArray(__spreadArray([], __read(defaultArgs), false), ['db'], false)).execute()];
155
+ case 1:
156
+ _a.sent();
157
+ expect(calls).toEqual(['setConstants', 'buildDB']);
158
+ return [2 /*return*/];
159
+ }
160
+ });
161
+ }); });
128
162
  it('should return an error code when the execution errors out', function () { return __awaiter(void 0, void 0, void 0, function () {
129
163
  var args, command, returnCode;
130
164
  return __generator(this, function (_a) {
@@ -149,7 +183,16 @@ var setupMocks = function () {
149
183
  jest.resetAllMocks();
150
184
  jest.mock('../db');
151
185
  jest.spyOn(dbModule, 'buildDB').mockImplementation(function () { return Promise.resolve(); });
152
- process.logger = new logger_1.Logger(logger_1.LogLevel.Off);
186
+ jest
187
+ .spyOn(configUtils, 'findTargetInConfiguration')
188
+ .mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
189
+ jest
190
+ .spyOn(configUtils, 'getLocalConfig')
191
+ .mockImplementation(function () { return Promise.resolve({}); });
192
+ jest
193
+ .spyOn(setConstantsUtils, 'setConstants')
194
+ .mockImplementation(function () { return Promise.resolve(); });
195
+ process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
153
196
  jest.spyOn(process.logger, 'success');
154
197
  jest.spyOn(process.logger, 'error');
155
198
  };
@@ -113,6 +113,15 @@ function printHelpText() {
113
113
  "It will also perform ".concat(chalk_1.default.greenBright('compile'), " command if services are not compiled.")
114
114
  ]
115
115
  },
116
+ {
117
+ name: 'builddeploy',
118
+ title: 'builddeploy <targetName>',
119
+ description: [
120
+ "builds the project and deploys the result to the target's server.",
121
+ "Unlike ".concat(chalk_1.default.greenBright('compilebuilddeploy'), " it does not recompile first - it ships the compiled services already in the build folder, and compiles only when that folder is missing."),
122
+ "Use ".concat(chalk_1.default.cyanBright('sasjs bd'), " as a shorthand.")
123
+ ]
124
+ },
116
125
  {
117
126
  name: 'compilebuild',
118
127
  title: 'compilebuild <targetName>',
@@ -344,6 +353,7 @@ function printHelpText() {
344
353
  ];
345
354
  aliases = [
346
355
  { name: 'build', aliases: ['b'] },
356
+ { name: 'builddeploy', aliases: ['bd'] },
347
357
  { name: 'compile', aliases: ['c'] },
348
358
  { name: 'compilebuild', aliases: ['cb'] },
349
359
  { name: 'compilebuilddeploy', aliases: ['cbd'] },
@@ -353,6 +363,7 @@ function printHelpText() {
353
363
  { name: 'help', aliases: ['h'] },
354
364
  { name: 'request', aliases: ['rq'] },
355
365
  { name: 'run', aliases: ['r'] },
366
+ { name: 'test', aliases: ['t'] },
356
367
  { name: 'version', aliases: ['v', '-v', '--version'] },
357
368
  { name: 'web', aliases: ['w'] }
358
369
  ];
@@ -117,6 +117,18 @@ describe('TestCommand', function () {
117
117
  expect(command.name).toEqual('test');
118
118
  expect(command.subCommand).toEqual('');
119
119
  });
120
+ it('should parse the t shorthand', function () {
121
+ var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['t'], false);
122
+ var command = new testCommand_1.TestCommand(args);
123
+ expect(command.name).toEqual('test');
124
+ expect(command.subCommand).toEqual('');
125
+ });
126
+ it('should accept filtering strings after the t shorthand', function () {
127
+ var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['t', 'pattern-1', '-t', 'testTarget'], false);
128
+ var command = new testCommand_1.TestCommand(args);
129
+ expect(command.name).toEqual('test');
130
+ expect(command.parsed.filteringString).toEqual(['pattern-1']);
131
+ });
120
132
  it('should parse a sasjs test command with all arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
121
133
  var args, command, targetInfo;
122
134
  return __generator(this, function (_a) {
@@ -59,6 +59,7 @@ var test_1 = require("./test");
59
59
  var syntax = 'test [filteringString..]';
60
60
  var usage = 'Usage: sasjs test [filtering-strings..] --source <test-flow-path> --outDirectory <folder-path> --target <target-name> --force';
61
61
  var description = 'Triggers SAS unit tests.';
62
+ var aliases = ['t'];
62
63
  var examples = [
63
64
  {
64
65
  command: 'sasjs test jobs/standalone1 jobs/standalone2 --source <test-flow-path> --outDirectory <folder-path> --target <target-name> --force',
@@ -94,7 +95,8 @@ var TestCommand = /** @class */ (function (_super) {
94
95
  syntax: syntax,
95
96
  usage: usage,
96
97
  description: description,
97
- examples: examples
98
+ examples: examples,
99
+ aliases: aliases
98
100
  }) || this;
99
101
  }
100
102
  TestCommand.prototype.execute = function () {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAllSupportedAliases = exports.aliasMap = void 0;
4
4
  exports.aliasMap = new Map([
5
5
  ['build', ['b']],
6
+ ['builddeploy', ['bd']],
6
7
  ['compile', ['c']],
7
8
  ['compilebuild', ['cb']],
8
9
  ['compilebuilddeploy', ['cbd']],
@@ -12,6 +13,7 @@ exports.aliasMap = new Map([
12
13
  ['help', ['h']],
13
14
  ['request', ['rq']],
14
15
  ['run', ['r']],
16
+ ['test', ['t']],
15
17
  ['version', ['v', '-v', '--version']],
16
18
  ['web', ['w']]
17
19
  ]);
@@ -4,6 +4,7 @@ exports.getAllSupportedCommands = exports.commandFactory = void 0;
4
4
  var addCommand_1 = require("../../commands/add/addCommand");
5
5
  var authCommand_1 = require("../../commands/auth/authCommand");
6
6
  var buildCommand_1 = require("../../commands/build/buildCommand");
7
+ var buildDeployCommand_1 = require("../../commands/build/buildDeployCommand");
7
8
  var compileBuildCommand_1 = require("../../commands/build/compileBuildCommand");
8
9
  var compileCommand_1 = require("../../commands/compile/compileCommand");
9
10
  var contextCommand_1 = require("../../commands/context/contextCommand");
@@ -30,6 +31,7 @@ exports.commandFactory = new Map([
30
31
  ['add', function (args) { return new addCommand_1.AddCommand(args); }],
31
32
  ['auth', function (args) { return new authCommand_1.AuthCommand(args); }],
32
33
  ['build', function (args) { return new buildCommand_1.BuildCommand(args); }],
34
+ ['builddeploy', function (args) { return new buildDeployCommand_1.BuildDeployCommand(args); }],
33
35
  ['compile', function (args) { return new compileCommand_1.CompileCommand(args); }],
34
36
  ['compilebuild', function (args) { return new compileBuildCommand_1.CompileBuildCommand(args); }],
35
37
  [
package/package.json CHANGED
@@ -123,5 +123,5 @@
123
123
  "ws": "8.21.0",
124
124
  "nanoid": "3.3.18"
125
125
  },
126
- "version": "6.4.7"
126
+ "version": "6.5.0"
127
127
  }