@youcan/cli 1.0.1 → 1.0.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.
- package/README.md +1 -1
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/theme/init.js +1 -1
- package/dist/cli/commands/theme/pack.js +28 -0
- package/dist/lib/cli/commands/index.d.ts +1 -0
- package/dist/lib/cli/commands/theme/pack.d.ts +2 -0
- package/dist/lib/cli/index.d.ts +1 -1
- package/dist/lib/utils/common.d.ts +1 -0
- package/dist/lib/utils/system/ls.d.ts +1 -0
- package/dist/lib/utils/system/zipFolder.d.ts +2 -1
- package/dist/utils/common.js +8 -1
- package/dist/utils/system/ls.js +9 -0
- package/dist/utils/system/zipFolder.js +26 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,4 +15,4 @@ npm install -g @youcan/cli
|
|
|
15
15
|
## Help
|
|
16
16
|
|
|
17
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
|
|
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.
|
|
@@ -4,5 +4,6 @@ export { default as InitCommand } from './theme/init.js';
|
|
|
4
4
|
export { default as DevCommand } from './theme/dev.js';
|
|
5
5
|
export { default as DeleteCommand } from './theme/delete.js';
|
|
6
6
|
export { default as PullCommand } from './theme/pull.js';
|
|
7
|
+
export { default as PackCommand } from './theme/pack.js';
|
|
7
8
|
|
|
8
9
|
// auth
|
|
@@ -5,7 +5,7 @@ import { fileFromPath } from 'formdata-node/file-from-path';
|
|
|
5
5
|
import config from '../../../config/index.js';
|
|
6
6
|
import cloneRepository from '../../../utils/git/cloneRepository.js';
|
|
7
7
|
import stdout from '../../../utils/system/stdout.js';
|
|
8
|
-
import zipFolder from '../../../utils/system/zipFolder.js';
|
|
8
|
+
import { zipFolder } from '../../../utils/system/zipFolder.js';
|
|
9
9
|
import writeToFile from '../../../utils/system/writeToFile.js';
|
|
10
10
|
import deleteFile from '../../../utils/system/deleteFile.js';
|
|
11
11
|
import messages from '../../../config/messages.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cwd } from 'process';
|
|
2
|
+
import stdout from '../../../utils/system/stdout.js';
|
|
3
|
+
import { getCurrentThemeId, getCurrentDate, LoadingSpinner } from '../../../utils/common.js';
|
|
4
|
+
import messages from '../../../config/messages.js';
|
|
5
|
+
import { zipDirectory } from '../../../utils/system/zipFolder.js';
|
|
6
|
+
|
|
7
|
+
function command(cli) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'pack',
|
|
10
|
+
group: 'theme',
|
|
11
|
+
description: 'Package a theme',
|
|
12
|
+
options: [],
|
|
13
|
+
action: async () => {
|
|
14
|
+
if (!cli.client.isAuthenticated())
|
|
15
|
+
return stdout.error(messages.AUTH_USER_NOT_LOGGED_IN);
|
|
16
|
+
if (!await getCurrentThemeId(cwd()))
|
|
17
|
+
return stdout.error('No theme found in the current directory');
|
|
18
|
+
const loading = new LoadingSpinner('📦 Packaging your theme');
|
|
19
|
+
loading.start();
|
|
20
|
+
const exportFolder = `theme_${getCurrentDate()}`;
|
|
21
|
+
await zipDirectory(cwd(), exportFolder);
|
|
22
|
+
loading.stop();
|
|
23
|
+
return stdout.info(`your theme was successfully packaged to ${exportFolder}`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { command as default };
|
|
@@ -4,3 +4,4 @@ export { default as InitCommand } from './theme/init';
|
|
|
4
4
|
export { default as DevCommand } from './theme/dev';
|
|
5
5
|
export { default as DeleteCommand } from './theme/delete';
|
|
6
6
|
export { default as PullCommand } from './theme/pull';
|
|
7
|
+
export { default as PackCommand } from './theme/pack';
|
package/dist/lib/cli/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare const cli: {
|
|
|
5
5
|
client: Client;
|
|
6
6
|
handler: import("cac").CAC;
|
|
7
7
|
registerCommand(command: (cli: typeof this) => CommandDefinition): void;
|
|
8
|
-
getAvailableCommands(): (typeof commands.LoginCommand | typeof commands.LogoutCommand | typeof commands.InitCommand | typeof commands.DevCommand | typeof commands.DeleteCommand | typeof commands.PullCommand)[];
|
|
8
|
+
getAvailableCommands(): (typeof commands.LoginCommand | typeof commands.LogoutCommand | typeof commands.InitCommand | typeof commands.DevCommand | typeof commands.DeleteCommand | typeof commands.PullCommand | typeof commands.PackCommand)[];
|
|
9
9
|
init(): Promise<void>;
|
|
10
10
|
prepareClient(): Promise<void>;
|
|
11
11
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function lsDir(path: string): string[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Zip folder and save it to a given path and return zip folder path
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export declare function zipFolder(folderPath: string, folderName: string): Promise<string>;
|
|
5
|
+
export declare function zipDirectory(dirPath: string, folderName: string): Promise<unknown>;
|
package/dist/utils/common.js
CHANGED
|
@@ -52,6 +52,13 @@ class LoadingSpinner {
|
|
|
52
52
|
}
|
|
53
53
|
function delay(ms) {
|
|
54
54
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
55
|
+
}
|
|
56
|
+
function getCurrentDate() {
|
|
57
|
+
const date = new Date();
|
|
58
|
+
const day = date.getDate();
|
|
59
|
+
const month = date.getMonth() + 1;
|
|
60
|
+
const year = date.getFullYear();
|
|
61
|
+
return `${day}-${month}-${year}`;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
export { LoadingSpinner, delay, getCurrentThemeId };
|
|
64
|
+
export { LoadingSpinner, delay, getCurrentDate, getCurrentThemeId };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import archiver from 'archiver';
|
|
4
|
+
import { lsDir } from './ls.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Zip folder and save it to a given path and return zip folder path
|
|
@@ -27,6 +28,30 @@ async function zipFolder(folderPath, folderName) {
|
|
|
27
28
|
reject(err);
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
}
|
|
32
|
+
async function zipDirectory(dirPath, folderName) {
|
|
33
|
+
const ls = lsDir(dirPath);
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
try {
|
|
36
|
+
const zip = path.resolve(dirPath, `${folderName}.zip`);
|
|
37
|
+
const output = fs.createWriteStream(zip);
|
|
38
|
+
const archive = archiver('zip', {
|
|
39
|
+
zlib: { level: 9 },
|
|
40
|
+
});
|
|
41
|
+
output.on('close', () => {
|
|
42
|
+
resolve(zip);
|
|
43
|
+
});
|
|
44
|
+
archive.on('error', (err) => {
|
|
45
|
+
reject(err);
|
|
46
|
+
});
|
|
47
|
+
archive.pipe(output);
|
|
48
|
+
ls.forEach(folder => archive.directory(path.resolve(dirPath, folder), folder));
|
|
49
|
+
archive.finalize();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
reject(err);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
30
55
|
}
|
|
31
56
|
|
|
32
|
-
export { zipFolder
|
|
57
|
+
export { zipDirectory, zipFolder };
|