@youcan/app 2.1.4 → 2.3.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.
Files changed (36) hide show
  1. package/dist/cli/commands/app/dev.d.ts +13 -6
  2. package/dist/cli/commands/app/dev.js +89 -51
  3. package/dist/cli/commands/app/env/show.d.ts +7 -0
  4. package/dist/cli/commands/app/env/show.js +29 -0
  5. package/dist/cli/commands/app/generate/extension.d.ts +6 -6
  6. package/dist/cli/commands/app/generate/extension.js +50 -50
  7. package/dist/cli/commands/app/install.d.ts +5 -5
  8. package/dist/cli/commands/app/install.js +21 -21
  9. package/dist/cli/services/dev/workers/app-worker.d.ts +11 -10
  10. package/dist/cli/services/dev/workers/app-worker.js +29 -30
  11. package/dist/cli/services/dev/workers/index.d.ts +14 -10
  12. package/dist/cli/services/dev/workers/index.js +25 -19
  13. package/dist/cli/services/dev/workers/theme-extension-worker.d.ts +15 -15
  14. package/dist/cli/services/dev/workers/theme-extension-worker.js +113 -113
  15. package/dist/cli/services/dev/workers/tunnel-worker.d.ts +15 -0
  16. package/dist/cli/services/dev/workers/tunnel-worker.js +57 -0
  17. package/dist/cli/services/dev/workers/web-worker.d.ts +12 -11
  18. package/dist/cli/services/dev/workers/web-worker.js +26 -23
  19. package/dist/cli/services/generate/extensions/index.d.ts +2 -2
  20. package/dist/cli/services/generate/extensions/index.js +2 -2
  21. package/dist/cli/services/generate/extensions/theme-extension.d.ts +3 -3
  22. package/dist/cli/services/generate/extensions/theme-extension.js +17 -17
  23. package/dist/cli/services/generate/generate.d.ts +10 -10
  24. package/dist/cli/services/generate/generate.js +24 -24
  25. package/dist/constants.d.ts +5 -5
  26. package/dist/constants.js +4 -4
  27. package/dist/flags.d.ts +3 -3
  28. package/dist/flags.js +7 -7
  29. package/dist/types.d.ts +84 -69
  30. package/dist/util/app-command.d.ts +8 -0
  31. package/dist/util/app-command.js +41 -0
  32. package/dist/util/app-loader.d.ts +2 -2
  33. package/dist/util/app-loader.js +35 -35
  34. package/package.json +8 -3
  35. package/dist/util/theme-command.d.ts +0 -3
  36. package/dist/util/theme-command.js +0 -6
