@takeshape/cli 8.199.0 → 8.200.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.
@@ -1,6 +1,7 @@
1
1
  import { ProjectImportFlags } from './project-import';
2
2
  import { SchemaImportFlags } from './schema-import';
3
+ import { RolesImportFlags } from './roles-import';
3
4
  import { Handler } from '../../types';
4
- declare const commandHandler: Handler<ProjectImportFlags | SchemaImportFlags>;
5
+ declare const commandHandler: Handler<ProjectImportFlags | SchemaImportFlags | RolesImportFlags>;
5
6
  export default commandHandler;
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/import/index.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACnE,OAAqB,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC,QAAA,MAAM,cAAc,EAAE,OAAO,CAAC,kBAAkB,GAAG,iBAAiB,CAMnE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/import/index.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACnE,OAAqB,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAChE,OAAoB,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC,QAAA,MAAM,cAAc,EAAE,OAAO,CAAC,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,CActF,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -9,6 +9,8 @@ var _projectImport = _interopRequireDefault(require("./project-import"));
9
9
 
10
10
  var _schemaImport = _interopRequireDefault(require("./schema-import"));
11
11
 
12
+ var _rolesImport = _interopRequireDefault(require("./roles-import"));
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
16
  const commandHandler = async (command, params, flags) => {
@@ -16,6 +18,10 @@ const commandHandler = async (command, params, flags) => {
16
18
  return (0, _schemaImport.default)(command, params, flags);
17
19
  }
18
20
 
21
+ if ('roles' in flags) {
22
+ return (0, _rolesImport.default)(command, params, flags);
23
+ }
24
+
19
25
  return (0, _projectImport.default)(command, params, flags);
20
26
  };
21
27
 
