@takeshape/cli 7.194.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.
Files changed (137) hide show
  1. package/README.md +9 -0
  2. package/lib/auth.d.ts +5 -0
  3. package/lib/auth.d.ts.map +1 -0
  4. package/lib/auth.js +76 -0
  5. package/lib/check-version.d.ts +2 -0
  6. package/lib/check-version.d.ts.map +1 -0
  7. package/lib/check-version.js +22 -0
  8. package/lib/commands/build-or-watch.d.ts +4 -0
  9. package/lib/commands/build-or-watch.d.ts.map +1 -0
  10. package/lib/commands/build-or-watch.js +69 -0
  11. package/lib/commands/deploy/index.d.ts +9 -0
  12. package/lib/commands/deploy/index.d.ts.map +1 -0
  13. package/lib/commands/deploy/index.js +74 -0
  14. package/lib/commands/deploy/zip.d.ts +18 -0
  15. package/lib/commands/deploy/zip.d.ts.map +1 -0
  16. package/lib/commands/deploy/zip.js +57 -0
  17. package/lib/commands/export/index.d.ts +6 -0
  18. package/lib/commands/export/index.d.ts.map +1 -0
  19. package/lib/commands/export/index.js +23 -0
  20. package/lib/commands/export/project-export.d.ts +13 -0
  21. package/lib/commands/export/project-export.d.ts.map +1 -0
  22. package/lib/commands/export/project-export.js +104 -0
  23. package/lib/commands/export/schema-export.d.ts +7 -0
  24. package/lib/commands/export/schema-export.d.ts.map +1 -0
  25. package/lib/commands/export/schema-export.js +80 -0
  26. package/lib/commands/import/index.d.ts +6 -0
  27. package/lib/commands/import/index.d.ts.map +1 -0
  28. package/lib/commands/import/index.js +23 -0
  29. package/lib/commands/import/project-import.d.ts +16 -0
  30. package/lib/commands/import/project-import.d.ts.map +1 -0
  31. package/lib/commands/import/project-import.js +167 -0
  32. package/lib/commands/import/schema-import.d.ts +7 -0
  33. package/lib/commands/import/schema-import.d.ts.map +1 -0
  34. package/lib/commands/import/schema-import.js +75 -0
  35. package/lib/commands/link.d.ts +3 -0
  36. package/lib/commands/link.d.ts.map +1 -0
  37. package/lib/commands/link.js +61 -0
  38. package/lib/commands/login.d.ts +4 -0
  39. package/lib/commands/login.d.ts.map +1 -0
  40. package/lib/commands/login.js +31 -0
  41. package/lib/commands/logout.d.ts +4 -0
  42. package/lib/commands/logout.d.ts.map +1 -0
  43. package/lib/commands/logout.js +29 -0
  44. package/lib/commands/schema.d.ts +3 -0
  45. package/lib/commands/schema.d.ts.map +1 -0
  46. package/lib/commands/schema.js +23 -0
  47. package/lib/commands/status.d.ts +3 -0
  48. package/lib/commands/status.d.ts.map +1 -0
  49. package/lib/commands/status.js +20 -0
  50. package/lib/commands/unlink.d.ts +4 -0
  51. package/lib/commands/unlink.d.ts.map +1 -0
  52. package/lib/commands/unlink.js +29 -0
  53. package/lib/config.d.ts +14 -0
  54. package/lib/config.d.ts.map +1 -0
  55. package/lib/config.js +161 -0
  56. package/lib/deprecated.d.ts +2 -0
  57. package/lib/deprecated.d.ts.map +1 -0
  58. package/lib/deprecated.js +9 -0
  59. package/lib/errors.d.ts +7 -0
  60. package/lib/errors.d.ts.map +1 -0
  61. package/lib/errors.js +36 -0
  62. package/lib/files.d.ts +5 -0
  63. package/lib/files.d.ts.map +1 -0
  64. package/lib/files.js +53 -0
  65. package/lib/graphql.d.ts +14 -0
  66. package/lib/graphql.d.ts.map +1 -0
  67. package/lib/graphql.js +94 -0
  68. package/lib/index.d.ts +3 -0
  69. package/lib/index.d.ts.map +1 -0
  70. package/lib/index.js +78 -0
  71. package/lib/log.d.ts +4 -0
  72. package/lib/log.d.ts.map +1 -0
  73. package/lib/log.js +21 -0
  74. package/lib/main.d.ts +2 -0
  75. package/lib/main.d.ts.map +1 -0
  76. package/lib/main.js +36 -0
  77. package/lib/prompt.d.ts +11 -0
  78. package/lib/prompt.d.ts.map +1 -0
  79. package/lib/prompt.js +39 -0
  80. package/lib/types.d.ts +45 -0
  81. package/lib/types.d.ts.map +1 -0
  82. package/lib/types.js +20 -0
  83. package/lib/util/api.d.ts +5 -0
  84. package/lib/util/api.d.ts.map +1 -0
  85. package/lib/util/api.js +66 -0
  86. package/lib/util/cached-connector.d.ts +5 -0
  87. package/lib/util/cached-connector.d.ts.map +1 -0
  88. package/lib/util/cached-connector.js +34 -0
  89. package/lib/util/connector.d.ts +7 -0
  90. package/lib/util/connector.d.ts.map +1 -0
  91. package/lib/util/connector.js +19 -0
  92. package/lib/util/data.d.ts +38 -0
  93. package/lib/util/data.d.ts.map +1 -0
  94. package/lib/util/data.js +156 -0
  95. package/lib/util/fatal-error.d.ts +2 -0
  96. package/lib/util/fatal-error.d.ts.map +1 -0
  97. package/lib/util/fatal-error.js +17 -0
  98. package/lib/util/format-error.d.ts +2 -0
  99. package/lib/util/format-error.d.ts.map +1 -0
  100. package/lib/util/format-error.js +10 -0
  101. package/lib/util/get-client-schema.d.ts +4 -0
  102. package/lib/util/get-client-schema.d.ts.map +1 -0
  103. package/lib/util/get-client-schema.js +28 -0
  104. package/lib/util/glitch.d.ts +5 -0
  105. package/lib/util/glitch.d.ts.map +1 -0
  106. package/lib/util/glitch.js +51 -0
  107. package/lib/util/linked-command.d.ts +4 -0
  108. package/lib/util/linked-command.d.ts.map +1 -0
  109. package/lib/util/linked-command.js +33 -0
  110. package/lib/util/login.d.ts +16 -0
  111. package/lib/util/login.d.ts.map +1 -0
  112. package/lib/util/login.js +123 -0
  113. package/lib/util/messages.d.ts +13 -0
  114. package/lib/util/messages.d.ts.map +1 -0
  115. package/lib/util/messages.js +57 -0
  116. package/lib/util/ora-wrapper.d.ts +2 -0
  117. package/lib/util/ora-wrapper.d.ts.map +1 -0
  118. package/lib/util/ora-wrapper.js +28 -0
  119. package/lib/util/pusher.d.ts +4 -0
  120. package/lib/util/pusher.d.ts.map +1 -0
  121. package/lib/util/pusher.js +45 -0
  122. package/lib/util/runner.d.ts +2 -0
  123. package/lib/util/runner.d.ts.map +1 -0
  124. package/lib/util/runner.js +44 -0
  125. package/lib/util/select-project.d.ts +4 -0
  126. package/lib/util/select-project.d.ts.map +1 -0
  127. package/lib/util/select-project.js +23 -0
  128. package/lib/util/spin.d.ts +7 -0
  129. package/lib/util/spin.d.ts.map +1 -0
  130. package/lib/util/spin.js +41 -0
  131. package/lib/util/upload.d.ts +5 -0
  132. package/lib/util/upload.d.ts.map +1 -0
  133. package/lib/util/upload.js +55 -0
  134. package/lib/util/watcher.d.ts +2 -0
  135. package/lib/util/watcher.d.ts.map +1 -0
  136. package/lib/util/watcher.js +30 -0
  137. package/package.json +90 -0
