specmatic 0.68.0 → 0.68.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.
package/dist/bin/core.js CHANGED
@@ -6,38 +6,38 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _execSh = _interopRequireDefault(require("exec-sh"));
8
8
  var _path = _interopRequireDefault(require("path"));
9
- var _config = require("../config");
10
- var _logger = _interopRequireDefault(require("../common/logger"));
11
9
  var _child_process = require("child_process");
12
10
  var _fs = _interopRequireDefault(require("fs"));
11
+ var _config = require("../config");
12
+ var _logger = _interopRequireDefault(require("../common/logger"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
16
- var callSpecmaticCli = /*#__PURE__*/function () {
17
- var _ref = _asyncToGenerator(function* (args) {
18
- var specmaticJarPath = yield getSpecmaticJarPath();
19
- _logger.default.debug("CLI: Specmatic jar path: ".concat(specmaticJarPath));
20
- var cliArgs = (args || process.argv).slice(2).join(' ');
21
- _logger.default.info("CLI: Running with args \"".concat(cliArgs, "\""));
22
- (0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(cliArgs), {}, err => {
23
- if (err) {
24
- _logger.default.info('CLI: Finished with non zero exit code: ', err.code);
25
- process.exitCode = err.code;
26
- } else {
27
- _logger.default.info('CLI: Finished');
28
- process.exitCode = 0;
29
- }
30
- });
14
+ var callSpecmaticCli = args => {
15
+ var rootPath = _path.default.resolve(__dirname, '..', '..');
16
+ var specmaticJarPath = _path.default.resolve(rootPath, _config.specmaticJarName);
17
+ _logger.default.debug("CLI: Specmatic jar path: ".concat(specmaticJarPath));
18
+ var cliArgs = (args || process.argv).slice(2).join(' ');
19
+ _logger.default.info("CLI: Running with args \"".concat(cliArgs, "\""));
20
+ (0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(cliArgs), {}, err => {
21
+ if (err) {
22
+ _logger.default.info('CLI: Finished with non zero exit code: ', err.code);
23
+ process.exitCode = err.code;
24
+ } else {
25
+ _logger.default.info('CLI: Finished');
26
+ process.exitCode = 0;
27
+ }
31
28
  });
32
- return function callSpecmaticCli(_x) {
33
- return _ref.apply(this, arguments);
34
- };
35
- }();
29
+ };
36
30
  function getSpecmaticJarPath() {
37
31
  return new Promise((resolve, _reject) => {
38
32
  var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
39
33
  resolve(specmaticJarPath);
40
34
  }).then(specmaticJarPath => {
35
+ //Get current directory
36
+ console.log("Script basename: ".concat(__dirname));
37
+ var rootPath = _path.default.resolve(__dirname, '..', '..');
38
+ var specmaticJarPath2 = _path.default.resolve(rootPath, _config.specmaticJarName);
39
+ console.log("Script jar path: ".concat(specmaticJarPath2));
40
+ console.log("Script jar path exists? ".concat(_fs.default.existsSync(specmaticJarPath2)));
41
41
  if (!_fs.default.existsSync(specmaticJarPath)) {
42
42
  return getGlobalSpecmaticJarPath();
43
43
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specmatic",
3
- "version": "0.68.0",
3
+ "version": "0.68.1",
4
4
  "description": "Node wrapper for Specmatic",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -16,19 +16,20 @@ beforeEach(() => {
16
16
  test('pass all wrapper arguments to the jar', async () => {
17
17
  jest.spyOn(fs, 'existsSync').mockReturnValue(true);
18
18
  const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
19
- await callSpecmaticCli(testArgs);
20
- expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} ${testArgs.slice(2).join(' ')}`);
19
+ callSpecmaticCli(testArgs);
20
+ const specmaticJarPath = path.resolve(__dirname, '..', '..', '..', specmaticJarName);
21
+ expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPath)} ${testArgs.slice(2).join(' ')}`);
21
22
  expect(execSh).toHaveBeenCalledTimes(1);
22
23
  });
23
24
 
24
- test('look for jar in specmatic globally installled directory when run from global install', async () => {
25
- jest.spyOn(fs, 'existsSync').mockReturnValue(false);
26
- const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
27
- const NPM_GLOBAL_PATH = '/npm/global/path';
28
- setTimeout(() => {
29
- execMock.mock.calls[0][1](0, NPM_GLOBAL_PATH);
30
- }, 0);
31
- await callSpecmaticCli(testArgs);
32
- expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(NPM_GLOBAL_PATH, 'specmatic', specmaticJarName)} ${testArgs.slice(2).join(' ')}`);
33
- expect(execSh).toHaveBeenCalledTimes(1);
34
- });
25
+ // test('look for jar in specmatic globally installled directory when run from global install', async () => {
26
+ // jest.spyOn(fs, 'existsSync').mockReturnValue(false);
27
+ // const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
28
+ // const NPM_GLOBAL_PATH = '/npm/global/path';
29
+ // setTimeout(() => {
30
+ // execMock.mock.calls[0][1](0, NPM_GLOBAL_PATH);
31
+ // }, 0);
32
+ // await callSpecmaticCli(testArgs);
33
+ // expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(NPM_GLOBAL_PATH, 'specmatic', specmaticJarName)} ${testArgs.slice(2).join(' ')}`);
34
+ // expect(execSh).toHaveBeenCalledTimes(1);
35
+ // });
package/src/bin/core.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import execSh from 'exec-sh';
2
2
  import path from 'path';
3
- import { specmaticJarPathLocal, specmaticJarName } from '../config';
4
- import logger from '../common/logger';
5
3
  import { exec } from 'child_process';
6
4
  import fs from 'fs';
5
+ import { specmaticJarPathLocal, specmaticJarName } from '../config';
6
+ import logger from '../common/logger';
7
7
 
8
- const callSpecmaticCli = async (args?: string[]) => {
9
- const specmaticJarPath = await getSpecmaticJarPath();
8
+ const callSpecmaticCli = (args?: string[]) => {
9
+ const rootPath = path.resolve(__dirname, '..', '..');
10
+ const specmaticJarPath = path.resolve(rootPath, specmaticJarName);
10
11
  logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
11
12
  const cliArgs = (args || process.argv).slice(2).join(' ');
12
13
  logger.info(`CLI: Running with args "${cliArgs}"`);
@@ -26,6 +27,12 @@ function getSpecmaticJarPath() {
26
27
  let specmaticJarPath = path.resolve(specmaticJarPathLocal);
27
28
  resolve(specmaticJarPath);
28
29
  }).then(specmaticJarPath => {
30
+ //Get current directory
31
+ console.log(`Script basename: ${__dirname}`);
32
+ const rootPath = path.resolve(__dirname, '..', '..');
33
+ const specmaticJarPath2 = path.resolve(rootPath, specmaticJarName);
34
+ console.log(`Script jar path: ${specmaticJarPath2}`);
35
+ console.log(`Script jar path exists? ${fs.existsSync(specmaticJarPath2)}`);
29
36
  if (!fs.existsSync(specmaticJarPath)) {
30
37
  return getGlobalSpecmaticJarPath();
31
38
  } else {