@youcan/cli 1.0.8 → 1.1.0-beta.2

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 (116) hide show
  1. package/bin/exec.cmd +3 -0
  2. package/bin/exec.js +8 -0
  3. package/dist/cli/commands/auth/login.d.ts +4 -2
  4. package/dist/cli/commands/auth/login.js +7 -85
  5. package/dist/cli/commands/auth/logout.d.ts +4 -2
  6. package/dist/cli/commands/auth/logout.js +9 -18
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.js +20 -2
  9. package/package.json +56 -38
  10. package/bin/index.js +0 -2
  11. package/dist/cli/commands/apps/create.d.ts +0 -2
  12. package/dist/cli/commands/apps/create.js +0 -65
  13. package/dist/cli/commands/apps/install.d.ts +0 -2
  14. package/dist/cli/commands/apps/install.js +0 -28
  15. package/dist/cli/commands/auth/types.d.ts +0 -6
  16. package/dist/cli/commands/index.d.ts +0 -12
  17. package/dist/cli/commands/index.js +0 -14
  18. package/dist/cli/commands/store/info.d.ts +0 -2
  19. package/dist/cli/commands/store/info.js +0 -29
  20. package/dist/cli/commands/store/switch.d.ts +0 -2
  21. package/dist/cli/commands/store/switch.js +0 -59
  22. package/dist/cli/commands/store/types.d.ts +0 -4
  23. package/dist/cli/commands/theme/delete.d.ts +0 -2
  24. package/dist/cli/commands/theme/delete.js +0 -46
  25. package/dist/cli/commands/theme/dev.d.ts +0 -2
  26. package/dist/cli/commands/theme/dev.js +0 -199
  27. package/dist/cli/commands/theme/init.d.ts +0 -2
  28. package/dist/cli/commands/theme/init.js +0 -86
  29. package/dist/cli/commands/theme/list.d.ts +0 -2
  30. package/dist/cli/commands/theme/list.js +0 -35
  31. package/dist/cli/commands/theme/pack.d.ts +0 -2
  32. package/dist/cli/commands/theme/pack.js +0 -31
  33. package/dist/cli/commands/theme/pull.d.ts +0 -2
  34. package/dist/cli/commands/theme/pull.js +0 -56
  35. package/dist/cli/commands/theme/types.d.ts +0 -17
  36. package/dist/cli/commands/types.d.ts +0 -22
  37. package/dist/cli/index.d.ts +0 -12
  38. package/dist/cli/index.js +0 -53
  39. package/dist/config/index.d.ts +0 -21
  40. package/dist/config/index.js +0 -25
  41. package/dist/config/messages.d.ts +0 -36
  42. package/dist/config/messages.js +0 -37
  43. package/dist/core/client/client.d.ts +0 -23
  44. package/dist/core/client/client.js +0 -83
  45. package/dist/core/client/types.d.ts +0 -80
  46. package/dist/core/themes/preview.d.ts +0 -1
  47. package/dist/core/themes/preview.js +0 -37
  48. package/dist/lib/cli/commands/apps/create.d.ts +0 -2
  49. package/dist/lib/cli/commands/apps/install.d.ts +0 -2
  50. package/dist/lib/cli/commands/auth/login.d.ts +0 -2
  51. package/dist/lib/cli/commands/auth/logout.d.ts +0 -2
  52. package/dist/lib/cli/commands/auth/types.d.ts +0 -6
  53. package/dist/lib/cli/commands/index.d.ts +0 -12
  54. package/dist/lib/cli/commands/store/info.d.ts +0 -2
  55. package/dist/lib/cli/commands/store/switch.d.ts +0 -2
  56. package/dist/lib/cli/commands/store/types.d.ts +0 -4
  57. package/dist/lib/cli/commands/theme/delete.d.ts +0 -2
  58. package/dist/lib/cli/commands/theme/dev.d.ts +0 -2
  59. package/dist/lib/cli/commands/theme/init.d.ts +0 -2
  60. package/dist/lib/cli/commands/theme/list.d.ts +0 -2
  61. package/dist/lib/cli/commands/theme/pack.d.ts +0 -2
  62. package/dist/lib/cli/commands/theme/pull.d.ts +0 -2
  63. package/dist/lib/cli/commands/theme/types.d.ts +0 -17
  64. package/dist/lib/cli/commands/types.d.ts +0 -22
  65. package/dist/lib/cli/index.d.ts +0 -12
  66. package/dist/lib/config/index.d.ts +0 -21
  67. package/dist/lib/config/messages.d.ts +0 -36
  68. package/dist/lib/core/client/client.d.ts +0 -23
  69. package/dist/lib/core/client/types.d.ts +0 -80
  70. package/dist/lib/core/themes/preview.d.ts +0 -1
  71. package/dist/lib/index.d.ts +0 -1
  72. package/dist/lib/utils/common.d.ts +0 -22
  73. package/dist/lib/utils/git/cloneRepository.d.ts +0 -6
  74. package/dist/lib/utils/helpers.d.ts +0 -3
  75. package/dist/lib/utils/http.d.ts +0 -11
  76. package/dist/lib/utils/network.d.ts +0 -2
  77. package/dist/lib/utils/system/deleteFile.d.ts +0 -5
  78. package/dist/lib/utils/system/ls.d.ts +0 -1
  79. package/dist/lib/utils/system/openLink.d.ts +0 -1
  80. package/dist/lib/utils/system/saveFile.d.ts +0 -1
  81. package/dist/lib/utils/system/stdout.d.ts +0 -20
  82. package/dist/lib/utils/system/writeToFile.d.ts +0 -6
  83. package/dist/lib/utils/system/zipFolder.d.ts +0 -5
  84. package/dist/lib/utils/system.d.ts +0 -1
  85. package/dist/test/commands/auth/login.d.ts +0 -2
  86. package/dist/test/commands/auth/logout.d.ts +0 -2
  87. package/dist/test/commands/help.d.ts +0 -2
  88. package/dist/test/commands/theme/delete.d.ts +0 -2
  89. package/dist/test/commands/theme/dev.d.ts +0 -2
  90. package/dist/test/commands/theme/init.d.ts +0 -2
  91. package/dist/test/index.test.d.ts +0 -1
  92. package/dist/utils/common.d.ts +0 -22
  93. package/dist/utils/common.js +0 -67
  94. package/dist/utils/git/cloneRepository.d.ts +0 -6
  95. package/dist/utils/git/cloneRepository.js +0 -18
  96. package/dist/utils/helpers.d.ts +0 -3
  97. package/dist/utils/helpers.js +0 -35
  98. package/dist/utils/http.d.ts +0 -11
  99. package/dist/utils/http.js +0 -26
  100. package/dist/utils/network.d.ts +0 -2
  101. package/dist/utils/network.js +0 -81
  102. package/dist/utils/system/deleteFile.d.ts +0 -5
  103. package/dist/utils/system/deleteFile.js +0 -13
  104. package/dist/utils/system/ls.d.ts +0 -1
  105. package/dist/utils/system/ls.js +0 -9
  106. package/dist/utils/system/openLink.d.ts +0 -1
  107. package/dist/utils/system/saveFile.d.ts +0 -1
  108. package/dist/utils/system/saveFile.js +0 -9
  109. package/dist/utils/system/stdout.d.ts +0 -17
  110. package/dist/utils/system/stdout.js +0 -35
  111. package/dist/utils/system/writeToFile.d.ts +0 -1
  112. package/dist/utils/system/writeToFile.js +0 -7
  113. package/dist/utils/system/zipFolder.d.ts +0 -5
  114. package/dist/utils/system/zipFolder.js +0 -57
  115. package/dist/utils/system.d.ts +0 -1
  116. package/dist/utils/system.js +0 -18