package/dist/types.d.ts CHANGED
@@ -1,69 +1,84 @@
1
- export interface InitialAppConfig {
2
- [key: string]: unknown;
3
- name: string;
4
- }
5
- export type AppConfig = {
6
- id: string;
7
- app_url: string;
8
- redirect_urls: string[];
9
- oauth: {
10
- client_id: string;
11
- scopes: string[];
12
- };
13
- } & InitialAppConfig;
14
- export interface ExtensionConfig {
15
- [key: string]: unknown;
16
- type: string;
17
- name: string;
18
- }
19
- export interface ExtensionFlavor {
20
- name: string;
21
- path?: string;
22
- value: 'liquid';
23
- }
24
- export interface ExtensionTemplateType {
25
- url: string;
26
- type: string;
27
- flavors: ExtensionFlavor[];
28
- }
29
- export interface ExtensionTemplate {
30
- identifier: string;
31
- name: string;
32
- description: string;
33
- types: ExtensionTemplateType[];
34
- }
35
- export interface Extension {
36
- id?: string;
37
- metadata?: ExtensionMetadata;
38
- root: string;
39
- config: ExtensionConfig;
40
- }
41
- export interface WebConfig {
42
- name?: string;
43
- commands: {
44
- dev: string;
45
- build?: string;
46
- };
47
- }
48
- export interface Web {
49
- root: string;
50
- config: WebConfig;
51
- framework?: string;
52
- }
53
- export interface App {
54
- root: string;
55
- webs: Web[];
56
- config: AppConfig;
57
- extensions: Extension[];
58
- }
59
- export interface ExtensionFileDescriptor {
60
- id: string;
61
- type: string;
62
- name: string;
63
- file_name: string;
64
- size: number;
65
- hash: string;
66
- }
67
- export interface ExtensionMetadata {
68
- [key: string]: ExtensionFileDescriptor[];
69
- }
1
+ export interface InitialAppConfig {
2
+ [key: string]: unknown;
3
+ name: string;
4
+ }
5
+ export type AppConfig = {
6
+ id: string;
7
+ app_url: string;
8
+ redirect_urls: string[];
9
+ oauth: {
10
+ client_id: string;
11
+ scopes: string[];
12
+ };
13
+ } & InitialAppConfig;
14
+ export interface RemoteAppConfig {
15
+ id: string;
16
+ name: string;
17
+ app_url: string;
18
+ owner_id: string;
19
+ client_id: string;
20
+ client_secret: string;
21
+ redirect_urls: string[];
22
+ scopes: string[];
23
+ }
24
+ export interface ExtensionConfig {
25
+ [key: string]: unknown;
26
+ type: string;
27
+ name: string;
28
+ }
29
+ export interface ExtensionFlavor {
30
+ name: string;
31
+ path?: string;
32
+ value: 'liquid';
33
+ }
34
+ export interface ExtensionTemplateType {
35
+ url: string;
36
+ type: string;
37
+ flavors: ExtensionFlavor[];
38
+ }
39
+ export interface ExtensionTemplate {
40
+ identifier: string;
41
+ name: string;
42
+ description: string;
43
+ types: ExtensionTemplateType[];
44
+ }
45
+ export interface Extension {
46
+ id?: string;
47
+ metadata?: ExtensionMetadata;
48
+ root: string;
49
+ config: ExtensionConfig;
50
+ }
51
+ export interface WebConfig {
52
+ name?: string;
53
+ commands: {
54
+ dev: string;
55
+ build?: string;
56
+ };
57
+ }
58
+ export interface Web {
59
+ root: string;
60
+ config: WebConfig;
61
+ framework?: string;
62
+ }
63
+ export interface App {
64
+ root: string;
65
+ webs: Web[];
66
+ config: AppConfig;
67
+ remoteConfig?: RemoteAppConfig;
68
+ networkConfig?: {
69
+ appUrl: string;
70
+ port: number;
71
+ };
72
+ extensions: Extension[];
73
+ }
74
+ export interface ExtensionFileDescriptor {
75
+ id: string;
76
+ type: string;
77
+ name: string;
78
+ file_name: string;
79
+ size: number;
80
+ hash: string;
81
+ }
82
+ export interface ExtensionMetadata {
83
+ [key: string]: ExtensionFileDescriptor[];
84
+ }
@@ -0,0 +1,8 @@
1
+ import type { Session } from '@youcan/cli-kit';
2
+ import { Cli } from '@youcan/cli-kit';
3
+ import type { App } from '@/types';
4
+ export declare abstract class AppCommand extends Cli.Command {
5
+ protected app: App;
6
+ protected session: Session.StoreSession;
7
+ syncAppConfig(): Promise<App>;
8
+ }
@@ -0,0 +1,41 @@
1
+ import { Cli, Env, Http, Filesystem, Path } from '@youcan/cli-kit';
2
+ import { APP_CONFIG_FILENAME } from '../constants.js';
3
+
4
+ class AppCommand extends Cli.Command {
5
+ app;
6
+ session;
7
+ async syncAppConfig() {
8
+ const endpoint = this.app.config.id == null
9
+ ? `${Env.apiHostname()}/apps/create`
10
+ : `${Env.apiHostname()}/apps/${this.app.config.id}/update`;
11
+ if (!this.app.networkConfig) {
12
+ throw new Error('app network config is not set');
13
+ }
14
+ const backUrl = new URL('/auth/callback', this.app.networkConfig.appUrl).toString();
15
+ const res = await Http.post(endpoint, {
16
+ headers: { Authorization: `Bearer ${this.session.access_token}` },
17
+ body: JSON.stringify({
18
+ name: this.app.config.name,
19
+ app_url: this.app.networkConfig.appUrl,
20
+ redirect_urls: [
21
+ backUrl,
22
+ ],
23
+ }),
24
+ });
25
+ this.app.config = {
26
+ name: res.name,
27
+ id: res.id,
28
+ app_url: res.app_url,
29
+ redirect_urls: res.redirect_urls,
30
+ oauth: {
31
+ scopes: res.scopes,
32
+ client_id: res.client_id,
33
+ },
34
+ };
35
+ await Filesystem.writeJsonFile(Path.join(this.app.root, APP_CONFIG_FILENAME), this.app.config);
36
+ this.app.remoteConfig = res;
37
+ return this.app;
38
+ }
39
+ }
40
+
41
+ export { AppCommand };
@@ -1,2 +1,2 @@
1
- import type { App } from '@/types';
2
- export declare function load(): Promise<App>;
1
+ import type { App } from '@/types';
2
+ export declare function load(): Promise<App>;
@@ -1,41 +1,41 @@
1
1
  import { Path, Filesystem } from '@youcan/cli-kit';
