@youcan/theme 1.1.0-beta.10
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/dist/cli/commands/theme/init.d.ts +15 -0
- package/dist/cli/commands/theme/init.js +116 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +3 -0
- package/dist/flags.d.ts +3 -0
- package/dist/flags.js +13 -0
- package/dist/util/theme-command.d.ts +4 -0
- package/dist/util/theme-command.js +10 -0
- package/package.json +35 -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.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ThemeCommand } from '@/util/theme-command';
|
|
2
|
+
declare class Init extends ThemeCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
name: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static flags: {
|
|
8
|
+
url: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
path: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
'no-color': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
export default Init;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { Cli, Session, Path, Tasks, Git, Filesystem, Form, Http, Env } from '@youcan/cli-kit';
|
|
3
|
+
import { ThemeCommand } from '../../../util/theme-command.js';
|
|
4
|
+
import { THEME_FLAGS } from '../../../flags.js';
|
|
5
|
+
import { THEME_CONFIG_FILENAME } from '../../../constants.js';
|
|
6
|
+
|
|
7
|
+
class Init extends ThemeCommand {
|
|
8
|
+
static description = 'Clones a theme template Git repo.';
|
|
9
|
+
static args = {
|
|
10
|
+
name: Args.string({
|
|
11
|
+
name: 'name',
|
|
12
|
+
required: false,
|
|
13
|
+
description: 'A name for the new theme',
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
static flags = {
|
|
17
|
+
...Cli.commonFlags,
|
|
18
|
+
...THEME_FLAGS,
|
|
19
|
+
url: Flags.string({
|
|
20
|
+
char: 'u',
|
|
21
|
+
env: 'YC_FLAG_CLONE_URL',
|
|
22
|
+
description: 'The Git URL to clone from',
|
|
23
|
+
default: 'https://github.com/youcan-shop/light-theme',
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(Init);
|
|
28
|
+
const session = await Session.authenticate(this);
|
|
29
|
+
const answers = await (prompt(this));
|
|
30
|
+
const dest = Path.join(flags.path, answers.theme_name);
|
|
31
|
+
await Tasks.run({
|
|
32
|
+
payload: answers,
|
|
33
|
+
theme_id: null,
|
|
34
|
+
cmd: this,
|
|
35
|
+
}, [
|
|
36
|
+
{
|
|
37
|
+
title: `Cloning ${flags.url} into ${dest}...`,
|
|
38
|
+
task: async () => {
|
|
39
|
+
await Git.clone({ url: flags.url, destination: dest });
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: 'Initializing development theme...',
|
|
44
|
+
task: async (ctx) => {
|
|
45
|
+
const path = await Filesystem.archived(Path.cwd(), answers.theme_name);
|
|
46
|
+
Object.assign(ctx.payload, { archive: await Form.file(path) });
|
|
47
|
+
const form = Form.convert(ctx.payload);
|
|
48
|
+
const res = await Http.post(`${Env.apiHostname()}/themes/init`, {
|
|
49
|
+
headers: { Authorization: `Bearer ${session.access_token}` },
|
|
50
|
+
body: form,
|
|
51
|
+
});
|
|
52
|
+
ctx.theme_id = res.id;
|
|
53
|
+
await Filesystem.unlink(path);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: 'Cleaning up...',
|
|
58
|
+
task: async (ctx) => {
|
|
59
|
+
await Filesystem.writeJsonFile(Path.join(Path.cwd(), ctx.payload.theme_name, THEME_CONFIG_FILENAME), { theme_id: ctx.theme_id });
|
|
60
|
+
ctx.cmd.output.info(`\nDevelopment theme '${ctx.theme_id}' initiated!`);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function prompt(command) {
|
|
67
|
+
return command.prompt([
|
|
68
|
+
{
|
|
69
|
+
name: 'theme_name',
|
|
70
|
+
type: 'text',
|
|
71
|
+
initial: 'light-theme',
|
|
72
|
+
message: 'Your theme\'s name',
|
|
73
|
+
validate: (v) => {
|
|
74
|
+
if (!v.length) {
|
|
75
|
+
return 'Theme name cannot be empty';
|
|
76
|
+
}
|
|
77
|
+
if (v.length > 32) {
|
|
78
|
+
return 'Theme name cannot exceed 32 characters';
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: 'text',
|
|
85
|
+
name: 'theme_name',
|
|
86
|
+
message: 'The theme\'s name, used for display purposes.',
|
|
87
|
+
initial: 'Starter',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'text',
|
|
91
|
+
name: 'theme_author',
|
|
92
|
+
message: 'The theme\'s author',
|
|
93
|
+
initial: 'YouCan',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'text',
|
|
97
|
+
name: 'theme_version',
|
|
98
|
+
message: 'The theme\'s current version',
|
|
99
|
+
initial: '1.0.0',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
name: 'theme_support_url',
|
|
104
|
+
message: 'A support URL for this theme.',
|
|
105
|
+
initial: 'https://developer.youcan.shop',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: 'text',
|
|
109
|
+
name: 'theme_documentation_url',
|
|
110
|
+
message: 'A documentation URL for this theme.',
|
|
111
|
+
initial: 'https://developer.youcan.shop',
|
|
112
|
+
},
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { Init as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const THEME_CONFIG_FILENAME = "youcan.theme.json";
|
package/dist/flags.d.ts
ADDED
package/dist/flags.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { Path } from '@youcan/cli-kit';
|
|
3
|
+
|
|
4
|
+
const THEME_FLAGS = {
|
|
5
|
+
path: Flags.string({
|
|
6
|
+
env: 'YC_FLAG_PATH',
|
|
7
|
+
default: async () => Path.cwd(),
|
|
8
|
+
parse: async (input) => Path.resolve(input),
|
|
9
|
+
description: 'The path to your theme directory.',
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { THEME_FLAGS };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@youcan/theme",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.1.0-beta.10",
|
|
5
|
+
"description": "OCLIF plugin for building themes",
|
|
6
|
+
"author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"youcan",
|
|
10
|
+
"youcan-cli",
|
|
11
|
+
"youcan-theme"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"oclif.manifest.json"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@oclif/core": "^2.15.0",
|
|
19
|
+
"@youcan/cli-kit": "1.1.0-beta.10"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@oclif/plugin-legacy": "^1.3.0",
|
|
23
|
+
"@types/node": "^18.18.0",
|
|
24
|
+
"shx": "^0.3.4"
|
|
25
|
+
},
|
|
26
|
+
"oclif": {
|
|
27
|
+
"commands": "./dist/cli/commands"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
|
|
31
|
+
"dev": "shx rm -rf dist && rollup --config rollup.config.js --watch",
|
|
32
|
+
"release": "pnpm publish --access public",
|
|
33
|
+
"type-check": "tsc --noEmit"
|
|
34
|
+
}
|
|
35
|
+
}
|