package/bin/exec.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\exec.js" %*
package/bin/exec.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ process.removeAllListeners('warning');
4
+
5
+ // eslint-disable-next-line import/first
6
+ import execCli from '../dist/index.js';
7
+
8
+ execCli(false);
@@ -1,2 +1,4 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
1
+ import { Cli } from '@youcan/cli-kit';
2
+ export default class Login extends Cli.Command {
3
+ run(): Promise<void>;
4
+ }
@@ -1,88 +1,10 @@
1
- import { exit } from 'node:process';
2
- import prompts from 'prompts';
3
- import config from '../../../config/index.js';
4
- import stdout from '../../../utils/system/stdout.js';
5
- import writeToFile from '../../../utils/system/writeToFile.js';
6
- import messages from '../../../config/messages.js';
7
- import { isPortAvailable, getPidByPort } from '../../../utils/network.js';
8
- import { kill } from '../../../utils/system.js';
9
- import { LoadingSpinner } from '../../../utils/common.js';
1
+ import { Cli, Session } from '@youcan/cli-kit';
10
2
 
11
- function command(cli) {
12
- return {
13
- name: 'login',
14
- group: 'auth',
15
- description: 'Log into a YouCan store',
16
- action: async () => {
17
- if (!(await isPortAvailable(config.OAUTH_CALLBACK_PORT))) {
18
- stdout.warn(`YouCan CLI requires that the port ${config.OAUTH_CALLBACK_PORT} be available`);
19
- const prompt = await prompts({
20
- initial: false,
21
- type: 'confirm',
22
- name: 'terminate',
23
- message: 'Terminate the process to free the port?',
24
- });
25
- if (!prompt.terminate) {
26
- stdout.log('Exiting..');
27
- exit(1);
28
- }
29
- const pid = await getPidByPort(config.OAUTH_CALLBACK_PORT);
30
- if (pid) {
31
- await LoadingSpinner.exec(`Terminating process ${pid}..`, async (spinner) => {
32
- try {
33
- await kill(pid, 'SIGTERM', 30_000);
34
- }
35
- catch (err) {
36
- spinner.error('Could not terminate process, proceeding..');
37
- }
38
- });
39
- }
40
- }
41
- const loading = new LoadingSpinner('Authenticating...');
42
- try {
43
- const inquiries = [
44
- {
45
- type: 'text',
46
- name: 'email',
47
- message: 'Type your email',
48
- validate: value => value !== '',
49
- },
50
- {
51
- type: 'password',
52
- name: 'password',
53
- message: 'Type your password',
54
- validate: value => value !== '',
55
- },
56
- ];
57
- const credentials = await prompts(inquiries);
58
- loading.start();
59
- const response = await cli.client.auth({ email: credentials.email, password: credentials.password });
60
- let token = response.token;
61
- loading.stop();
62
- cli.client.setAccessToken(response.token);
63
- if (response.stores.length > 1) {
64
- const choices = response.stores.map(store => ({
65
- title: store.slug,
66
- value: store.store_id,
67
- }));
68
- const { storeId } = await prompts({
69
- type: 'select',
70
- name: 'storeId',
71
- message: messages.SELECT_STORE,
72
- choices,
73
- });
74
- const selectStoreResponse = await cli.client.selectStore({ id: storeId });
75
- token = selectStoreResponse.token;
76
- }
77
- writeToFile(config.CLI_GLOBAL_CONFIG_PATH, JSON.stringify({ access_token: token }));
78
- stdout.info(messages.LOGIN_SUCCESS);
79
- }
80
- catch (err) {
81
- const error = JSON.parse(err.message);
82
- loading.error(error.detail);
83
- }
84
- },
85
- };
3
+ class Login extends Cli.Command {
4
+ async run() {
5
+ const session = await Session.authenticate(this);
6
+ this.output.info(`Logged in as ${session.slug}`);
7
+ }
86
8
  }
87
9
 
88
- export { command as default };
10
+ export { Login as default };
@@ -1,2 +1,4 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
1
+ import { Cli } from '@youcan/cli-kit';
2
+ export default class Login extends Cli.Command {
3
+ run(): Promise<void>;
4
+ }
@@ -1,21 +1,12 @@
1
- import config from '../../../config/index.js';
2
- import messages from '../../../config/messages.js';
3
- import deleteFile from '../../../utils/system/deleteFile.js';
4
- import stdout from '../../../utils/system/stdout.js';
1
+ import { Cli, Config } from '@youcan/cli-kit';
5
2
 
6
- function command(cli) {
7
- return {
8
- name: 'logout',
9
- group: 'auth',
10
- description: 'Log out from the current store',
11
- action: async () => {
12
- if (!cli.client.isAuthenticated()) {
13
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
14
- }
15
- deleteFile(config.CLI_GLOBAL_CONFIG_PATH);
16
- stdout.info(messages.AUTH_USER_LOGGED_OUT);
17
- },
18
- };
3
+ class Login extends Cli.Command {
4
+ async run() {
5
+ Config
6
+ .manager({ projectName: 'youcan-cli' })
7
+ .delete('store_session');
8
+ return this.output.info('Successfully logged out..');
9
+ }
19
10
  }
20
11
 
21
- export { command as default };
12
+ export { Login as default };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ declare function execCli(development: boolean): Promise<void>;
2
+ export default execCli;
package/dist/index.js CHANGED
@@ -1,3 +1,21 @@
1
- import cli from './cli/index.js';
1
+ import fs from 'node:fs';
2
+ import { Cli } from '@youcan/cli-kit';
2
3
 
3
- cli.init();
4
+ process.on('uncaughtException', (err) => {
5
+ fs.writeSync(process.stderr.fd, `${err.stack}\n`);
6
+ process.exit(1);
7
+ });
8
+ const signals = ['SIGINT', 'SIGTERM', 'SIGQUIT'];
9
+ signals.forEach((signal) => {
10
+ process.on(signal, () => {
11
+ process.exit(1);
12
+ });
13
+ });
14
+ async function execCli(development) {
15
+ await Cli.exec({
16
+ moduleUrl: import.meta.url,
17
+ development,
18
+ });
19
+ }
20
+
21
+ export { execCli as default };
package/package.json CHANGED
@@ -1,61 +1,79 @@
1
1
  {
2
2
  "name": "@youcan/cli",
3
3
  "type": "module",
4
- "version": "1.0.8",
5
- "description": "YouCan CLI for developers.",
4
+ "version": "1.1.0-beta.2",
5
+ "description": "A CLI for creating YouCan Shop apps",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
- "keywords": [],
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/youcan-shop/cli#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/youcan-shop/cli/edit/main/packages/cli"
12
+ },
13
+ "keywords": [
14
+ "youcan",
15
+ "youcan-cli",
16
+ "youcan-app"
17
+ ],
8
18
  "exports": {
9
19
  ".": {
10
- "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
11
21
  "import": "./dist/index.js"
12
22
  }
13
23
  },
14
24
  "main": "./dist/index.js",
15
- "types": "./dist/dts/index.d.ts",
16
25
  "bin": {
17
- "youcan": "bin/index.js"
26
+ "youcan": "./bin/exec.js"
18
27
  },
19
28
  "files": [
20
- "bin",
21
- "dist"
29
+ "/dist",
30
+ "/bin/exec.js",
31
+ "/bin/exec.cmd",
32
+ "/oclif.manifest.json"
22
33
  ],
23
34
  "dependencies": {
24
- "archiver": "^5.3.2",
25
- "cac": "^6.7.14",
26
- "chokidar": "^3.5.3",
27
- "decompress": "^4.2.1",
28
- "execa": "^6.1.0",
29
- "formdata-node": "^5.0.1",
30
- "kleur": "^4.1.5",
31
- "node-fetch": "^3.3.2",
32
- "prompts": "^2.4.2",
33
- "puppeteer": "^19.11.1",
34
- "ramda": "^0.28.0",
35
- "socket.io": "^4.7.2",
36
- "socket.io-client": "^4.7.2"
35
+ "@oclif/core": "^2.15.0",
36
+ "@oclif/plugin-commands": "^2.2.26",
37
+ "@oclif/plugin-help": "^5.2.19",
38
+ "@oclif/plugin-plugins": "^3.8.2",
39
+ "@youcan/app": "1.1.0-beta.2",
40
+ "@youcan/cli-kit": "1.1.0-beta.2",
41
+ "@youcan/theme": "1.1.0-beta.2"
37
42
  },
38
43
  "devDependencies": {
39
- "@azuradara/eslint-config-base": "^0.1.3",
40
- "@azuradara/eslint-config-ts": "^0.1.3",
41
- "@types/archiver": "^5.3.3",
42
- "@types/file-saver": "^2.0.5",
44
+ "@oclif/plugin-legacy": "^1.3.0",
43
45
  "@types/node": "^18.18.0",
44
- "@types/prompts": "^2.4.5",
45
- "@types/ramda": "^0.28.25",
46
- "@types/rimraf": "^3.0.2",
47
- "esno": "^0.16.3",
48
- "pnpm": "^7.33.6",
49
- "rimraf": "^3.0.2",
50
- "rollup": "^3.29.3",
51
- "rollup-plugin-dts": "^5.3.1",
52
- "rollup-plugin-node-externals": "^6.1.1",
53
- "rollup-plugin-typescript2": "^0.34.1",
54
- "typescript": "^4.9.5"
46
+ "shx": "^0.3.4"
47
+ },
48
+ "oclif": {
49
+ "bin": "youcan",
50
+ "scope": "youcan",
51
+ "commands": "./dist/cli/commands",
52
+ "plugins": [
53
+ "@youcan/app",
54
+ "@youcan/theme",
55
+ "@oclif/plugin-help",
56
+ "@oclif/plugin-commands"
57
+ ],
58
+ "topicSeparator": " ",
59
+ "topics": {
60
+ "theme": {
61
+ "description": "Build YouCan themes."
62
+ },
63
+ "app": {
64
+ "description": "Build YouCan apps."
65
+ },
66
+ "auth": {
67
+ "description": "Authenticate with your YouCan account."
68
+ }
69
+ },
70
+ "additionalHelpFlags": [
71
+ "-h"
72
+ ]
55
73
  },
56
74
  "scripts": {
57
- "build": "tsc --noEmit && rollup --config rollup.config.js",
58
- "dev": "rollup --config rollup.config.js --watch",
75
+ "build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
76
+ "dev": "shx rm -rf dist && rollup --config rollup.config.js --watch",
59
77
  "release": "pnpm publish --access public",
60
78
  "type-check": "tsc --noEmit",
61
79
  "relink": "pnpm link --global"
package/bin/index.js DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import('../dist/index.js');
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
@@ -1,65 +0,0 @@
1
- import fs from 'node:fs';
2
- import prompts from 'prompts';
3
- import stdout from '../../../utils/system/stdout.js';
4
- import messages from '../../../config/messages.js';
5
- import { LoadingSpinner } from '../../../utils/common.js';
6
-
7
- function command(cli) {
8
- return {
9
- name: 'apps:create',
10
- group: 'apps',
11
- description: 'Create your app',
12
- action: async () => {
13
- if (!cli.client.isAuthenticated()) {
14
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
15
- }
16
- const loading = new LoadingSpinner('Creating your app ...');
17
- try {
18
- const inquiries = [
19
- {
20
- type: 'text',
21
- name: 'name',
22
- message: 'Type your app name',
23
- validate: value => value !== '' && value.length > 3,
24
- },
25
- ];
26
- const app = await prompts(inquiries);
27
- loading.start();
28
- await cli.client.createApp({ name: app.name });
29
- const appPath = `./${app.name}`;
30
- fs.mkdir(appPath, (err) => {
31
- if (err) {
32
- loading.error(`Error creating directory: ${err}`);
33
- }
34
- });
35
- const packageContent = {
36
- name: app.name,
37
- version: '0.0.1',
38
- description: 'Your package description',
39
- main: 'index.js',
40
- scripts: {
41
- start: `node index.js && youcan apps:install -n ${app.name}`,
42
- },
43
- dependencies: {},
44
- };
45
- fs.writeFile(`${appPath}/package.json`, JSON.stringify(packageContent, null, 2), (err) => {
46
- if (err) {
47
- stdout.error(`Error creating the package.json file: ${err}`);
48
- }
49
- });
50
- fs.writeFile(`${appPath}/index.js`, 'console.log(\'Hello, World!\')', (err) => {
51
- if (err) {
52
- stdout.error(`Error creating the index.js file: ${err}`);
53
- }
54
- });
55
- loading.stop();
56
- }
57
- catch (err) {
58
- const error = JSON.parse(err.message);
59
- loading.error(error.detail);
60
- }
61
- },
62
- };
63
- }
64
-
65
- export { command as default };
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
@@ -1,28 +0,0 @@
1
- import stdout from '../../../utils/system/stdout.js';
2
- import messages from '../../../config/messages.js';
3
-
4
- function command(cli) {
5
- return {
6
- name: 'apps:install',
7
- group: 'apps',
8
- description: 'Generate app installation url',
9
- options: [
10
- { name: '-n, --name <app>', description: 'Specify a app name e.g. codmanager' },
11
- ],
12
- action: async (options) => {
13
- if (!cli.client.isAuthenticated()) {
14
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
15
- }
16
- try {
17
- const response = await cli.client.generateAppInstallationUrl(options.name);
18
- stdout.info(`To test the app within your store hit the following url : ${response.url}`);
19
- }
20
- catch (err) {
21
- const error = JSON.parse(err.message);
22
- stdout.error(error);
23
- }
24
- },
25
- };
26
- }
27
-
28
- export { command as default };
@@ -1,6 +0,0 @@
1
- export interface TokenResponse {
2
- token_type: string;
3
- expires_in: string;
4
- access_token: string;
5
- refresh_toekn: string;
6
- }
@@ -1,12 +0,0 @@
1
- export { default as LoginCommand } from './auth/login';
2
- export { default as LogoutCommand } from './auth/logout';
3
- export { default as ThemeInitCommand } from './theme/init';
4
- export { default as ThemeListCommand } from './theme/list';
5
- export { default as ThemeDevCommand } from './theme/dev';
6
- export { default as ThemeDeleteCommand } from './theme/delete';
7
- export { default as ThemePullCommand } from './theme/pull';
8
- export { default as ThemePackCommand } from './theme/pack';
9
- export { default as StoreInfoCommand } from './store/info';
10
- export { default as StoreSwitchCommand } from './store/switch';
11
- export { default as CreateAppCommand } from './apps/create';
12
- export { default as InstallAppCommand } from './apps/install';
@@ -1,14 +0,0 @@
1
- export { default as LoginCommand } from './auth/login.js';
2
- export { default as LogoutCommand } from './auth/logout.js';
3
- export { default as ThemeInitCommand } from './theme/init.js';
4
- export { default as ThemeListCommand } from './theme/list.js';
5
- export { default as ThemeDevCommand } from './theme/dev.js';
6
- export { default as ThemeDeleteCommand } from './theme/delete.js';
7
- export { default as ThemePullCommand } from './theme/pull.js';
8
- export { default as ThemePackCommand } from './theme/pack.js';
9
- export { default as StoreInfoCommand } from './store/info.js';
10
- export { default as StoreSwitchCommand } from './store/switch.js';
11
- export { default as CreateAppCommand } from './apps/create.js';
12
- export { default as InstallAppCommand } from './apps/install.js';
13
-
14
- // auth
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
@@ -1,29 +0,0 @@
1
- import messages from '../../../config/messages.js';
2
- import stdout from '../../../utils/system/stdout.js';
3
- import { LoadingSpinner } from '../../../utils/common.js';
4
-
5
- function command(cli) {
6
- return {
7
- name: 'store:info',
8
- group: 'theme',
9
- description: 'Current development store info',
10
- options: [],
11
- action: async () => {
12
- if (!cli.client.isAuthenticated()) {
13
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
14
- }
15
- await LoadingSpinner.exec(`${messages.FETCHING_CURRENT_STORE_INFO}..`, async (spinner) => {
16
- try {
17
- const storeInfo = await cli.client.getStoreInfo();
18
- spinner.stop();
19
- stdout.info(`${messages.CURRENT_DEVELOPMENT_STORE}: ${storeInfo.slug}`);
20
- }
21
- catch (err) {
22
- spinner.error(messages.ERROR_WHILE_FETCHING_CURRENT_STORE_INFO);
23
- }
24
- });
25
- },
26
- };
27
- }
28
-
29
- export { command as default };
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
@@ -1,59 +0,0 @@
1
- import prompts from 'prompts';
2
- import messages from '../../../config/messages.js';
3
- import stdout from '../../../utils/system/stdout.js';
4
- import { LoadingSpinner } from '../../../utils/common.js';
5
- import writeToFile from '../../../utils/system/writeToFile.js';
6
- import config from '../../../config/index.js';
7
-
8
- function command(cli) {
9
- return {
10
- name: 'store:switch',
11
- group: 'theme',
12
- description: 'Switch the development store',
13
- options: [],
14
- action: async () => {
15
- if (!cli.client.isAuthenticated()) {
16
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
17
- }
18
- let storeInfo;
19
- await LoadingSpinner.exec(`${messages.FETCHING_CURRENT_STORE_INFO}..`, async (spinner) => {
20
- try {
21
- storeInfo = await cli.client.getStoreInfo();
22
- }
23
- catch (err) {
24
- spinner.error(messages.ERROR_WHILE_FETCHING_CURRENT_STORE_INFO);
25
- }
26
- });
27
- stdout.info(`${messages.CURRENT_DEVELOPMENT_STORE}: ${storeInfo.slug}`);
28
- const { stores } = await cli.client.listStores();
29
- if (!stores.length) {
30
- return stdout.error(messages.NO_STORE_FOUND);
31
- }
32
- const choices = stores.map(store => ({
33
- title: store.slug,
34
- value: store.store_id,
35
- }));
36
- const { storeId } = await prompts({
37
- type: 'select',
38
- name: 'storeId',
39
- message: messages.SELECT_STORE,
40
- choices,
41
- });
42
- if (!storeId) {
43
- return stdout.error(messages.NO_STORE_SELECTED);
44
- }
45
- await LoadingSpinner.exec(`${messages.SELECT_STORE_IN_PROGRESS}..`, async (spinner) => {
46
- try {
47
- const selectStoreResponse = await cli.client.selectStore({ id: storeId });
48
- writeToFile(config.CLI_GLOBAL_CONFIG_PATH, JSON.stringify({ access_token: selectStoreResponse.token }));
49
- }
50
- catch (err) {
51
- spinner.error(messages.CANNOT_SELECT_STORE);
52
- }
53
- });
54
- stdout.info(messages.STORE_SELECTED);
55
- },
56
- };
57
- }
58
-
59
- export { command as default };
@@ -1,4 +0,0 @@
1
- import type { Store } from '@/core/client/types';
2
- export interface listStoresResponse {
3
- stores: Store[];
4
- }
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
- export default function command(cli: CLI): CommandDefinition;
@@ -1,46 +0,0 @@
1
- import prompts from 'prompts';
2
- import messages from '../../../config/messages.js';
3
- import stdout from '../../../utils/system/stdout.js';
4
- import { LoadingSpinner } from '../../../utils/common.js';
5
-
6
- function command(cli) {
7
- return {
8
- name: 'theme:delete',
9
- group: 'theme',
10
- description: 'Delete a remote development theme',
11
- options: [],
12
- action: async () => {
13
- if (!cli.client.isAuthenticated()) {
14
- return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
15
- }
16
- const { dev: devThemes } = await cli.client.listThemes();
17
- if (!devThemes.length) {
18
- return stdout.error(messages.NO_REMOTE_THEMES);
19
- }
20
- const choices = devThemes.map(theme => ({
21
- title: theme.name,
22
- value: theme.id,
23
- }));
24
- const { themeId } = await prompts({
25
- type: 'select',
26
- name: 'themeId',
27
- message: messages.DELETE_SELECT_THEME,
28
- choices,
29
- });
30
- if (!themeId) {
31
- return stdout.error(messages.DELETE_NO_THEME_SELECTED);
32
- }
33
- await LoadingSpinner.exec(`${messages.DELETE_IN_PROGRESS} ${themeId}..`, async (spinner) => {
34
- try {
35
- await cli.client.deleteTheme(themeId);
36
- }
37
- catch (err) {
38
- spinner.error(messages.DELETE_ERROR);
39
- }
40
- });
41
- stdout.info(messages.DELETE_THEME_DELETED);
42
- },
43
- };
44
- }
45
-
46
- export { command as default };
@@ -1,2 +0,0 @@
1
- import type { CLI, CommandDefinition } from '../types';
2
- export default function command(cli: CLI): CommandDefinition;