@youcan/cli 1.0.6 → 1.0.8

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/bin/index.js +1 -1
  3. package/dist/cli/commands/apps/create.js +65 -0
  4. package/dist/cli/commands/apps/install.d.ts +2 -0
  5. package/dist/cli/commands/apps/install.js +28 -0
  6. package/dist/cli/commands/auth/login.d.ts +2 -0
  7. package/dist/cli/commands/auth/login.js +3 -4
  8. package/dist/cli/commands/auth/logout.d.ts +2 -0
  9. package/dist/cli/commands/auth/logout.js +2 -1
  10. package/dist/cli/commands/auth/types.d.ts +6 -0
  11. package/dist/cli/commands/index.d.ts +12 -0
  12. package/dist/cli/commands/index.js +2 -0
  13. package/dist/cli/commands/store/info.d.ts +2 -0
  14. package/dist/cli/commands/store/info.js +2 -1
  15. package/dist/cli/commands/store/switch.d.ts +2 -0
  16. package/dist/cli/commands/store/switch.js +6 -3
  17. package/dist/cli/commands/store/types.d.ts +4 -0
  18. package/dist/cli/commands/theme/delete.d.ts +2 -0
  19. package/dist/cli/commands/theme/delete.js +6 -3
  20. package/dist/cli/commands/theme/dev.d.ts +2 -0
  21. package/dist/cli/commands/theme/dev.js +24 -16
  22. package/dist/cli/commands/theme/init.d.ts +2 -0
  23. package/dist/cli/commands/theme/init.js +7 -6
  24. package/dist/cli/commands/theme/list.d.ts +2 -0
  25. package/dist/cli/commands/theme/list.js +4 -2
  26. package/dist/cli/commands/theme/pack.d.ts +2 -0
  27. package/dist/cli/commands/theme/pack.js +5 -3
  28. package/dist/cli/commands/theme/pull.d.ts +2 -0
  29. package/dist/cli/commands/theme/pull.js +5 -3
  30. package/dist/cli/commands/theme/types.d.ts +17 -0
  31. package/dist/cli/commands/types.d.ts +22 -0
  32. package/dist/cli/index.d.ts +12 -0
  33. package/dist/cli/index.js +10 -8
  34. package/dist/config/index.d.ts +21 -0
  35. package/dist/config/index.js +6 -6
  36. package/dist/config/messages.d.ts +36 -0
  37. package/dist/core/client/client.d.ts +23 -0
  38. package/dist/core/client/client.js +10 -3
  39. package/dist/core/client/types.d.ts +80 -0
  40. package/dist/core/themes/preview.d.ts +1 -0
  41. package/dist/core/themes/preview.js +3 -2
  42. package/dist/index.d.ts +1 -0
  43. package/dist/lib/cli/commands/apps/create.d.ts +2 -0
  44. package/dist/lib/cli/commands/apps/install.d.ts +2 -0
  45. package/dist/lib/cli/commands/index.d.ts +2 -0
  46. package/dist/lib/cli/index.d.ts +1 -1
  47. package/dist/lib/core/client/client.d.ts +3 -1
  48. package/dist/lib/core/client/types.d.ts +9 -0
  49. package/dist/utils/common.d.ts +22 -0
  50. package/dist/utils/common.js +8 -5
  51. package/dist/utils/git/cloneRepository.d.ts +6 -0
  52. package/dist/utils/git/cloneRepository.js +1 -1
  53. package/dist/utils/helpers.d.ts +3 -0
  54. package/dist/utils/helpers.js +6 -3
  55. package/dist/utils/http.d.ts +11 -0
  56. package/dist/utils/http.js +3 -2
  57. package/dist/utils/network.d.ts +2 -0
  58. package/dist/utils/network.js +12 -7
  59. package/dist/utils/system/deleteFile.d.ts +5 -0
  60. package/dist/utils/system/deleteFile.js +3 -2
  61. package/dist/utils/system/ls.d.ts +1 -0
  62. package/dist/utils/system/ls.js +1 -1
  63. package/dist/utils/system/openLink.d.ts +1 -0
  64. package/dist/utils/system/saveFile.d.ts +1 -0
  65. package/dist/utils/system/saveFile.js +2 -2
  66. package/dist/utils/system/stdout.d.ts +17 -0
  67. package/dist/utils/system/stdout.js +30 -11
  68. package/dist/utils/system/writeToFile.d.ts +1 -0
  69. package/dist/utils/system/writeToFile.js +1 -6
  70. package/dist/utils/system/zipFolder.d.ts +5 -0
  71. package/dist/utils/system/zipFolder.js +3 -3
  72. package/dist/utils/system.d.ts +1 -0
  73. package/dist/utils/system.js +2 -1
  74. package/package.json +19 -26
  75. package/README.md +0 -18
  76. package/dist/utils/system/openLink.js +0 -15
  77. /package/dist/{lib/cli/commands/theme/switch-store.d.ts → cli/commands/apps/create.d.ts} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 YouCan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import('../dist/index.js')
