@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
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loginBrowser = loginBrowser;
7
+ exports.attemptLogin = attemptLogin;
8
+ exports.attemptOpenForgotPassword = attemptOpenForgotPassword;
9
+ exports.loginCli = loginCli;
10
+ exports.loginQuestions = void 0;
11
+
12
+ var _http = _interopRequireDefault(require("http"));
13
+
14
+ var _open = _interopRequireDefault(require("open"));
15
+
16
+ var _prompt = require("../prompt");
17
+
18
+ var _emailValidator = require("email-validator");
19
+
20
+ var _getPort = _interopRequireDefault(require("get-port"));
21
+
22
+ var _auth = require("../auth");
23
+
24
+ var _messages = require("./messages");
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ async function loginBrowser(params) {
29
+ // Port for login page to communicate with the CLI
30
+ const port = await (0, _getPort.default)(); // Open a browser to the login page
31
+
32
+ await (0, _open.default)(`${params.appUrl}/login?returnToCli=true&cliPort=${port}`, {
33
+ wait: false
34
+ }); // Spin up an ad-hoc server to recive the auth token from the login page
35
+
36
+ return new Promise((resolve, reject) => {
37
+ const server = _http.default.createServer((req, res) => {
38
+ res.setHeader('Content-Type', 'text/plain');
39
+ res.setHeader('Access-Control-Allow-Origin', params.appUrl);
40
+ res.setHeader('Access-Control-Allow-Headers', 'x-takeshape-token');
41
+
42
+ if (req.method === 'OPTIONS') {
43
+ res.statusCode = 200;
44
+ res.end('Success');
45
+ return;
46
+ }
47
+
48
+ const token = req.headers['x-takeshape-token'];
49
+
50
+ if (typeof token === 'string') {
51
+ res.statusCode = 200;
52
+ res.end('Success');
53
+ (0, _messages.loginSuccess)();
54
+ resolve(token);
55
+ } else {
56
+ res.statusCode = 400;
57
+ res.end('Bad Request');
58
+ reject(new Error('Did not receive auth token from webapp.'));
59
+ }
60
+
61
+ server.close();
62
+ });
63
+
64
+ server.listen(port, '127.0.0.1', () => {
65
+ (0, _messages.waitingForLogin)();
66
+ });
67
+ });
68
+ }
69
+
70
+ const loginQuestions = [{
71
+ type: 'input',
72
+ name: 'email',
73
+ message: 'Enter your TakeShape email:',
74
+
75
+ validate(input) {
76
+ return (0, _emailValidator.validate)(input) || 'Please enter a valid email';
77
+ }
78
+
79
+ }, {
80
+ type: 'password',
81
+ name: 'password',
82
+ message: 'Enter your TakeShape password:'
83
+ }];
84
+ exports.loginQuestions = loginQuestions;
85
+
86
+ async function attemptLogin(params) {
87
+ const answers = await (0, _prompt.prompt)(loginQuestions);
88
+ return (0, _auth.login)(params.endpoint, answers.email, answers.password);
89
+ }
90
+
91
+ async function attemptOpenForgotPassword(params) {
92
+ const isConfirmed = await (0, _prompt.confirm)('Would you like to open TakeShape to set a password?');
93
+
94
+ if (isConfirmed) {
95
+ await (0, _open.default)(params.appUrl + '/forgot-password', {
96
+ wait: false
97
+ });
98
+ }
99
+ }
100
+
101
+ async function loginCli(params, maxAttempts) {
102
+ let attempts = 0;
103
+
104
+ do {
105
+ attempts++;
106
+
107
+ try {
108
+ // eslint-disable-next-line no-await-in-loop
109
+ return await attemptLogin(params);
110
+ } catch (e) {
111
+ if (e.statusCode === 403) {
112
+ attempts--;
113
+ (0, _messages.missingPasswordMsg)(); // eslint-disable-next-line no-await-in-loop
114
+
115
+ await attemptOpenForgotPassword(params);
116
+ } else {
117
+ (0, _messages.invalidLoginMsg)();
118
+ }
119
+ }
120
+ } while (attempts < maxAttempts);
121
+
122
+ (0, _messages.forgotPasswordWarning)(params);
123
+ }
@@ -0,0 +1,13 @@
1
+ import { CliConfig } from '../types';
2
+ export declare function warning(msg: string): () => void;
3
+ export declare function info(msg: string): () => void;
4
+ export declare const waitingForLogin: () => void;
5
+ export declare const loginSuccess: () => void;
6
+ export declare const invalidLoginMsg: () => void;
7
+ export declare const missingPasswordMsg: () => void;
8
+ export declare const writingFilesMsg: () => void;
9
+ export declare const writingHomeConfigMsg: (path: string) => void;
10
+ export declare const consoleWarning: () => void;
11
+ export declare function forgotPasswordWarning(params: CliConfig): void;
12
+ export declare function noProjectsError(params: CliConfig): void;
13
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/util/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,cAMlC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,cAI/B;AAED,eAAO,MAAM,eAAe,YAAiD,CAAC;AAC9E,eAAO,MAAM,YAAY,YAAkC,CAAC;AAE5D,eAAO,MAAM,eAAe,YAA6C,CAAC;AAC1E,eAAO,MAAM,kBAAkB,YAE9B,CAAC;AAEF,eAAO,MAAM,eAAe,YAAgD,CAAC;AAC7E,eAAO,MAAM,oBAAoB,SAAU,MAAM,SAEhD,CAAC;AAEF,eAAO,MAAM,cAAc,YAM1B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,QAEtD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,QAEhD"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.warning = warning;
7
+ exports.info = info;
8
+ exports.forgotPasswordWarning = forgotPasswordWarning;
9
+ exports.noProjectsError = noProjectsError;
10
+ exports.consoleWarning = exports.writingHomeConfigMsg = exports.writingFilesMsg = exports.missingPasswordMsg = exports.invalidLoginMsg = exports.loginSuccess = exports.waitingForLogin = void 0;
11
+
12
+ var _chalk = _interopRequireDefault(require("chalk"));
13
+
14
+ var _log = _interopRequireDefault(require("../log"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function warning(msg) {
19
+ return () => {
20
+ msg.split('\n').forEach(line => {
21
+ (0, _log.default)(_chalk.default.black.bgYellow(line));
22
+ });
23
+ };
24
+ }
25
+
26
+ function info(msg) {
27
+ return () => {
28
+ (0, _log.default)(msg);
29
+ };
30
+ }
31
+
32
+ const waitingForLogin = info('Opening a web browser to log you in...');
33
+ exports.waitingForLogin = waitingForLogin;
34
+ const loginSuccess = info('Successfully logged in.');
35
+ exports.loginSuccess = loginSuccess;
36
+ const invalidLoginMsg = info('Invalid email/password combination');
37
+ exports.invalidLoginMsg = invalidLoginMsg;
38
+ const missingPasswordMsg = info('No password set in TakeShape. Follow the forgot password flow to set a password.');
39
+ exports.missingPasswordMsg = missingPasswordMsg;
40
+ const writingFilesMsg = info('Writing .takeshaperc, .graphqlconfig.');
41
+ exports.writingFilesMsg = writingFilesMsg;
42
+
43
+ const writingHomeConfigMsg = path => {
44
+ (0, _log.default)(`Saving personal access token to ${path}`);
45
+ };
46
+
47
+ exports.writingHomeConfigMsg = writingHomeConfigMsg;
48
+ const consoleWarning = warning('**************************************************************************************************\n' + ' Add the following to your vcs ignore file: \n' + ' .takeshaperc \n' + ' .graphqlconfig \n' + '**************************************************************************************************');
49
+ exports.consoleWarning = consoleWarning;
50
+
51
+ function forgotPasswordWarning(params) {
52
+ (0, _log.default)(`If you forgot your credentials please visit ${params.appUrl}/forgot-password`);
53
+ }
54
+
55
+ function noProjectsError(params) {
56
+ (0, _log.default)(`No projects configured. Set one up at ${params.appUrl}/projects`);
57
+ }
@@ -0,0 +1,2 @@
1
+ export default function oraWrapper(fn: any, start: any, success: any, failure: any): (...args: any[]) => Promise<void>;
2
+ //# sourceMappingURL=ora-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ora-wrapper.d.ts","sourceRoot":"","sources":["../../../src/util/ora-wrapper.js"],"names":[],"mappings":"AAIA,uHAWC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = oraWrapper;
7
+
8
+ var _ora = _interopRequireDefault(require("ora"));
9
+
10
+ var _formatError = _interopRequireDefault(require("./format-error"));
11
+
12
+ var _log = require("../log");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function oraWrapper(fn, start, success, failure) {
17
+ return async (...args) => {
18
+ const spinner = (0, _ora.default)(start).start();
19
+
20
+ try {
21
+ await fn(...args);
22
+ spinner.succeed(success);
23
+ } catch (e) {
24
+ spinner.fail(failure);
25
+ (0, _log.logError)('Error:', (0, _formatError.default)(e));
26
+ }
27
+ };
28
+ }
@@ -0,0 +1,4 @@
1
+ export function handleWarning(type: any, error: any): void;
2
+ export function handleAction(callback: any): (action: any) => void;
3
+ export function subscribe(params: any, callback: any): Promise<void>;
4
+ //# sourceMappingURL=pusher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pusher.d.ts","sourceRoot":"","sources":["../../../src/util/pusher.js"],"names":[],"mappings":"AAIA,2DAIC;AAID,mEAUC;AAED,qEAYC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.handleWarning = handleWarning;
7
+ exports.handleAction = handleAction;
8
+ exports.subscribe = subscribe;
9
+
10
+ var _api = _interopRequireDefault(require("./api"));
11
+
12
+ var _pusherClient = _interopRequireDefault(require("pusher-client"));
13
+
14
+ var _log = _interopRequireDefault(require("../log"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function handleWarning(type, error) {
19
+ if (type === 'Error' && error.type === 'WebSocketError') {
20
+ (0, _log.default)('Disconnected from TakeShape. Restart this process to resume live content updates.');
21
+ }
22
+ }
23
+
24
+ _pusherClient.default.warn = handleWarning;
25
+
26
+ function handleAction(callback) {
27
+ return action => {
28
+ if (action.type === 'content/CONTENT_UPDATED' || action.type === 'content/CONTENT_CREATED' || action.type === 'content/CONTENT_DELETED') {
29
+ callback(action);
30
+ }
31
+ };
32
+ }
33
+
34
+ async function subscribe(params, callback) {
35
+ var _params$linkedApiKey;
36
+
37
+ const config = await (0, _api.default)(params, 'GET', `/project/${params.projectId}/pusher-client-config`);
38
+ const pusher = new _pusherClient.default(config.key, {
39
+ authEndpoint: `${params.endpoint}/project/channel-auth?auth=${(_params$linkedApiKey = params.linkedApiKey) === null || _params$linkedApiKey === void 0 ? void 0 : _params$linkedApiKey.apiKey}`,
40
+ cluster: config.cluster,
41
+ encrypted: true
42
+ });
43
+ const channel = pusher.subscribe(`presence-project.${params.projectId}`);
44
+ channel.bind('server-action', handleAction(callback));
45
+ }
@@ -0,0 +1,2 @@
1
+ export function createRunner(name: any, task: any): (...args: any[]) => Promise<void>;
2
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/util/runner.js"],"names":[],"mappings":"AAIA,sFA0BC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createRunner = createRunner;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ var _formatError = _interopRequireDefault(require("./format-error"));
11
+
12
+ var _log = _interopRequireDefault(require("../log"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function createRunner(name, task) {
17
+ let running = false;
18
+ return async (...args) => {
19
+ if (!running) {
20
+ running = true;
21
+ const startTime = Date.now();
22
+ (0, _log.default)(`${name} - Started!`);
23
+
24
+ try {
25
+ const stats = await task(...args);
26
+ const totalSeconds = (Date.now() - startTime) / 1000;
27
+ (0, _log.default)(`${name} - ` + _chalk.default.green(`Generated ${stats.pagesGenerated} pages in ${totalSeconds}s`));
28
+ const warnings = stats.warnings;
29
+
30
+ if (warnings !== null && warnings !== void 0 && warnings.length) {
31
+ (0, _log.default)(`${name} - ` + _chalk.default.yellow('Warnings:'));
32
+ warnings.forEach(warning => {
33
+ (0, _log.default)(_chalk.default.yellow(`${warning.source}: ${warning.message}`));
34
+ });
35
+ }
36
+
37
+ running = false;
38
+ } catch (error) {
39
+ (0, _log.default)(`${name} - ` + _chalk.default.red(`Error:\n${(0, _formatError.default)(error)}`));
40
+ running = false;
41
+ }
42
+ }
43
+ };
44
+ }
@@ -0,0 +1,4 @@
1
+ import { Choice } from '../prompt';
2
+ import { LoggedInCliConfig } from '../types';
3
+ export declare function selectProject(params: LoggedInCliConfig): Promise<Choice | undefined>;
4
+ //# sourceMappingURL=select-project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-project.d.ts","sourceRoot":"","sources":["../../../src/util/select-project.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAa,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAE3C,wBAAsB,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAQ1F"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.selectProject = selectProject;
7
+
8
+ var _data = require("./data");
9
+
10
+ var _messages = require("./messages");
11
+
12
+ var _prompt = require("../prompt");
13
+
14
+ async function selectProject(params) {
15
+ const projects = await (0, _data.fetchProjects)(params);
16
+
17
+ if (!projects.length) {
18
+ (0, _messages.noProjectsError)(params);
19
+ return;
20
+ }
21
+
22
+ return (0, _prompt.promptList)('Select a project:', projects);
23
+ }
@@ -0,0 +1,7 @@
1
+ interface SpinQueryRes {
2
+ status: string;
3
+ message?: string;
4
+ }
5
+ declare function spin(spinQuery: () => null | Promise<SpinQueryRes>): Promise<void>;
6
+ export default spin;
7
+ //# sourceMappingURL=spin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spin.d.ts","sourceRoot":"","sources":["../../../src/util/spin.ts"],"names":[],"mappings":"AAIA,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,iBAAe,IAAI,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBhF;AAED,eAAe,IAAI,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _util = require("@takeshape/util");
9
+
10
+ const SPINTERVAL = 100;
11
+
12
+ async function spin(spinQuery) {
13
+ const res = await spinQuery();
14
+ const status = res === null ? 'running' : res.status;
15
+
16
+ switch (status) {
17
+ case 'running':
18
+ await (0, _util.delay)(SPINTERVAL);
19
+ await spin(spinQuery);
20
+ break;
21
+
22
+ case 'completed':
23
+ break;
24
+
25
+ case 'timeout':
26
+ throw new Error('Export timed out');
27
+
28
+ case 'error':
29
+ if (res !== null && res !== void 0 && res.message) {
30
+ throw new Error(res.message);
31
+ } else {
32
+ throw new Error('An unknown error occurred');
33
+ }
34
+
35
+ default:
36
+ throw new Error(`Unexpected export status: ${status}`);
37
+ }
38
+ }
39
+
40
+ var _default = spin;
41
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ import { CliConfig } from '../types';
2
+ export declare function createTempFile(filePath: string): [string, () => void];
3
+ export declare function getUploadUrl(params: CliConfig): Promise<string>;
4
+ export declare function uploadFile(filePath: string, uploadUrl: string): Promise<number>;
5
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/util/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAQnC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAGrE;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAOrE;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWrF"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createTempFile = createTempFile;
7
+ exports.getUploadUrl = getUploadUrl;
8
+ exports.uploadFile = uploadFile;
9
+
10
+ var _api = _interopRequireDefault(require("./api"));
11
+
12
+ var _tmp = _interopRequireDefault(require("tmp"));
13
+
14
+ var _path = _interopRequireDefault(require("path"));
15
+
16
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
17
+
18
+ var _request = _interopRequireDefault(require("request"));
19
+
20
+ var _streams = require("@takeshape/streams");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ function createTempFile(filePath) {
25
+ const tmpDir = _tmp.default.dirSync({
26
+ unsafeCleanup: true
27
+ });
28
+
29
+ return [_path.default.join(tmpDir.name, filePath), tmpDir.removeCallback];
30
+ }
31
+
32
+ async function getUploadUrl(params) {
33
+ try {
34
+ const {
35
+ uploadUrl
36
+ } = await (0, _api.default)(params, 'GET', `/project/${params.projectId}/ssg/${params.siteId}/upload-url`);
37
+ return uploadUrl;
38
+ } catch (e) {
39
+ throw new Error(`Failed to get upload url: ${e.message}`);
40
+ }
41
+ }
42
+
43
+ async function uploadFile(filePath, uploadUrl) {
44
+ const stats = _fsExtra.default.statSync(filePath);
45
+
46
+ const putStream = (0, _request.default)({
47
+ method: 'PUT',
48
+ url: uploadUrl,
49
+ headers: {
50
+ 'Content-Length': stats.size
51
+ }
52
+ });
53
+ await (0, _streams.pump)(_fsExtra.default.createReadStream(filePath), putStream);
54
+ return stats.size;
55
+ }
@@ -0,0 +1,2 @@
1
+ export function createWatcher(description: any, handler: any, path: any): void;
2
+ //# sourceMappingURL=watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/util/watcher.js"],"names":[],"mappings":"AAGA,+EAkBC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createWatcher = createWatcher;
7
+
8
+ var _chokidar = _interopRequireDefault(require("chokidar"));
9
+
10
+ var _log = require("../log");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function createWatcher(description, handler, path) {
15
+ const watcher = _chokidar.default.watch(path);
16
+
17
+ let ready = false;
18
+ watcher.on('all', (event, path) => {
19
+ if (ready) {
20
+ handler(event, path);
21
+ }
22
+ });
23
+ watcher.on('error', error => {
24
+ (0, _log.logError)(`Error Watching ${description}:`, error);
25
+ });
26
+ watcher.once('ready', () => {
27
+ (0, _log.log)('Watching ' + description);
28
+ ready = true;
29
+ });
30
+ }
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@takeshape/cli",
3
+ "version": "7.194.0",
4
+ "description": "TakeShape CLI",
5
+ "homepage": "https://www.takeshape.io",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "github.com:takeshape/takeshape.git"
9
+ },
10
+ "author": "asprouse",
11
+ "license": "MIT",
12
+ "engines": {
13
+ "node": ">=12"
14
+ },
15
+ "bin": {
16
+ "tsg": "./lib/deprecated.js",
17
+ "takeshape": "./lib/index.js"
18
+ },
19
+ "files": [
20
+ "lib"
21
+ ],
22
+ "dependencies": {
23
+ "@takeshape/schema": "7.194.0",
24
+ "@takeshape/ssg": "7.194.0",
25
+ "@takeshape/streams": "7.194.0",
26
+ "@takeshape/util": "7.194.0",
27
+ "archiver": "^1.3.0",
28
+ "async-retry": "^1.2.1",
29
+ "bluebird": "^3.4.6",
30
+ "chalk": "^2.4.2",
31
+ "chokidar": "^2.1.5",
32
+ "commander": "^2.9.0",
33
+ "dotenv": "^6.0.0",
34
+ "dotenv-stringify": "^1.0.0",
35
+ "email-validator": "^2.0.4",
36
+ "fs-extra": "^7.0.1",
37
+ "get-port": "^5.1.1",
38
+ "glob": "^7.1.2",
39
+ "ignore": "^5.1.8",
40
+ "inquirer": "^7.3.3",
41
+ "is-docker": "^2.1.1",
42
+ "jsonwebtoken": "^8.1.1",
43
+ "lodash": "^4.17.20",
44
+ "lokka": "^1.7.0",
45
+ "lokka-transport-http": "^1.6.1",
46
+ "meow": "^9.0.0",
47
+ "node-fetch": "^2.6.1",
48
+ "object-hash": "^1.3.1",
49
+ "open": "^7.0.3",
50
+ "ora": "^3.4.0",
51
+ "pretty-bytes": "^5.3.0",
52
+ "pusher-client": "^1.1.0",
53
+ "request": "^2.88.0",
54
+ "semver": "^6.3.0",
55
+ "stream-to-promise": "^2.2.0",
56
+ "tmp": "^0.0.33"
57
+ },
58
+ "devDependencies": {
59
+ "@types/archiver": "^3.1.0",
60
+ "@types/async-retry": "^1.4.2",
61
+ "@types/fs-extra": "^8.1.0",
62
+ "@types/glob": "^7.1.1",
63
+ "@types/inquirer": "^7.3.1",
64
+ "@types/jsonwebtoken": "^8.3.9",
65
+ "@types/lodash": "^4.14.165",
66
+ "@types/node": "^12.7.1",
67
+ "@types/node-fetch": "^2.5.6",
68
+ "@types/request": "^2.48.4",
69
+ "@types/semver": "^6.0.1",
70
+ "@types/stream-to-promise": "^2.2.1",
71
+ "@types/tmp": "^0.1.0",
72
+ "@types/unzipper": "^0.10.3",
73
+ "cross-env": "^5.2.0",
74
+ "graphql": "14.7.0",
75
+ "unzipper": "^0.10.11"
76
+ },
77
+ "scripts": {
78
+ "test": "jest",
79
+ "test:ci": "JEST_JUNIT_OUTPUT_DIR=\"${HOME}/test-results/${npm_package_name#*\\/}\" JEST_JUNIT_OUTPUT_NAME=jest-results.xml jest --ci --reporters=default --reporters=jest-junit",
80
+ "typecheck": "tsc --noEmit",
81
+ "lint": "eslint . --ext .js,.ts",
82
+ "lint:code:ci": "eslint . --ext .js,.ts --format junit -o \"${HOME}/test-results/${npm_package_name#*\\/}/eslint-results.xml\"",
83
+ "clean": "rimraf build lib *.tsbuildinfo",
84
+ "build": "pnpm build:js && pnpm build:types && pnpm build:copy",
85
+ "build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
86
+ "build:js": "cross-env BABEL_MODULES=commonjs babel src --out-dir lib --extensions \".js,.ts\" --ignore '**/__tests__'",
87
+ "build:copy": "cp -rf build/src/* lib/",
88
+ "will-it-blend": "pnpm typecheck && pnpm lint -- --quiet && pnpm test -- --silent --coverage false"
89
+ }
90
+ }