2
2
  import { APP_CONFIG_FILENAME, DEFAULT_EXTENSIONS_DIR, EXTENSION_CONFIG_FILENAME, DEFAULT_WEBS_DIR, WEB_CONFIG_FILENAME } from '../constants.js';
3
3
 
4
- async function load() {
5
- const path = Path.resolve(Path.cwd(), APP_CONFIG_FILENAME);
6
- if (!await Filesystem.exists(path)) {
7
- throw new Error(`app config not found at ${path}`);
8
- }
9
- const config = await Filesystem.readJsonFile(path);
10
- const app = {
11
- config,
12
- webs: [],
13
- extensions: [],
14
- root: Path.cwd(),
15
- };
16
- app.extensions = await loadExtensions(app);
17
- app.webs = await loadWebs(app);
18
- return app;
19
- }
20
- async function loadExtensions(app) {
21
- const pattern = Path.join(app.root, `${DEFAULT_EXTENSIONS_DIR}/*`, EXTENSION_CONFIG_FILENAME);
22
- const paths = await Filesystem.glob(pattern);
23
- const promises = paths.map(async (p) => {
24
- return {
25
- root: Path.dirname(p),
26
- config: await Filesystem.readJsonFile(p),
27
- };
28
- });
29
- return await Promise.all(promises);
30
- }
31
- async function loadWebs(app) {
32
- const pattern = Path.join(app.root, DEFAULT_WEBS_DIR, WEB_CONFIG_FILENAME);
33
- const paths = await Filesystem.glob(pattern);
34
- const promises = paths.map(async (p) => ({
35
- root: Path.dirname(p),
36
- config: await Filesystem.readJsonFile(p),
37
- }));
38
- return await Promise.all(promises);
4
+ async function load() {
5
+ const path = Path.resolve(Path.cwd(), APP_CONFIG_FILENAME);
6
+ if (!await Filesystem.exists(path)) {
7
+ throw new Error(`app config not found at ${path}`);
8
+ }
9
+ const config = await Filesystem.readJsonFile(path);
10
+ const app = {
11
+ config,
12
+ webs: [],
13
+ extensions: [],
14
+ root: Path.cwd(),
15
+ };
16
+ app.extensions = await loadExtensions(app);
17
+ app.webs = await loadWebs(app);
18
+ return app;
19
+ }
20
+ async function loadExtensions(app) {
21
+ const pattern = Path.join(app.root, `${DEFAULT_EXTENSIONS_DIR}/*`, EXTENSION_CONFIG_FILENAME);
22
+ const paths = await Filesystem.glob(pattern);
23
+ const promises = paths.map(async (p) => {
24
+ return {
25
+ root: Path.dirname(p),
26
+ config: await Filesystem.readJsonFile(p),
27
+ };
28
+ });
29
+ return await Promise.all(promises);
30
+ }
31
+ async function loadWebs(app) {
32
+ const pattern = Path.join(app.root, DEFAULT_WEBS_DIR, WEB_CONFIG_FILENAME);
33
+ const paths = await Filesystem.glob(pattern);
34
+ const promises = paths.map(async (p) => ({
35
+ root: Path.dirname(p),
36
+ config: await Filesystem.readJsonFile(p),
37
+ }));
38
+ return await Promise.all(promises);
39
39
  }
40
40
 
41
41
  export { load };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@youcan/app",
3
3
  "type": "module",
4
- "version": "2.1.4",
4
+ "version": "2.3.0",
5
5
  "description": "OCLIF plugin for building apps",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
7
  "license": "MIT",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@oclif/core": "^2.15.0",
19
19
  "dayjs": "^1.11.10",
20
- "@youcan/cli-kit": "2.1.4"
20
+ "@youcan/cli-kit": "2.3.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@oclif/plugin-legacy": "^1.3.0",
@@ -25,7 +25,12 @@
25
25
  "shx": "^0.3.4"
26
26
  },
27
27
  "oclif": {
28
- "commands": "./dist/cli/commands"
28
+ "commands": "./dist/cli/commands",
29
+ "topics": {
30
+ "app:env": {
31
+ "description": "Manage app environment variables"
32
+ }
33
+ }
29
34
  },
30
35
  "scripts": {
31
36
  "build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
@@ -1,3 +0,0 @@
1
- import { Cli } from '@youcan/cli-kit';
2
- export declare abstract class AppCommand extends Cli.Command {
3
- }
@@ -1,6 +0,0 @@
1
- import { Cli } from '@youcan/cli-kit';
2
-
3
- class AppCommand extends Cli.Command {
4
- }
5
-
6
- export { AppCommand };