2
+ import('../dist/index.js');
@@ -0,0 +1,65 @@
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 };
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -0,0 +1,28 @@
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 };
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -1,4 +1,4 @@
1
- import { exit } from 'process';
1
+ import { exit } from 'node:process';
2
2
  import prompts from 'prompts';
3
3
  import config from '../../../config/index.js';
4
4
  import stdout from '../../../utils/system/stdout.js';
@@ -7,9 +7,8 @@ import messages from '../../../config/messages.js';
7
7
  import { isPortAvailable, getPidByPort } from '../../../utils/network.js';
8
8
  import { kill } from '../../../utils/system.js';
9
9
  import { LoadingSpinner } from '../../../utils/common.js';
10
- import cli from '../../index.js';
11
10
 
12
- function command(_cli) {
11
+ function command(cli) {
13
12
  return {
14
13
  name: 'login',
15
14
  group: 'auth',
@@ -31,7 +30,7 @@ function command(_cli) {
31
30
  if (pid) {
32
31
  await LoadingSpinner.exec(`Terminating process ${pid}..`, async (spinner) => {
33
32
  try {
34
- await kill(pid, 'SIGTERM', 30000);
33
+ await kill(pid, 'SIGTERM', 30_000);
35
34
  }
36
35
  catch (err) {
37
36
  spinner.error('Could not terminate process, proceeding..');
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -9,8 +9,9 @@ function command(cli) {
9
9
  group: 'auth',
10
10
  description: 'Log out from the current store',
11
11
  action: async () => {
12
- if (!cli.client.isAuthenticated())
12
+ if (!cli.client.isAuthenticated()) {
13
13
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
14
+ }
14
15
  deleteFile(config.CLI_GLOBAL_CONFIG_PATH);
15
16
  stdout.info(messages.AUTH_USER_LOGGED_OUT);
16
17
  },
@@ -0,0 +1,6 @@
1
+ export interface TokenResponse {
2
+ token_type: string;
3
+ expires_in: string;
4
+ access_token: string;
5
+ refresh_toekn: string;
6
+ }
@@ -0,0 +1,12 @@
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';
@@ -8,5 +8,7 @@ export { default as ThemePullCommand } from './theme/pull.js';
8
8
  export { default as ThemePackCommand } from './theme/pack.js';
9
9
  export { default as StoreInfoCommand } from './store/info.js';
10
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';
11
13
 
12
14
  // auth
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -9,8 +9,9 @@ function command(cli) {
9
9
  description: 'Current development store info',
10
10
  options: [],
11
11
  action: async () => {
12
- if (!cli.client.isAuthenticated())
12
+ if (!cli.client.isAuthenticated()) {
13
13
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
14
+ }
14
15
  await LoadingSpinner.exec(`${messages.FETCHING_CURRENT_STORE_INFO}..`, async (spinner) => {
15
16
  try {
16
17
  const storeInfo = await cli.client.getStoreInfo();
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -12,8 +12,9 @@ function command(cli) {
12
12
  description: 'Switch the development store',
13
13
  options: [],
14
14
  action: async () => {
15
- if (!cli.client.isAuthenticated())
15
+ if (!cli.client.isAuthenticated()) {
16
16
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
17
+ }
17
18
  let storeInfo;
18
19
  await LoadingSpinner.exec(`${messages.FETCHING_CURRENT_STORE_INFO}..`, async (spinner) => {
19
20
  try {
@@ -25,8 +26,9 @@ function command(cli) {
25
26
  });
26
27
  stdout.info(`${messages.CURRENT_DEVELOPMENT_STORE}: ${storeInfo.slug}`);
27
28
  const { stores } = await cli.client.listStores();
28
- if (!stores.length)
29
+ if (!stores.length) {
29
30
  return stdout.error(messages.NO_STORE_FOUND);
31
+ }
30
32
  const choices = stores.map(store => ({
31
33
  title: store.slug,
32
34
  value: store.store_id,
@@ -37,8 +39,9 @@ function command(cli) {
37
39
  message: messages.SELECT_STORE,
38
40
  choices,
39
41
  });
40
- if (!storeId)
42
+ if (!storeId) {
41
43
  return stdout.error(messages.NO_STORE_SELECTED);
44
+ }
42
45
  await LoadingSpinner.exec(`${messages.SELECT_STORE_IN_PROGRESS}..`, async (spinner) => {
43
46
  try {
44
47
  const selectStoreResponse = await cli.client.selectStore({ id: storeId });
@@ -0,0 +1,4 @@
1
+ import type { Store } from '@/core/client/types';
2
+ export interface listStoresResponse {
3
+ stores: Store[];
4
+ }
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -10,11 +10,13 @@ function command(cli) {
10
10
  description: 'Delete a remote development theme',
11
11
  options: [],
12
12
  action: async () => {
13
- if (!cli.client.isAuthenticated())
13
+ if (!cli.client.isAuthenticated()) {
14
14
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
15
+ }
15
16
  const { dev: devThemes } = await cli.client.listThemes();
16
- if (!devThemes.length)
17
+ if (!devThemes.length) {
17
18
  return stdout.error(messages.NO_REMOTE_THEMES);
19
+ }
18
20
  const choices = devThemes.map(theme => ({
19
21
  title: theme.name,
20
22
  value: theme.id,
@@ -25,8 +27,9 @@ function command(cli) {
25
27
  message: messages.DELETE_SELECT_THEME,
26
28
  choices,
27
29
  });
28
- if (!themeId)
30
+ if (!themeId) {
29
31
  return stdout.error(messages.DELETE_NO_THEME_SELECTED);
32
+ }
30
33
  await LoadingSpinner.exec(`${messages.DELETE_IN_PROGRESS} ${themeId}..`, async (spinner) => {
31
34
  try {
32
35
  await cli.client.deleteTheme(themeId);
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '../types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -1,7 +1,7 @@
1
- import { cwd } from 'process';
2
- import { clear } from 'console';
3
- import { readdirSync, existsSync, readFileSync } from 'fs';
4
- import crypto from 'crypto';
1
+ import { cwd } from 'node:process';
2
+ import { clear } from 'node:console';
3
+ import { readdirSync, existsSync, readFileSync } from 'node:fs';
4
+ import crypto from 'node:crypto';
5
5
  import chokidar from 'chokidar';
6
6
  import kleur from 'kleur';
7
7
  import { fileFromPathSync } from 'formdata-node/file-from-path';
@@ -59,8 +59,9 @@ async function syncChanges(cli, themeId) {
59
59
  });
60
60
  }
61
61
  catch (err) {
62
- if (err instanceof Error)
62
+ if (err instanceof Error) {
63
63
  stdout.error(`[error] ${file}: ${err.message}`);
64
+ }
64
65
  }
65
66
  }
66
67
  }
@@ -76,8 +77,9 @@ async function syncChanges(cli, themeId) {
76
77
  });
77
78
  }
78
79
  catch (err) {
79
- if (err instanceof Error)
80
+ if (err instanceof Error) {
80
81
  stdout.error(`[error] ${file.file_name}: ${err.message}`);
82
+ }
81
83
  }
82
84
  continue;
83
85
  }
@@ -94,8 +96,9 @@ async function syncChanges(cli, themeId) {
94
96
  });
95
97
  }
96
98
  catch (err) {
97
- if (err instanceof Error)
99
+ if (err instanceof Error) {
98
100
  stdout.error(`[error] ${file.file_name}: ${err.message}`);
101
+ }
99
102
  }
100
103
  }
101
104
  }
@@ -112,11 +115,13 @@ function command(cli) {
112
115
  ],
113
116
  action: async (options) => {
114
117
  let socket;
115
- if (!cli.client.isAuthenticated())
118
+ if (!cli.client.isAuthenticated()) {
116
119
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
120
+ }
117
121
  const themeId = await getCurrentThemeId(cwd());
118
- if (!themeId)
122
+ if (!themeId) {
119
123
  return stdout.error(messages.DEV_NO_THEME_DETECTED);
124
+ }
120
125
  const { domain } = await cli.client.getStoreInfo();
121
126
  clear();
122
127
  const loadingSpinner = new LoadingSpinner('Syncing changes...');
@@ -138,14 +143,15 @@ function command(cli) {
138
143
  },
139
144
  })
140
145
  .on('all', async (event, path, stats) => {
141
- var _a, _b;
142
146
  const start = new Date().getTime();
143
147
  try {
144
148
  const [filetype, filename] = path.split('/', 2);
145
- if (!config.THEME_FILE_TYPES.includes(filetype))
149
+ if (!config.THEME_FILE_TYPES.includes(filetype)) {
146
150
  return;
147
- if (!['add', 'change', 'unlink'].includes(event))
151
+ }
152
+ if (!['add', 'change', 'unlink'].includes(event)) {
148
153
  return;
154
+ }
149
155
  switch (event) {
150
156
  case 'add':
151
157
  case 'change':
@@ -164,12 +170,13 @@ function command(cli) {
164
170
  });
165
171
  break;
166
172
  }
167
- if (socket)
173
+ if (socket) {
168
174
  socket.emit('theme:update', { themeId });
175
+ }
169
176
  logFileEvent({
170
177
  path,
171
178
  event,
172
- size: (_a = stats === null || stats === void 0 ? void 0 : stats.size) !== null && _a !== void 0 ? _a : 0,
179
+ size: stats?.size ?? 0,
173
180
  roundtrip: new Date().getTime() - start,
174
181
  });
175
182
  }
@@ -177,11 +184,12 @@ function command(cli) {
177
184
  logFileEvent({
178
185
  path,
179
186
  event: 'error',
180
- size: (_b = stats === null || stats === void 0 ? void 0 : stats.size) !== null && _b !== void 0 ? _b : 0,
187
+ size: stats?.size ?? 0,
181
188
  roundtrip: new Date().getTime() - start,
182
189
  });
183
- if (err instanceof Error)
190
+ if (err instanceof Error) {
184
191
  stdout.info(`message: ${err.message}`);
192
+ }
185
193
  }
186
194
  });
187
195
  },
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -1,5 +1,5 @@
1
- import { cwd } from 'process';
2
- import path from 'path';
1
+ import { cwd } from 'node:process';
2
+ import path from 'node:path';
3
3
  import prompts from 'prompts';
4
4
  import { fileFromPath } from 'formdata-node/file-from-path';
5
5
  import config from '../../../config/index.js';
@@ -50,10 +50,10 @@ const defaultInquiries = {
50
50
  theme_documentation_url: 'https://developer.youcan.shop',
51
51
  };
52
52
  function getSelectedTheme(optionTheme) {
53
- var _a;
54
- const selectedTheme = (_a = config.AVAILABLE_THEMES.find(theme => theme.name === (optionTheme === null || optionTheme === void 0 ? void 0 : optionTheme.toLocaleLowerCase().trim()))) === null || _a === void 0 ? void 0 : _a.repository;
55
- if (selectedTheme)
53
+ const selectedTheme = config.AVAILABLE_THEMES.find(theme => theme.name === optionTheme?.toLocaleLowerCase().trim())?.repository;
54
+ if (selectedTheme) {
56
55
  return selectedTheme;
56
+ }
57
57
  return config.STARTER_THEME_GIT_REPOSITORY;
58
58
  }
59
59
  function command(cli) {
@@ -66,8 +66,9 @@ function command(cli) {
66
66
  { name: '-d, --default', description: 'Use default values for theme name, author, version, support url and documentation url.' },
67
67
  ],
68
68
  action: async (options) => {
69
- if (!cli.client.isAuthenticated())
69
+ if (!cli.client.isAuthenticated()) {
70
70
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
71
+ }
71
72
  const info = options.default ? defaultInquiries : await prompts(inquiries);
72
73
  stdout.info(messages.INIT_CLONE_START);
73
74
  const themeRepository = getSelectedTheme(options.theme);
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -9,14 +9,16 @@ function command(cli) {
9
9
  description: 'List my development themes',
10
10
  options: [],
11
11
  action: async () => {
12
- if (!cli.client.isAuthenticated())
12
+ if (!cli.client.isAuthenticated()) {
13
13
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
14
+ }
14
15
  await LoadingSpinner.exec(`${messages.FETCHING_DEV_THEMES}..`, async (spinner) => {
15
16
  try {
16
17
  const devThemes = await cli.client.listThemes();
17
18
  spinner.stop();
18
- if (!devThemes.dev.length)
19
+ if (!devThemes.dev.length) {
19
20
  return stdout.error(messages.NO_REMOTE_THEMES);
21
+ }
20
22
  stdout.table(devThemes.dev.map((theme) => ({
21
23
  Name: theme.name,
22
24
  Size: theme.size,
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '../types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -1,4 +1,4 @@
1
- import { cwd } from 'process';
1
+ import { cwd } from 'node:process';
2
2
  import stdout from '../../../utils/system/stdout.js';
3
3
  import { getCurrentThemeId, getCurrentDate, LoadingSpinner } from '../../../utils/common.js';
4
4
  import messages from '../../../config/messages.js';
@@ -12,10 +12,12 @@ function command(cli) {
12
12
  description: 'Package a theme',
13
13
  options: [],
14
14
  action: async () => {
15
- if (!cli.client.isAuthenticated())
15
+ if (!cli.client.isAuthenticated()) {
16
16
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
17
- if (!await getCurrentThemeId(cwd()))
17
+ }
18
+ if (!await getCurrentThemeId(cwd())) {
18
19
  return stdout.error('No theme found in the current directory');
20
+ }
19
21
  const loading = new LoadingSpinner('📦 Packaging your theme');
20
22
  loading.start();
21
23
  const exportFolder = `theme_${getCurrentDate()}`;
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '../types';
2
+ export default function command(cli: CLI): CommandDefinition;
@@ -1,4 +1,4 @@
1
- import { cwd } from 'process';
1
+ import { cwd } from 'node:process';
2
2
  import prompts from 'prompts';
3
3
  import decompress from 'decompress';
4
4
  import stdout from '../../../utils/system/stdout.js';
@@ -15,8 +15,9 @@ function command(cli) {
15
15
  description: 'Pull a theme',
16
16
  options: [],
17
17
  action: async () => {
18
- if (!cli.client.isAuthenticated())
18
+ if (!cli.client.isAuthenticated()) {
19
19
  return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
20
+ }
20
21
  const { dev } = await cli.client.listThemes();
21
22
  const choices = dev.map(theme => ({
22
23
  title: theme.name,
@@ -34,8 +35,9 @@ function command(cli) {
34
35
  themeId = promt.themeId;
35
36
  }
36
37
  themeId = themeId || cwdThemeId;
37
- if (!themeId)
38
+ if (!themeId) {
38
39
  return stdout.error(messages.PULL_NO_THEME_FOUND);
40
+ }
39
41
  const fileName = `${themeId}`;
40
42
  const fileNameZip = `${fileName}.zip`;
41
43
  stdout.info(messages.PULL_PULLING_THEME);
@@ -0,0 +1,17 @@
1
+ export interface FileEventOptions {
2
+ path: string;
3
+ size: number;
4
+ roundtrip: number;
5
+ event: string;
6
+ }
7
+ export interface ThemeMetaData {
8
+ id: string;
9
+ name: string;
10
+ size: number;
11
+ version: string;
12
+ live: boolean;
13
+ }
14
+ export interface listThemesResponse {
15
+ dev: ThemeMetaData[];
16
+ published: ThemeMetaData[];
17
+ }
@@ -0,0 +1,22 @@
1
+ import type { CAC } from 'cac';
2
+ import type Client from '@/core/client/client';
3
+ export interface CommandOptionDefinition {
4
+ name: string;
5
+ description: string;
6
+ config?: {
7
+ default?: any;
8
+ type?: any[];
9
+ };
10
+ }
11
+ export interface CommandDefinition {
12
+ name: string;
13
+ group: string;
14
+ aliases?: string[];
15
+ description: string;
16
+ action: ReturnType<any>;
17
+ options?: CommandOptionDefinition[];
18
+ }
19
+ export interface CLI {
20
+ handler: CAC;
21
+ client: Client;
22
+ }
@@ -0,0 +1,12 @@
1
+ import * as commands from './commands';
2
+ import type { CLI, CommandDefinition } from './commands/types';
3
+ import Client from '@/core/client/client';
4
+ declare const cli: {
5
+ client: Client;
6
+ handler: import("cac").CAC;
7
+ registerCommand(command: (cli: CLI) => CommandDefinition): void;
8
+ getAvailableCommands(): (typeof commands.LoginCommand | typeof commands.LogoutCommand | typeof commands.ThemeInitCommand | typeof commands.ThemeListCommand | typeof commands.ThemeDevCommand | typeof commands.ThemeDeleteCommand | typeof commands.ThemePullCommand | typeof commands.ThemePackCommand | typeof commands.StoreInfoCommand | typeof commands.StoreSwitchCommand | typeof commands.CreateAppCommand | typeof commands.InstallAppCommand)[];
9
+ init(): Promise<void>;
10
+ prepareClient(): Promise<void>;
11
+ };
12
+ export default cli;
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, promises } from 'fs';
1
+ import { existsSync, promises } from 'node:fs';
2
2
  import { cac } from 'cac';
3
3
  import * as index from './commands/index.js';
4
4
  import Client from '../core/client/client.js';
@@ -8,13 +8,12 @@ const cli = {
8
8
  client: new Client(),
9
9
  handler: cac('youcan'),
10
10
  registerCommand(command) {
11
- var _a, _b;
12
11
  const definition = command(this);
13
12
  const instance = this.handler
14
13
  .command(definition.name, definition.description)
15
14
  .action(definition.action);
16
- (_a = definition.aliases) === null || _a === void 0 ? void 0 : _a.forEach(a => instance.alias(a));
17
- (_b = definition.options) === null || _b === void 0 ? void 0 : _b.forEach(o => instance.option(o.name, o.description, o.config));
15
+ definition.aliases?.forEach(a => instance.alias(a));
16
+ definition.options?.forEach(o => instance.option(o.name, o.description, o.config));
18
17
  },
19
18
  getAvailableCommands() {
20
19
  return Object.values(index);
@@ -29,22 +28,25 @@ const cli = {
29
28
  this.handler.parse();
30
29
  },
31
30
  async prepareClient() {
32
- if (!existsSync(config.CLI_GLOBAL_CONFIG_DIR))
31
+ if (!existsSync(config.CLI_GLOBAL_CONFIG_DIR)) {
33
32
  await promises.mkdir(config.CLI_GLOBAL_CONFIG_DIR);
34
- if (!existsSync(config.CLI_GLOBAL_CONFIG_PATH))
33
+ }
34
+ if (!existsSync(config.CLI_GLOBAL_CONFIG_PATH)) {
35
35
  return await promises.writeFile(config.CLI_GLOBAL_CONFIG_PATH, '', { flag: 'wx', encoding: 'utf-8' });
36
+ }
36
37
  const data = await promises
37
38
  .readFile(config.CLI_GLOBAL_CONFIG_PATH, 'utf-8')
38
39
  .then((b) => {
39
40
  try {
40
41
  return JSON.parse(b);
41
42
  }
42
- catch (_a) {
43
+ catch {
43
44
  return {};
44
45
  }
45
46
  });
46
- if ('access_token' in data)
47
+ if ('access_token' in data) {
47
48
  this.client.setAccessToken(data.access_token);
49
+ }
48
50
  },
49
51
  };
50
52