@@ -0,0 +1,7 @@
1
+ export interface RolesImportFlags {
2
+ roles: true;
3
+ from: string;
4
+ }
5
+ declare const _default: import("../../types").Handler<RolesImportFlags>;
6
+ export default _default;
7
+ //# sourceMappingURL=roles-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles-import.d.ts","sourceRoot":"","sources":["../../../../src/commands/import/roles-import.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,IAAI,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;;AAED,wBAoBG"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _fatalError = require("../../util/fatal-error");
9
+
10
+ var _linkedCommand = require("../../util/linked-command");
11
+
12
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
+
14
+ var _log = require("../../log");
15
+
16
+ var _api = _interopRequireDefault(require("../../util/api"));
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _schema = require("@takeshape/schema");
21
+
22
+ var _fs = require("../../util/fs");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
26
+ var _default = (0, _linkedCommand.linkedCommand)(async (_, params, flags) => {
27
+ if (!flags.from) {
28
+ return (0, _fatalError.fatalError)('No roles file provided. Use `--from path/to/file` or `--from directory`.');
29
+ }
30
+
31
+ const {
32
+ exists,
33
+ file
34
+ } = (0, _fs.resolveFromFlag)(flags.from, 'roles.json');
35
+
36
+ if (!exists) {
37
+ return (0, _fatalError.fatalError)(`Roles file does not exist: ${file}`);
38
+ }
39
+
40
+ try {
41
+ const roles = JSON.parse(_fsExtra.default.readFileSync(file).toString());
42
+ const validatedRoles = (0, _schema.validateRoleImport)(roles);
43
+ (0, _log.log)(`Uploading roles from ${file}…\n`);
44
+ await (0, _api.default)(params, 'POST', `/project/${params.projectId}/roles`, validatedRoles);
45
+ (0, _log.log)(_chalk.default.green('Success!'), 'Roles updated.');
46
+ } catch (e) {
47
+ return (0, _fatalError.fatalError)(e.message);
48
+ }
49
+ });
50
+
51
+ exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"file":"schema-import.d.ts","sourceRoot":"","sources":["../../../../src/commands/import/schema-import.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;;AAWD,wBAiCG"}
1
+ {"version":3,"file":"schema-import.d.ts","sourceRoot":"","sources":["../../../../src/commands/import/schema-import.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;;AAWD,wBA0BG"}
@@ -19,10 +19,10 @@ var _schema = require("@takeshape/schema");
19
19
 
20
20
  var _linkedCommand = require("../../util/linked-command");
21
21
 
22
- var _path = _interopRequireDefault(require("path"));
23
-
24
22
  var _formatValidationResult = require("../../util/format-validation-result");
25
23
 
24
+ var _fs = require("../../util/fs");
25
+
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
28
  /*
@@ -42,18 +42,13 @@ var _default = (0, _linkedCommand.linkedCommand)(async (_, params, flags) => {
42
42
  return (0, _fatalError.fatalError)('No schema file provided. Use `--from path/to/file` or `--from directory`.');
43
43
  }
44
44
 
45
- if (!_fsExtra.default.existsSync(flags.from)) {
46
- return (0, _fatalError.fatalError)(`${flags.from} does not exist`);
47
- }
48
-
49
- let file = flags.from;
50
-
51
- if (!_fsExtra.default.lstatSync(file).isFile()) {
52
- file = _path.default.join(flags.from, 'schema.json');
45
+ const {
46
+ exists,
47
+ file
48
+ } = (0, _fs.resolveFromFlag)(flags.from, 'schema.json');
53
49
 
54
- if (!_fsExtra.default.existsSync(file) || !_fsExtra.default.lstatSync(file).isFile()) {
55
- return (0, _fatalError.fatalError)(`Schema file does not exist: ${file}`);
56
- }
50
+ if (!exists) {
51
+ return (0, _fatalError.fatalError)(`Schema file does not exist: ${file}`);
57
52
  }
58
53
 
59
54
  try {
package/dist/index.js CHANGED
@@ -41,21 +41,22 @@ const help = `
41
41
  --watchContent, -W rebuild on content change (watch only)
42
42
 
43
43
  import Options
44
- --schema import a takeshape schema from a directory or JSON file to the currently linked project
45
- use either --schema or --project not both, must be combined with --from
46
- --project import a takeshape project from given directory, zip or url
47
- use either --project or --schema not both, must be combined with --from
48
- --from specifies the file, directory, zip or url to import
44
+ One of
45
+ --project import a takeshape project from given directory, zip or url
46
+ --schema import a takeshape schema from a directory or JSON file to the currently linked project
47
+ --roles import roles from a directory or JSON file to the currently linked project
48
+
49
+ --from specifies the file, directory, zip or url to import (required)
49
50
  --to either "new-project" or "current-project" (default "new-project")
50
51
  --name for use with --project specifies a new name for the imported project
51
52
 
52
53
  export Options
53
- --schema export a takeshape schema from a directory or JSON file
54
- use either --schema or --project not both, must be combined with --to
55
- --project export a takeshape project zip
56
- use either --project or --schema not both, must be combined with --to
54
+ One of
55
+ --schema export a takeshape schema from a directory or JSON file
56
+ --project export a takeshape project zip
57
+
58
+ --to specifies the directory to write the exported data to (required)
57
59
  --withoutData when using --project skip exporting the data
58
- --to specifies the directory to write the exported data to
59
60
 
60
61
  validate Options
61
62
  --path path to the schema file to validate, or the directory it is in (default "./schema.json")
@@ -1,5 +1,5 @@
1
1
  import { CliConfig } from '../types';
2
2
  export declare function isJWT(str: string): boolean;
3
3
  export declare function getAuthHeader(authToken?: string): Record<string, string>;
4
- export default function api<T = any>(params: CliConfig, method: string, path: string, body?: any): Promise<T>;
4
+ export default function api(params: CliConfig, method: string, path: string, body?: any): Promise<any>;
5
5
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/util/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAanC,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG1C;AAED,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxE;AAED,wBAA8B,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAqBlH"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/util/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAanC,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG1C;AAED,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxE;AAED,wBAA8B,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAyB3G"}
package/dist/util/api.js CHANGED
@@ -59,6 +59,10 @@ async function api(params, method, path, body) {
59
59
  const res = await (0, _nodeFetch.default)(endpoint, requestParams);
60
60
 
61
61
  if (res.ok) {
62
+ if (res.size === 0) {
63
+ return;
64
+ }
65
+
62
66
  return res.json();
63
67
  }
64
68
 
@@ -0,0 +1,5 @@
1
+ export declare function resolveFromFlag(from: string, expectedFilename: string): {
2
+ exists: boolean;
3
+ file: string;
4
+ };
5
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/util/fs.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM;;;EAerE"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveFromFlag = resolveFromFlag;
7
+
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function resolveFromFlag(from, expectedFilename) {
15
+ if (!_fsExtra.default.existsSync(from)) {
16
+ return {
17
+ exists: false,
18
+ file: from
19
+ };
20
+ }
21
+
22
+ if (_fsExtra.default.lstatSync(from).isFile()) {
23
+ return {
24
+ exists: true,
25
+ file: from
26
+ };
27
+ }
28
+
29
+ const file = _path.default.join(from, expectedFilename);
30
+
31
+ if (_fsExtra.default.existsSync(file) && _fsExtra.default.lstatSync(file).isFile()) {
32
+ return {
33
+ exists: true,
34
+ file
35
+ };
36
+ }
37
+
38
+ return {
39
+ exists: false,
40
+ file
41
+ };
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/cli",
3
- "version": "8.199.0",
3
+ "version": "8.200.0",
4
4
  "description": "TakeShape CLI",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -25,10 +25,10 @@
25
25
  "@graphql-codegen/typescript": "^2.4.5",
26
26
  "@graphql-tools/graphql-file-loader": "^7.3.3",
27
27
  "@graphql-tools/load": "^7.5.1",
28
- "@takeshape/schema": "8.199.0",
29
- "@takeshape/ssg": "8.199.0",
30
- "@takeshape/streams": "8.199.0",
31
- "@takeshape/util": "8.199.0",
28
+ "@takeshape/schema": "8.200.0",
29
+ "@takeshape/ssg": "8.200.0",
30
+ "@takeshape/streams": "8.200.0",
31
+ "@takeshape/util": "8.200.0",
32
32
  "archiver": "^1.3.0",
33
33
  "async-retry": "^1.2.1",
34
34
  "bluebird": "^3.4.6",