package/lib/config.js ADDED
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getHomeConfigPath = getHomeConfigPath;
7
+ exports.loadConfig = loadConfig;
8
+ exports.writeLinkedProjectConfig = writeLinkedProjectConfig;
9
+ exports.deleteLinkedConfig = deleteLinkedConfig;
10
+ exports.writeHomeConfig = writeHomeConfig;
11
+ exports.deleteHomeConfig = deleteHomeConfig;
12
+ exports.GRAPHQL_CONFIG_FILENAME = exports.TAKESHAPE_CONFIG_FILENAME = void 0;
13
+
14
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
15
+
16
+ var _path = _interopRequireDefault(require("path"));
17
+
18
+ var _os = _interopRequireDefault(require("os"));
19
+
20
+ var _isDocker = _interopRequireDefault(require("is-docker"));
21
+
22
+ var _messages = require("./util/messages");
23
+
24
+ var _graphql = require("./graphql");
25
+
26
+ var _api = require("./util/api");
27
+
28
+ var _connector = require("./util/connector");
29
+
30
+ var _getClientSchema = _interopRequireDefault(require("./util/get-client-schema"));
31
+
32
+ var _ignore = _interopRequireDefault(require("ignore"));
33
+
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+
36
+ const TAKESHAPE_CONFIG_FILENAME = '.takeshaperc';
37
+ exports.TAKESHAPE_CONFIG_FILENAME = TAKESHAPE_CONFIG_FILENAME;
38
+ const GRAPHQL_CONFIG_FILENAME = '.graphqlconfig';
39
+ exports.GRAPHQL_CONFIG_FILENAME = GRAPHQL_CONFIG_FILENAME;
40
+
41
+ function getHomeConfigPath() {
42
+ return _path.default.join(_os.default.homedir(), TAKESHAPE_CONFIG_FILENAME);
43
+ }
44
+
45
+ function loadConfig(cwd, cli) {
46
+ var _cli$flags$output, _cli$flags$file, _ref, _process$env$TS_APP_U, _ref2, _process$env$TS_API_E, _ref3, _cli$flags$token, _ref4, _cli$flags$site, _process$env$TS_PROJE, _process$env$TS_PROJE2, _process$env$TS_SITE_;
47
+
48
+ let config = {};
49
+
50
+ const configPath = _path.default.join(cwd, TAKESHAPE_CONFIG_FILENAME);
51
+
52
+ if (_fsExtra.default.existsSync(configPath)) {
53
+ config = _fsExtra.default.readJsonSync(configPath);
54
+ }
55
+
56
+ const homeConfigPath = getHomeConfigPath();
57
+
58
+ if (_fsExtra.default.existsSync(homeConfigPath)) {
59
+ const homeConfig = _fsExtra.default.readJsonSync(homeConfigPath);
60
+
61
+ config.authToken = homeConfig.accessToken;
62
+ config.personalAccessTokenId = homeConfig.id;
63
+ }
64
+
65
+ return {
66
+ buildPath: _path.default.join(cwd, (_cli$flags$output = cli.flags.output) !== null && _cli$flags$output !== void 0 ? _cli$flags$output : 'build'),
67
+ configFilePath: _path.default.join(cwd, (_cli$flags$file = cli.flags.file) !== null && _cli$flags$file !== void 0 ? _cli$flags$file : 'tsg.yml'),
68
+ appUrl: (_ref = (_process$env$TS_APP_U = process.env.TS_APP_URL) !== null && _process$env$TS_APP_U !== void 0 ? _process$env$TS_APP_U : config.appUrl) !== null && _ref !== void 0 ? _ref : 'https://app.takeshape.io',
69
+ endpoint: (_ref2 = (_process$env$TS_API_E = process.env.TS_API_ENDPOINT) !== null && _process$env$TS_API_E !== void 0 ? _process$env$TS_API_E : config.endpoint) !== null && _ref2 !== void 0 ? _ref2 : 'https://api.takeshape.io',
70
+ authToken: (_ref3 = (_cli$flags$token = cli.flags.token) !== null && _cli$flags$token !== void 0 ? _cli$flags$token : process.env.TS_AUTH_TOKEN) !== null && _ref3 !== void 0 ? _ref3 : config.authToken,
71
+ personalAccessTokenId: config.personalAccessTokenId,
72
+ linkedApiKey: process.env.TS_API_KEY ? {
73
+ id: 'TS_API_KEY',
74
+ apiKey: process.env.TS_API_KEY
75
+ } : config.linkedApiKey,
76
+ cliLogin: Boolean(cli.flags.cliLogin) || (0, _isDocker.default)() || Boolean(process.env.GITHUB_ACTIONS),
77
+ siteId: (_ref4 = (_cli$flags$site = cli.flags.site) !== null && _cli$flags$site !== void 0 ? _cli$flags$site : process.env.TS_SITE_ID) !== null && _ref4 !== void 0 ? _ref4 : config.siteId,
78
+ projectName: (_process$env$TS_PROJE = process.env.TS_PROJECT_NAME) !== null && _process$env$TS_PROJE !== void 0 ? _process$env$TS_PROJE : config.projectName,
79
+ projectId: (_process$env$TS_PROJE2 = process.env.TS_PROJECT_ID) !== null && _process$env$TS_PROJE2 !== void 0 ? _process$env$TS_PROJE2 : config.projectId,
80
+ siteName: (_process$env$TS_SITE_ = process.env.TS_SITE_NAME) !== null && _process$env$TS_SITE_ !== void 0 ? _process$env$TS_SITE_ : config.siteName,
81
+ cache: Boolean(cli.flags.cache),
82
+ watchContent: Boolean(cli.flags.watchContent)
83
+ };
84
+ }
85
+
86
+ function gitignores(files) {
87
+ if (_fsExtra.default.existsSync('.gitignore')) {
88
+ const ig = (0, _ignore.default)().add(_fsExtra.default.readFileSync('.gitignore', 'utf8'));
89
+ return ig.filter(files).length === 0;
90
+ }
91
+
92
+ return false;
93
+ }
94
+
95
+ async function writeLinkedProjectConfig(params, linkedApiKey, project, site) {
96
+ (0, _messages.writingFilesMsg)();
97
+
98
+ if (!gitignores([GRAPHQL_CONFIG_FILENAME, TAKESHAPE_CONFIG_FILENAME])) {
99
+ (0, _messages.consoleWarning)();
100
+ }
101
+
102
+ const graphqlEndpoint = (0, _graphql.getGraphQLEndpoint)(params, project.value);
103
+ const takeshaperc = {
104
+ projectId: project.value,
105
+ siteId: site === null || site === void 0 ? void 0 : site.value,
106
+ siteName: site === null || site === void 0 ? void 0 : site.name,
107
+ endpoint: params.endpoint,
108
+ appUrl: params.appUrl,
109
+ projectName: project.name,
110
+ linkedApiKey
111
+ };
112
+ const options = {
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ ...(0, _api.getAuthHeader)(linkedApiKey.apiKey)
116
+ },
117
+ introspect: true
118
+ };
119
+ const graphqlConfigJson = {
120
+ schemaPath: 'takeshape-project.graphql',
121
+ includes: ['**/*.graphql'],
122
+ excludes: ['node_modules/**/*.graphql'],
123
+ extensions: {
124
+ endpoints: {
125
+ TakeShape: {
126
+ url: graphqlEndpoint,
127
+ ...options
128
+ }
129
+ }
130
+ }
131
+ };
132
+ await Promise.all([_fsExtra.default.writeJSON(GRAPHQL_CONFIG_FILENAME, graphqlConfigJson), _fsExtra.default.writeJSON(TAKESHAPE_CONFIG_FILENAME, takeshaperc), (0, _getClientSchema.default)((0, _connector.createConnector)({ ...params,
133
+ ...takeshaperc
134
+ }, {
135
+ cache: false
136
+ }))]);
137
+ }
138
+
139
+ function deleteLinkedConfig() {
140
+ if (_fsExtra.default.existsSync(GRAPHQL_CONFIG_FILENAME)) {
141
+ _fsExtra.default.removeSync(GRAPHQL_CONFIG_FILENAME);
142
+ }
143
+
144
+ if (_fsExtra.default.existsSync(TAKESHAPE_CONFIG_FILENAME)) {
145
+ _fsExtra.default.removeSync(TAKESHAPE_CONFIG_FILENAME);
146
+ }
147
+ }
148
+
149
+ async function writeHomeConfig(accessToken) {
150
+ const configPath = getHomeConfigPath();
151
+ (0, _messages.writingHomeConfigMsg)(configPath);
152
+ await _fsExtra.default.writeJSON(configPath, accessToken);
153
+ }
154
+
155
+ function deleteHomeConfig() {
156
+ const homeConfigPath = getHomeConfigPath();
157
+
158
+ if (_fsExtra.default.existsSync(homeConfigPath)) {
159
+ _fsExtra.default.removeSync(homeConfigPath);
160
+ }
161
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=deprecated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.d.ts","sourceRoot":"","sources":["../../src/deprecated.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _log = _interopRequireDefault(require("./log"));
4
+
5
+ var _chalk = _interopRequireDefault(require("chalk"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ (0, _log.default)(`${_chalk.default.red('Error:')} The "tsg" command has been deprecated. Use "takeshape" instead`);
@@ -0,0 +1,7 @@
1
+ export declare class HTTPError extends Error {
2
+ statusCode: number;
3
+ constructor(message: string, statusCode: number);
4
+ }
5
+ export declare function formatErrorMessage(error: Error | HTTPError, activity: string): Error;
6
+ export declare function handleHttpErrors(error: Error | HTTPError, activity: string): void;
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAC3B,UAAU,EAAE,MAAM,CAAC;gBACP,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAIvD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAYpF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEjF"}
package/lib/errors.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatErrorMessage = formatErrorMessage;
7
+ exports.handleHttpErrors = handleHttpErrors;
8
+ exports.HTTPError = void 0;
9
+
10
+ class HTTPError extends Error {
11
+ constructor(message, statusCode) {
12
+ super(message);
13
+ this.statusCode = statusCode;
14
+ }
15
+
16
+ }
17
+
18
+ exports.HTTPError = HTTPError;
19
+
20
+ function formatErrorMessage(error, activity) {
21
+ if ('statusCode' in error) {
22
+ if (error.statusCode === 401 || error.statusCode === 403) {
23
+ return new Error('Insufficient Permissions to develop with TakeShape CLI. Your account must have the "Admin" role or better.');
24
+ }
25
+
26
+ if (error.statusCode === 500) {
27
+ return new Error(`A Server error occurred while ${activity}.`);
28
+ }
29
+ }
30
+
31
+ return error;
32
+ }
33
+
34
+ function handleHttpErrors(error, activity) {
35
+ throw formatErrorMessage(error, activity);
36
+ }
package/lib/files.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export function copyStatic(config: any): Promise<void>;
2
+ export function syncStatic(config: any): (event: any, sourcePath: any) => void;
3
+ export function writePages(outputPath: any): (generated: any) => BbPromise<any>;
4
+ import BbPromise from "bluebird";
5
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/files.js"],"names":[],"mappings":"AAKA,uDAIC;AAED,+EAgBC;AAED,gFAOC"}
package/lib/files.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.copyStatic = copyStatic;
7
+ exports.syncStatic = syncStatic;
8
+ exports.writePages = writePages;
9
+
10
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _bluebird = _interopRequireDefault(require("bluebird"));
15
+
16
+ var _log = _interopRequireDefault(require("./log"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ async function copyStatic(config) {
21
+ return _fsExtra.default.mkdirs(config.buildPath).then(async () => _fsExtra.default.copy(config.staticPath, config.buildPath, {
22
+ preserveTimestamps: true
23
+ }));
24
+ }
25
+
26
+ function syncStatic(config) {
27
+ return (event, sourcePath) => {
28
+ const relativePath = sourcePath.replace(config.staticPath, '');
29
+
30
+ const destPath = _path.default.join(config.buildPath, relativePath);
31
+
32
+ if (event === 'addDir') {
33
+ (0, _log.default)('takeshape watch - copied ' + relativePath);
34
+ void _fsExtra.default.mkdirs(destPath);
35
+ } else if (event === 'unlink' || event === 'unlinkDir') {
36
+ (0, _log.default)('takeshape watch - deleted ' + relativePath);
37
+ void _fsExtra.default.remove(destPath);
38
+ } else {
39
+ (0, _log.default)('takeshape watch - copied ' + relativePath);
40
+ void _fsExtra.default.copy(sourcePath, destPath);
41
+ }
42
+ };
43
+ }
44
+
45
+ function writePages(outputPath) {
46
+ return generated => {
47
+ return _bluebird.default.map(generated.pages, async page => {
48
+ const filePath = _path.default.join(outputPath, page.path);
49
+
50
+ return _fsExtra.default.mkdirs(_path.default.dirname(filePath)).then(async () => _fsExtra.default.writeFile(filePath, page.contents, 'utf8'));
51
+ }).then(() => generated.stats);
52
+ };
53
+ }
@@ -0,0 +1,14 @@
1
+ import { Client, CliConfig } from './types';
2
+ export declare type GetGraphQLEndpoint = (params: CliConfig, projectId?: string) => string;
3
+ export declare const getGraphQLEndpoint: GetGraphQLEndpoint;
4
+ export declare const getGraphQLAdminEndpoint: GetGraphQLEndpoint;
5
+ export interface GraphQLConnectorOptions {
6
+ retries?: number;
7
+ timeout?: number;
8
+ cache?: boolean;
9
+ }
10
+ export declare const createConnectorFactory: (getGraphQLEndpoint: GetGraphQLEndpoint) => (params: CliConfig, authToken: string, projectId?: string | undefined, options?: GraphQLConnectorOptions | undefined) => Client;
11
+ export declare const createConnector: (params: CliConfig, authToken: string, projectId?: string | undefined, options?: GraphQLConnectorOptions | undefined) => Client;
12
+ export declare const createAdminConnector: (params: CliConfig, authToken: string, projectId?: string | undefined, options?: GraphQLConnectorOptions | undefined) => Client;
13
+ export declare function graphQLQuery<Variables extends Record<string, unknown>, Data>(query: string): (client: Client, variables: Variables) => Promise<Data>;
14
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAE1C,oBAAY,kBAAkB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAOnF,eAAO,MAAM,kBAAkB,oBAA0C,CAAC;AAC1E,eAAO,MAAM,uBAAuB,oBAAgD,CAAC;AAErF,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAOD,eAAO,MAAM,sBAAsB,uBAAwB,kBAAkB,cACnE,SAAS,aACN,MAAM,oFAGhB,MAkCF,CAAC;AAEF,eAAO,MAAM,eAAe,WAxClB,SAAS,aACN,MAAM,oFAGhB,MAoCsE,CAAC;AAC1E,eAAO,MAAM,oBAAoB,WAzCvB,SAAS,aACN,MAAM,oFAGhB,MAqCgF,CAAC;AAEpF,wBAAgB,YAAY,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YACnE,MAAM,aAAa,SAAS,KAAG,QAAQ,IAAI,CAAC,CAOnE"}
package/lib/graphql.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.graphQLQuery = graphQLQuery;
7
+ exports.createAdminConnector = exports.createConnector = exports.createConnectorFactory = exports.getGraphQLAdminEndpoint = exports.getGraphQLEndpoint = void 0;
8
+
9
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
10
+
11
+ var _asyncRetry = _interopRequireDefault(require("async-retry"));
12
+
13
+ var _errors = require("./errors");
14
+
15
+ var _api = require("./util/api");
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ const getGraphQLEndpointFactory = path => (params, projectId) => {
20
+ const project = projectId ? `project/${projectId}/` : '';
21
+ return `${params.endpoint}/${project}${path}`;
22
+ };
23
+
24
+ const getGraphQLEndpoint = getGraphQLEndpointFactory('v3/graphql');
25
+ exports.getGraphQLEndpoint = getGraphQLEndpoint;
26
+ const getGraphQLAdminEndpoint = getGraphQLEndpointFactory('v3/admin-graphql');
27
+ exports.getGraphQLAdminEndpoint = getGraphQLAdminEndpoint;
28
+ const defaultOptions = {
29
+ retries: 3,
30
+ timeout: 0
31
+ };
32
+
33
+ const createConnectorFactory = getGraphQLEndpoint => (params, authToken, projectId, options) => {
34
+ const endpoint = getGraphQLEndpoint(params, projectId);
35
+ const authHeader = (0, _api.getAuthHeader)(authToken);
36
+ const {
37
+ timeout,
38
+ retries
39
+ } = { ...defaultOptions,
40
+ ...options
41
+ };
42
+ return async (params) => (0, _asyncRetry.default)(async bail => {
43
+ const res = await (0, _nodeFetch.default)(endpoint, {
44
+ method: 'POST',
45
+ timeout,
46
+ body: JSON.stringify(params),
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ ...authHeader
50
+ }
51
+ });
52
+ const body = await res.json();
53
+
54
+ if (res.ok) {
55
+ return body;
56
+ }
57
+
58
+ const error = new _errors.HTTPError(`${res.statusText}: ${body.message}`, res.status);
59
+
60
+ if (res.status === 401 || res.status === 403) {
61
+ // bail to stop retrying
62
+ bail(error);
63
+ return;
64
+ }
65
+
66
+ throw error;
67
+ }, {
68
+ retries
69
+ });
70
+ };
71
+
72
+ exports.createConnectorFactory = createConnectorFactory;
73
+ const createConnector = createConnectorFactory(getGraphQLEndpoint);
74
+ exports.createConnector = createConnector;
75
+ const createAdminConnector = createConnectorFactory(getGraphQLAdminEndpoint);
76
+ exports.createAdminConnector = createAdminConnector;
77
+
78
+ function graphQLQuery(query) {
79
+ return async (client, variables) => {
80
+ const {
81
+ data,
82
+ errors
83
+ } = await client({
84
+ query,
85
+ variables
86
+ });
87
+
88
+ if (errors) {
89
+ throw new Error(errors.map(error => error.message).join(', '));
90
+ }
91
+
92
+ return data.result;
93
+ };
94
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
package/lib/index.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _meow = _interopRequireDefault(require("meow"));
5
+
6
+ var _main = _interopRequireDefault(require("./main"));
7
+
8
+ var _config = require("./config");
9
+
10
+ var _checkVersion = require("./check-version");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const help = `
15
+ Usage
16
+ $ takeshape <comand>
17
+
18
+ Commands
19
+ login
20
+ logout
21
+ link
22
+ unlink
23
+ build
24
+ watch
25
+ schema
26
+ status
27
+ import
28
+ export
29
+
30
+ Options
31
+ --token, -t TakeShape API auth token
32
+ --cli-login, -l Log in using CLI (do not open browser)
33
+ --site, -s TakeShape static site id
34
+ --file, -f path to tsg.yml
35
+ --output, -o build output path
36
+ --endpoint, -e endpoint
37
+ --version, -v version number
38
+ --cache -c use file cache (default false)
39
+ --watchContent, -W rebuild on content change (watch only)
40
+
41
+ import Options
42
+ --schema import a takeshape schema from a directory or JSON file to the currently linked project
43
+ use either --schema or --project not both, must be combined with --from
44
+ --project import a takeshape project from given directory, zip or url
45
+ use either --project or --schema not both, must be combined with --from
46
+ --from specifies the file, directory, zip or url to import
47
+ --name for use with --project specifies a new name for the imported project
48
+
49
+ export Options
50
+ --schema export a takeshape schema from a directory or JSON file
51
+ use either --schema or --project not both, must be combined with --to
52
+ --project export a takeshape project zip
53
+ use either --project or --schema not both, must be combined with --to
54
+ --withoutData when using --project skip exporting the data
55
+ --to specifies the directory to write the exported data to
56
+
57
+ Examples
58
+ $ takeshape build --file path/to/tsg.yml
59
+
60
+ `;
61
+ const minimistOptions = {
62
+ alias: {
63
+ t: 'token',
64
+ l: 'cli-login',
65
+ s: 'site',
66
+ f: 'file',
67
+ o: 'output',
68
+ e: 'endpoint',
69
+ v: 'version',
70
+ c: 'cache',
71
+ W: 'watchContent'
72
+ }
73
+ };
74
+ const cli = (0, _meow.default)(help, minimistOptions);
75
+ const cwd = process.cwd();
76
+ const command = cli.input[0];
77
+ (0, _checkVersion.checkVersion)(process.version);
78
+ void (0, _main.default)(command, (0, _config.loadConfig)(cwd, cli), cli);
package/lib/log.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function log(...args: any): void;
2
+ export declare function logError(...args: any): void;
3
+ export default log;
4
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAGtC;AAED,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAG3C;AAED,eAAe,GAAG,CAAC"}
package/lib/log.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.log = log;
7
+ exports.logError = logError;
8
+ exports.default = void 0;
9
+
10
+ function log(...args) {
11
+ // eslint-disable-next-line no-console
12
+ console.log.apply(null, args);
13
+ }
14
+
15
+ function logError(...args) {
16
+ // eslint-disable-next-line no-console
17
+ console.error.apply(null, args);
18
+ }
19
+
20
+ var _default = log;
21
+ exports.default = _default;
package/lib/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export default function _default(command: any, params: any, cli: any): Promise<void>;
2
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.js"],"names":[],"mappings":"AAgBA,qFAQC"}
package/lib/main.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _log = _interopRequireDefault(require("./log"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const commandPath = {
13
+ build: 'build-or-watch',
14
+ watch: 'build-or-watch',
15
+ login: 'login',
16
+ logout: 'logout',
17
+ link: 'link',
18
+ unlink: 'unlink',
19
+ deploy: 'deploy',
20
+ schema: 'schema',
21
+ status: 'status',
22
+ import: 'import',
23
+ export: 'export'
24
+ };
25
+
26
+ async function _default(command, params, cli) {
27
+ const path = commandPath[command];
28
+
29
+ if (path) {
30
+ const fn = require(`./commands/${path}`).default;
31
+
32
+ await fn(command, params, cli.flags);
33
+ } else {
34
+ (0, _log.default)('No such command:' + cli.help);
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import inquirer, { QuestionCollection } from 'inquirer';
2
+ export declare function prompt(options: QuestionCollection): Promise<inquirer.Answers> & {
3
+ ui: import("inquirer/lib/ui/prompt");
4
+ };
5
+ export declare function confirm(message: string): Promise<boolean>;
6
+ export interface Choice {
7
+ name: string;
8
+ value: string;
9
+ }
10
+ export declare function promptList(message: string, choices: Choice[]): Promise<Choice>;
11
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAC,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAEtD,wBAAgB,MAAM,CAAC,OAAO,EAAE,kBAAkB;;EAEjD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ/D;AACD,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CASpF"}
package/lib/prompt.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.prompt = prompt;
7
+ exports.confirm = confirm;
8
+ exports.promptList = promptList;
9
+
10
+ var _inquirer = _interopRequireDefault(require("inquirer"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function prompt(options) {
15
+ return _inquirer.default.prompt(options);
16
+ }
17
+
18
+ async function confirm(message) {
19
+ const {
20
+ isConfirmed
21
+ } = await prompt({
22
+ type: 'confirm',
23
+ name: 'isConfirmed',
24
+ message
25
+ });
26
+ return isConfirmed;
27
+ }
28
+
29
+ async function promptList(message, choices) {
30
+ const {
31
+ id
32
+ } = await prompt({
33
+ type: 'list',
34
+ name: 'id',
35
+ message,
36
+ choices
37
+ });
38
+ return choices.find(choice => choice.value === id);
39
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { ApiKey } from './util/data';
2
+ export declare type Handler<Flags = unknown> = (command: string, params: CliConfig, flags: Flags) => Promise<void>;
3
+ export interface CliConfig {
4
+ buildPath: string;
5
+ configFilePath: string;
6
+ appUrl: string;
7
+ endpoint: string;
8
+ authToken?: string;
9
+ personalAccessTokenId?: string;
10
+ linkedApiKey?: ApiKey;
11
+ cliLogin?: boolean;
12
+ siteId?: string;
13
+ projectName?: string;
14
+ projectId?: string;
15
+ siteName?: string;
16
+ cache: boolean;
17
+ watchContent: boolean;
18
+ }
19
+ export declare type AuthedHandler<Flags = unknown> = (command: string, params: LoggedInCliConfig, flags: Flags) => Promise<void>;
20
+ export declare type LinkedHandler<Flags = unknown> = (command: string, params: LinkedCliConfig, flags: Flags) => Promise<void>;
21
+ export interface LoggedInCliConfig extends CliConfig {
22
+ authToken: string;
23
+ personalAccessTokenId: string;
24
+ }
25
+ export interface LinkedCliConfig extends CliConfig {
26
+ projectId: string;
27
+ linkedApiKey: ApiKey;
28
+ }
29
+ export declare type LoggedInAndLinkedConfig = LoggedInCliConfig & LinkedCliConfig;
30
+ export declare function isLinkedCliConfig(cliConfig: CliConfig): cliConfig is LinkedCliConfig;
31
+ export declare function isLoggedInCliConfig(cliConfig: CliConfig): cliConfig is LoggedInCliConfig;
32
+ export declare function isLoggedInAndLinkedConfig(cliConfig: CliConfig): cliConfig is LoggedInAndLinkedConfig;
33
+ export interface GraphQLRequestParams {
34
+ query: string;
35
+ variables?: Record<string, unknown>;
36
+ }
37
+ export interface GraphQLResponse {
38
+ data: any;
39
+ errors?: GraphQLError[];
40
+ }
41
+ export interface GraphQLError {
42
+ message: string;
43
+ }
44
+ export declare type Client = (params: GraphQLRequestParams) => Promise<GraphQLResponse>;
45
+ //# sourceMappingURL=types.d.ts.map