@youcan/cli 1.0.7 → 1.1.0-beta.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.
- package/LICENSE +21 -0
- package/bin/index.js +1 -1
- package/dist/cli/commands/apps/create.js +65 -0
- package/dist/cli/commands/apps/install.js +28 -0
- package/dist/cli/commands/auth/login.js +3 -4
- package/dist/cli/commands/auth/logout.js +2 -1
- package/dist/{lib/cli → cli}/commands/index.d.ts +2 -0
- package/dist/cli/commands/index.js +2 -0
- package/dist/cli/commands/store/info.js +2 -1
- package/dist/cli/commands/store/switch.js +6 -3
- package/dist/cli/commands/theme/delete.js +6 -3
- package/dist/cli/commands/theme/dev.js +24 -16
- package/dist/cli/commands/theme/init.d.ts +2 -0
- package/dist/cli/commands/theme/init.js +7 -6
- package/dist/cli/commands/theme/list.d.ts +2 -0
- package/dist/cli/commands/theme/list.js +4 -2
- package/dist/cli/commands/theme/pack.js +5 -3
- package/dist/cli/commands/theme/pull.js +5 -3
- package/dist/{lib/cli → cli}/index.d.ts +3 -3
- package/dist/cli/index.js +10 -8
- package/dist/config/index.js +3 -3
- package/dist/{lib/core → core}/client/client.d.ts +3 -1
- package/dist/core/client/client.js +10 -3
- package/dist/{lib/core → core}/client/types.d.ts +9 -0
- package/dist/core/themes/preview.js +3 -2
- package/dist/{lib/utils → utils}/common.d.ts +1 -1
- package/dist/utils/common.js +8 -5
- package/dist/utils/git/cloneRepository.js +1 -1
- package/dist/utils/helpers.js +6 -3
- package/dist/utils/http.js +3 -2
- package/dist/utils/network.js +12 -7
- package/dist/utils/system/deleteFile.js +3 -2
- package/dist/utils/system/ls.js +1 -1
- package/dist/utils/system/saveFile.js +2 -2
- package/dist/{lib/utils → utils}/system/stdout.d.ts +0 -3
- package/dist/utils/system/stdout.js +30 -11
- package/dist/utils/system/writeToFile.d.ts +1 -0
- package/dist/utils/system/writeToFile.js +1 -6
- package/dist/utils/system/zipFolder.js +3 -3
- package/dist/utils/system.js +2 -1
- package/package.json +23 -27
- package/README.md +0 -18
- package/dist/lib/cli/commands/auth/login.d.ts +0 -2
- package/dist/lib/utils/system/writeToFile.d.ts +0 -6
- package/dist/test/commands/auth/login.d.ts +0 -2
- package/dist/test/commands/auth/logout.d.ts +0 -2
- package/dist/test/commands/help.d.ts +0 -2
- package/dist/test/commands/theme/delete.d.ts +0 -2
- package/dist/test/commands/theme/dev.d.ts +0 -2
- package/dist/test/commands/theme/init.d.ts +0 -2
- package/dist/test/index.test.d.ts +0 -1
- package/dist/utils/system/openLink.js +0 -15
- /package/dist/{lib/cli/commands/auth/logout.d.ts → cli/commands/apps/create.d.ts} +0 -0
- /package/dist/{lib/cli/commands/store/info.d.ts → cli/commands/apps/install.d.ts} +0 -0
- /package/dist/{lib/cli/commands/store/switch.d.ts → cli/commands/auth/login.d.ts} +0 -0
- /package/dist/{lib/cli/commands/theme/delete.d.ts → cli/commands/auth/logout.d.ts} +0 -0
- /package/dist/{lib/cli → cli}/commands/auth/types.d.ts +0 -0
- /package/dist/{lib/cli/commands/theme/init.d.ts → cli/commands/store/info.d.ts} +0 -0
- /package/dist/{lib/cli/commands/theme/list.d.ts → cli/commands/store/switch.d.ts} +0 -0
- /package/dist/{lib/cli → cli}/commands/store/types.d.ts +0 -0
- /package/dist/{lib/cli/commands/theme/switch-store.d.ts → cli/commands/theme/delete.d.ts} +0 -0
- /package/dist/{lib/cli → cli}/commands/theme/dev.d.ts +0 -0
- /package/dist/{lib/cli → cli}/commands/theme/pack.d.ts +0 -0
- /package/dist/{lib/cli → cli}/commands/theme/pull.d.ts +0 -0
- /package/dist/{lib/cli → cli}/commands/theme/types.d.ts +0 -0
- /package/dist/{lib/cli → cli}/commands/types.d.ts +0 -0
- /package/dist/{lib/config → config}/index.d.ts +0 -0
- /package/dist/{lib/config → config}/messages.d.ts +0 -0
- /package/dist/{lib/core → core}/themes/preview.d.ts +0 -0
- /package/dist/{lib/index.d.ts → index.d.ts} +0 -0
- /package/dist/{lib/utils → utils}/git/cloneRepository.d.ts +0 -0
- /package/dist/{lib/utils → utils}/helpers.d.ts +0 -0
- /package/dist/{lib/utils → utils}/http.d.ts +0 -0
- /package/dist/{lib/utils → utils}/network.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system/deleteFile.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system/ls.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system/openLink.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system/saveFile.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system/zipFolder.d.ts +0 -0
- /package/dist/{lib/utils → utils}/system.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,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 };
|
|
@@ -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(
|
|
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',
|
|
33
|
+
await kill(pid, 'SIGTERM', 30_000);
|
|
35
34
|
}
|
|
36
35
|
catch (err) {
|
|
37
36
|
spinner.error('Could not terminate process, proceeding..');
|
|
@@ -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
|
},
|
|
@@ -8,3 +8,5 @@ export { default as ThemePullCommand } from './theme/pull';
|
|
|
8
8
|
export { default as ThemePackCommand } from './theme/pack';
|
|
9
9
|
export { default as StoreInfoCommand } from './store/info';
|
|
10
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
|
|
@@ -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();
|
|
@@ -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 });
|
|
@@ -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);
|
|
@@ -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
|
-
|
|
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:
|
|
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:
|
|
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
|
},
|
|
@@ -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
|
-
|
|
54
|
-
|
|
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);
|
|
@@ -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,
|
|
@@ -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
|
-
|
|
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()}`;
|
|
@@ -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);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as commands from './commands';
|
|
2
|
-
import type { CommandDefinition } from './commands/types';
|
|
2
|
+
import type { CLI, CommandDefinition } from './commands/types';
|
|
3
3
|
import Client from '@/core/client/client';
|
|
4
4
|
declare const cli: {
|
|
5
5
|
client: Client;
|
|
6
6
|
handler: import("cac").CAC;
|
|
7
|
-
registerCommand(command: (cli:
|
|
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)[];
|
|
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
9
|
init(): Promise<void>;
|
|
10
10
|
prepareClient(): Promise<void>;
|
|
11
11
|
};
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
package/dist/config/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { homedir } from 'os';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
var config = {
|
|
5
5
|
OAUTH_CLIENT_ID: 8,
|
|
6
|
-
OAUTH_CALLBACK_PORT:
|
|
6
|
+
OAUTH_CALLBACK_PORT: 3_000,
|
|
7
7
|
OAUTH_CALLBACK_SERVER_TIMEOUT: 5 * 60 * 100,
|
|
8
8
|
OAUTH_CALLBACK_URL: 'http://localhost:3000/',
|
|
9
9
|
OAUTH_CLIENT_SECRET: 'lvUw2mQ7nXp4WqZ9CZlURMgRGAra3KuOrYhFlU7X',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeleteThemeFileRequestData, InitThemeRequest as InitThemeRequestData, LoginRequest, LoginResponse, SelectStoreRequest, SelectStoreResponse, StoreInfoResponse, ThemeMetaResponse, UpdateThemeFileRequestData } from './types';
|
|
1
|
+
import type { CreateAppRequest, CreateAppResponse, DeleteThemeFileRequestData, GenerateAppInstallationUrlResponse, InitThemeRequest as InitThemeRequestData, LoginRequest, LoginResponse, SelectStoreRequest, SelectStoreResponse, StoreInfoResponse, ThemeMetaResponse, UpdateThemeFileRequestData } from './types';
|
|
2
2
|
import type { listStoresResponse } from '@/cli/commands/store/types';
|
|
3
3
|
export default class Client {
|
|
4
4
|
private accessToken;
|
|
@@ -17,5 +17,7 @@ export default class Client {
|
|
|
17
17
|
updateFile(themeId: string, data: UpdateThemeFileRequestData): Promise<void>;
|
|
18
18
|
deleteFile(themeId: string, data: DeleteThemeFileRequestData): Promise<void>;
|
|
19
19
|
getStoreInfo(): Promise<StoreInfoResponse>;
|
|
20
|
+
createApp(data: CreateAppRequest): Promise<CreateAppResponse>;
|
|
21
|
+
generateAppInstallationUrl(name: string): Promise<GenerateAppInstallationUrlResponse>;
|
|
20
22
|
private withDefaults;
|
|
21
23
|
}
|
|
@@ -6,9 +6,8 @@ import config from '../../config/index.js';
|
|
|
6
6
|
import { delay } from '../../utils/common.js';
|
|
7
7
|
|
|
8
8
|
class Client {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
accessToken = null;
|
|
10
|
+
constructor() { }
|
|
12
11
|
setAccessToken(token) {
|
|
13
12
|
this.accessToken = token;
|
|
14
13
|
}
|
|
@@ -62,6 +61,14 @@ class Client {
|
|
|
62
61
|
async getStoreInfo() {
|
|
63
62
|
return await get(`${config.SELLER_AREA_API_BASE_URI}/me`, this.withDefaults());
|
|
64
63
|
}
|
|
64
|
+
async createApp(data) {
|
|
65
|
+
const form = new FormData();
|
|
66
|
+
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
67
|
+
return await post(`${config.SELLER_AREA_API_BASE_URI}/apps/draft/create`, this.withDefaults({ body: form }));
|
|
68
|
+
}
|
|
69
|
+
async generateAppInstallationUrl(name) {
|
|
70
|
+
return await get(`${config.SELLER_AREA_API_BASE_URI}/apps/draft/generate-installation-url?name=${name}`, this.withDefaults());
|
|
71
|
+
}
|
|
65
72
|
withDefaults(override = {}) {
|
|
66
73
|
return mergeDeepLeft(override, {
|
|
67
74
|
headers: {
|
|
@@ -69,3 +69,12 @@ export interface ThemeMetaResponse {
|
|
|
69
69
|
snippets: ThemeFileInfo[];
|
|
70
70
|
assets: ThemeFileInfo[];
|
|
71
71
|
}
|
|
72
|
+
export interface CreateAppRequest {
|
|
73
|
+
name: string;
|
|
74
|
+
}
|
|
75
|
+
export interface CreateAppResponse {
|
|
76
|
+
name: string;
|
|
77
|
+
}
|
|
78
|
+
export interface GenerateAppInstallationUrlResponse {
|
|
79
|
+
url: string;
|
|
80
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer } from 'http';
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
2
|
import { Server } from 'socket.io';
|
|
3
3
|
import puppeteer from 'puppeteer';
|
|
4
4
|
import stdout from '../../utils/system/stdout.js';
|
|
@@ -10,8 +10,9 @@ async function openPreviewPage(url, disableHardwareAcceleration) {
|
|
|
10
10
|
defaultViewport: null,
|
|
11
11
|
userDataDir: '/tmp/youcan_puppeteer',
|
|
12
12
|
};
|
|
13
|
-
if (disableHardwareAcceleration)
|
|
13
|
+
if (disableHardwareAcceleration) {
|
|
14
14
|
options.args = ['--disable-gpu'];
|
|
15
|
+
}
|
|
15
16
|
const browser = await puppeteer.launch(options);
|
|
16
17
|
browser.on('disconnected', () => {
|
|
17
18
|
stdout.info('Browser closed');
|
|
@@ -10,7 +10,7 @@ export declare function getUserToken(): Promise<string>;
|
|
|
10
10
|
export declare function getCurrentThemeId(dir: PathLike): Promise<string | null>;
|
|
11
11
|
export declare class LoadingSpinner {
|
|
12
12
|
private message;
|
|
13
|
-
timer: NodeJS.
|
|
13
|
+
timer: NodeJS.Timeout | null;
|
|
14
14
|
constructor(message: string);
|
|
15
15
|
start(): this;
|
|
16
16
|
private flush;
|
package/dist/utils/common.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import kleur from 'kleur';
|
|
5
5
|
|
|
6
6
|
os.homedir();
|
|
7
7
|
async function getCurrentThemeId(dir) {
|
|
8
8
|
const filepath = path.resolve(dir.toString(), '.youcan');
|
|
9
|
-
if (!fs.existsSync(filepath))
|
|
9
|
+
if (!fs.existsSync(filepath)) {
|
|
10
10
|
return null;
|
|
11
|
+
}
|
|
11
12
|
return await fs.promises.readFile(filepath, 'utf-8')
|
|
12
13
|
.then(b => JSON.parse(b).theme_id);
|
|
13
14
|
}
|
|
14
15
|
class LoadingSpinner {
|
|
16
|
+
message;
|
|
17
|
+
timer;
|
|
15
18
|
constructor(message) {
|
|
16
19
|
this.message = message;
|
|
17
20
|
this.message = message;
|
|
@@ -41,7 +44,7 @@ class LoadingSpinner {
|
|
|
41
44
|
error(message = null) {
|
|
42
45
|
this.flush();
|
|
43
46
|
process.stdout.write('\r');
|
|
44
|
-
process.stdout.write(kleur.red(`✖ ${message
|
|
47
|
+
process.stdout.write(kleur.red(`✖ ${message ?? this.message}\n`));
|
|
45
48
|
return this;
|
|
46
49
|
}
|
|
47
50
|
static async exec(message, closure) {
|
package/dist/utils/helpers.js
CHANGED
|
@@ -2,22 +2,25 @@ function stripln(buffer, ln) {
|
|
|
2
2
|
let index = 0;
|
|
3
3
|
while (ln-- > 0) {
|
|
4
4
|
const lfIndex = buffer.indexOf('\n', index);
|
|
5
|
-
if (lfIndex >= 0)
|
|
5
|
+
if (lfIndex >= 0) {
|
|
6
6
|
index = lfIndex + 1;
|
|
7
|
+
}
|
|
7
8
|
}
|
|
8
9
|
return index > 0 ? buffer.substring(index) : buffer;
|
|
9
10
|
}
|
|
10
11
|
function splitln(buffer, limit) {
|
|
11
12
|
const cols = buffer.trim().split(/\s+/);
|
|
12
|
-
if (cols.length > limit)
|
|
13
|
+
if (cols.length > limit) {
|
|
13
14
|
cols[limit - 1] = cols.slice(limit - 1).join(' ');
|
|
15
|
+
}
|
|
14
16
|
return cols;
|
|
15
17
|
}
|
|
16
18
|
function getcols(buffer, indices, limit = null) {
|
|
17
19
|
const lines = buffer.split(/(\r\n|\n|\r)/);
|
|
18
20
|
const cols = [];
|
|
19
|
-
if (!limit)
|
|
21
|
+
if (!limit) {
|
|
20
22
|
limit = Math.max.apply(null, indices) + 1;
|
|
23
|
+
}
|
|
21
24
|
lines.forEach((ln) => {
|
|
22
25
|
const lncols = splitln(ln, limit);
|
|
23
26
|
const lncol = [];
|
package/dist/utils/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent } from 'https';
|
|
1
|
+
import { Agent } from 'node:https';
|
|
2
2
|
import fetch from 'node-fetch';
|
|
3
3
|
import { mergeDeepLeft } from 'ramda';
|
|
4
4
|
|
|
@@ -11,8 +11,9 @@ const DEFAULT_HTTP_CLIENT_OPTIONS = {
|
|
|
11
11
|
};
|
|
12
12
|
async function request(endpoint, options = {}) {
|
|
13
13
|
const response = await fetch(endpoint, mergeDeepLeft(options, DEFAULT_HTTP_CLIENT_OPTIONS));
|
|
14
|
-
if (!response.ok)
|
|
14
|
+
if (!response.ok) {
|
|
15
15
|
throw new Error(await response.text(), { cause: response });
|
|
16
|
+
}
|
|
16
17
|
return response.json();
|
|
17
18
|
}
|
|
18
19
|
async function get(endpoint, options = {}) {
|
package/dist/utils/network.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createServer } from 'net';
|
|
2
|
-
import { platform } from 'process';
|
|
1
|
+
import { createServer } from 'node:net';
|
|
2
|
+
import { platform } from 'node:process';
|
|
3
3
|
import { execaCommand } from 'execa';
|
|
4
4
|
import stdout from './system/stdout.js';
|
|
5
5
|
import { stripln, getcols } from './helpers.js';
|
|
@@ -9,8 +9,9 @@ async function isPortAvailable(port) {
|
|
|
9
9
|
const server = createServer();
|
|
10
10
|
server.once('error', (err) => {
|
|
11
11
|
server.close();
|
|
12
|
-
if (err.code === 'EADDRINUSE')
|
|
12
|
+
if (err.code === 'EADDRINUSE') {
|
|
13
13
|
resolve(false);
|
|
14
|
+
}
|
|
14
15
|
reject(err);
|
|
15
16
|
});
|
|
16
17
|
server.once('listening', () => {
|
|
@@ -32,8 +33,9 @@ const PID_GETTER_CLASS_MAP = {
|
|
|
32
33
|
const matches = col[1].match(/\.(\d+)$/);
|
|
33
34
|
return matches && matches[1] === String(port);
|
|
34
35
|
});
|
|
35
|
-
if (col && col[2].length)
|
|
36
|
+
if (col && col[2].length) {
|
|
36
37
|
return (parseInt(col[2], 10));
|
|
38
|
+
}
|
|
37
39
|
return null;
|
|
38
40
|
},
|
|
39
41
|
async linux(port) {
|
|
@@ -47,8 +49,9 @@ const PID_GETTER_CLASS_MAP = {
|
|
|
47
49
|
});
|
|
48
50
|
if (cols && cols[1]) {
|
|
49
51
|
const pid = cols[1].split('/', 1)[0];
|
|
50
|
-
if (pid.length)
|
|
52
|
+
if (pid.length) {
|
|
51
53
|
return parseInt(pid, 10);
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
return null;
|
|
54
57
|
},
|
|
@@ -61,14 +64,16 @@ const PID_GETTER_CLASS_MAP = {
|
|
|
61
64
|
const matches = col[0].match(/:(\d+)$/);
|
|
62
65
|
return matches && matches[1] === String(port);
|
|
63
66
|
});
|
|
64
|
-
if (cols && cols[1].length && parseInt(cols[1], 10) > 0)
|
|
67
|
+
if (cols && cols[1].length && parseInt(cols[1], 10) > 0) {
|
|
65
68
|
return parseInt(cols[1], 10);
|
|
69
|
+
}
|
|
66
70
|
return null;
|
|
67
71
|
},
|
|
68
72
|
};
|
|
69
73
|
async function getPidByPort(port) {
|
|
70
|
-
if (!(platform in PID_GETTER_CLASS_MAP))
|
|
74
|
+
if (!(platform in PID_GETTER_CLASS_MAP)) {
|
|
71
75
|
throw new Error('Unsupported platform, process will have to be killed manually.');
|
|
76
|
+
}
|
|
72
77
|
const getter = PID_GETTER_CLASS_MAP[platform];
|
|
73
78
|
return await getter(port);
|
|
74
79
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param filePath - The path of the file to delete.
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
function deleteFile(filePath) {
|
|
8
|
-
if (fs.existsSync(filePath))
|
|
8
|
+
if (fs.existsSync(filePath)) {
|
|
9
9
|
fs.unlinkSync(filePath);
|
|
10
|
+
}
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export { deleteFile as default };
|
package/dist/utils/system/ls.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import kleur from 'kleur';
|
|
2
2
|
|
|
3
3
|
const stdout = console;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
|
|
4
|
+
function log(arg) {
|
|
5
|
+
return stdout.log(kleur.gray(arg));
|
|
6
|
+
}
|
|
7
|
+
function info(arg) {
|
|
8
|
+
return log(kleur.blue(arg));
|
|
9
|
+
}
|
|
10
|
+
function warn(arg) {
|
|
11
|
+
return log(kleur.yellow(arg));
|
|
12
|
+
}
|
|
13
|
+
function error(arg) {
|
|
14
|
+
return log(kleur.bgRed().white(arg));
|
|
15
|
+
}
|
|
16
|
+
function success(arg) {
|
|
17
|
+
return log(kleur.green(arg));
|
|
18
|
+
}
|
|
19
|
+
function clear() {
|
|
20
|
+
return stdout.clear();
|
|
21
|
+
}
|
|
22
|
+
function table(arg) {
|
|
23
|
+
return stdout.table(arg);
|
|
24
|
+
}
|
|
25
|
+
var stdout$1 = {
|
|
26
|
+
log,
|
|
27
|
+
info,
|
|
28
|
+
warn,
|
|
29
|
+
error,
|
|
30
|
+
clear,
|
|
31
|
+
success,
|
|
32
|
+
table,
|
|
33
|
+
};
|
|
15
34
|
|
|
16
35
|
export { stdout$1 as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function writeToFile(filePath: string, content: string): void;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* @param filePath - The path to the file to write to.
|
|
5
|
-
* @param content - The content to write to the file.
|
|
6
|
-
* @returns A promise that resolves when the file has been written.
|
|
7
|
-
*/
|
|
8
3
|
function writeToFile(filePath, content) {
|
|
9
4
|
return fs.writeFileSync(filePath, content, { encoding: 'utf-8', flag: 'w' });
|
|
10
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
import archiver from 'archiver';
|
|
4
4
|
import { lsDir } from './ls.js';
|
|
5
5
|
|
|
@@ -30,7 +30,7 @@ async function zipFolder(folderPath, folderName) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
async function zipDirectory(dirPath, folderName, only) {
|
|
33
|
-
const ls = lsDir(dirPath).filter(folder => only
|
|
33
|
+
const ls = lsDir(dirPath).filter(folder => only?.includes(folder));
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
35
|
try {
|
|
36
36
|
const zip = path.resolve(dirPath, `${folderName}.zip`);
|
package/dist/utils/system.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youcan/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.1.0-beta.0",
|
|
5
5
|
"description": "YouCan CLI for developers.",
|
|
6
6
|
"author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
|
|
7
7
|
"keywords": [],
|
|
@@ -21,50 +21,46 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"archiver": "^5.3.
|
|
24
|
+
"archiver": "^5.3.2",
|
|
25
25
|
"cac": "^6.7.14",
|
|
26
26
|
"chokidar": "^3.5.3",
|
|
27
27
|
"decompress": "^4.2.1",
|
|
28
28
|
"execa": "^6.1.0",
|
|
29
|
-
"formdata-node": "^5.0.
|
|
29
|
+
"formdata-node": "^5.0.1",
|
|
30
30
|
"kleur": "^4.1.5",
|
|
31
|
-
"node-fetch": "^3.2
|
|
31
|
+
"node-fetch": "^3.3.2",
|
|
32
32
|
"prompts": "^2.4.2",
|
|
33
|
-
"puppeteer": "^19.
|
|
33
|
+
"puppeteer": "^19.11.1",
|
|
34
34
|
"ramda": "^0.28.0",
|
|
35
|
-
"socket.io": "^4.
|
|
36
|
-
"socket.io-client": "^4.
|
|
35
|
+
"socket.io": "^4.7.2",
|
|
36
|
+
"socket.io-client": "^4.7.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@azuradara/eslint-config-base": "^0.1.3",
|
|
40
40
|
"@azuradara/eslint-config-ts": "^0.1.3",
|
|
41
|
-
"@
|
|
41
|
+
"@oclif/plugin-autocomplete": "^2.3.8",
|
|
42
|
+
"@oclif/plugin-commands": "^2.2.26",
|
|
43
|
+
"@types/archiver": "^5.3.3",
|
|
42
44
|
"@types/file-saver": "^2.0.5",
|
|
43
|
-
"@types/node": "^18.
|
|
44
|
-
"@types/prompts": "^2.4.
|
|
45
|
-
"@types/ramda": "^0.28.
|
|
45
|
+
"@types/node": "^18.18.0",
|
|
46
|
+
"@types/prompts": "^2.4.5",
|
|
47
|
+
"@types/ramda": "^0.28.25",
|
|
46
48
|
"@types/rimraf": "^3.0.2",
|
|
47
|
-
"@vitest/coverage-c8": "^0.25.2",
|
|
48
|
-
"@vitest/ui": "^0.25.2",
|
|
49
|
-
"bumpp": "^8.2.1",
|
|
50
|
-
"eslint": "^8.27.0",
|
|
51
49
|
"esno": "^0.16.3",
|
|
52
|
-
"pnpm": "^7.
|
|
50
|
+
"pnpm": "^7.33.6",
|
|
53
51
|
"rimraf": "^3.0.2",
|
|
54
|
-
"rollup": "^3.
|
|
55
|
-
"rollup-plugin-dts": "^5.
|
|
52
|
+
"rollup": "^3.29.3",
|
|
53
|
+
"rollup-plugin-dts": "^5.3.1",
|
|
54
|
+
"rollup-plugin-node-externals": "^6.1.1",
|
|
56
55
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"vitest": "^0.24.5"
|
|
56
|
+
"shx": "^0.3.4",
|
|
57
|
+
"typescript": "^4.9.5"
|
|
60
58
|
},
|
|
61
59
|
"scripts": {
|
|
62
|
-
"build": "tsc --noEmit && rollup --config rollup.config.js",
|
|
60
|
+
"build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
|
|
63
61
|
"dev": "rollup --config rollup.config.js --watch",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"test": "vitest",
|
|
68
|
-
"check": "pnpm typecheck && pnpm lint && pnpm run test"
|
|
62
|
+
"release": "pnpm publish --access public",
|
|
63
|
+
"type-check": "tsc --noEmit",
|
|
64
|
+
"relink": "pnpm link --global"
|
|
69
65
|
}
|
|
70
66
|
}
|
package/README.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# youcan-cli
|
|
2
|
-
|
|
3
|
-
YouCan CLI is a command line utility for building custom YouCan themes. It can be installed and run on Mac, Linux, and Windows systems. Using the CLI requires you to have pre-requisite knowledge of the YouCan themes system documented [here](https://developer.youcan.shop/).
|
|
4
|
-
|
|
5
|
-
## Requirements
|
|
6
|
-
|
|
7
|
-
The YouCan CLI requires that you install the latest version of [Node.js](https://nodejs.org/en/download/) and [npm](https://docs.npmjs.com/getting-started), or whichever node package manger you prefer.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```shell
|
|
12
|
-
npm install -g @youcan/cli
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Help
|
|
16
|
-
|
|
17
|
-
- [Open a GitHub issue](https://github.com/youcan-shop/youcan-cli/issues) - For bug reports and feature requests, you can open an issue in the YouCan CLI repository.
|
|
18
|
-
- [CLI documentation - Theme development](https://developer.youcan.shop/themes/cli/introduction.html) - Visit our documentation for guides on getting started with YouCan Theme development.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
|
|
3
|
-
const { platform } = process;
|
|
4
|
-
const PLATFORM_OPEN_CMD_MAP = {
|
|
5
|
-
win32: 'cmd /c start',
|
|
6
|
-
linux: 'xdg-open',
|
|
7
|
-
darwin: 'open',
|
|
8
|
-
};
|
|
9
|
-
function openLink(url) {
|
|
10
|
-
if (!(platform in PLATFORM_OPEN_CMD_MAP))
|
|
11
|
-
throw new Error('Platform not supported');
|
|
12
|
-
execSync(`${PLATFORM_OPEN_CMD_MAP[platform]} '${url}'`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { openLink as default };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|