@plasmicapp/cli 0.1.162
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/.eslintrc.js +61 -0
- package/.idea/cli.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +16 -0
- package/README.internal +46 -0
- package/README.md +17 -0
- package/build.sh +8 -0
- package/dist/__mocks__/api.d.ts +16 -0
- package/dist/__mocks__/api.js +297 -0
- package/dist/__tests__/code-utils-spec.d.ts +1 -0
- package/dist/__tests__/code-utils-spec.js +838 -0
- package/dist/__tests__/ftue-spec.d.ts +1 -0
- package/dist/__tests__/ftue-spec.js +39 -0
- package/dist/__tests__/project-api-token-spec.d.ts +1 -0
- package/dist/__tests__/project-api-token-spec.js +147 -0
- package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
- package/dist/__tests__/versioned-sync-spec.js +145 -0
- package/dist/actions/auth.d.ts +8 -0
- package/dist/actions/auth.js +47 -0
- package/dist/actions/fix-imports.d.ts +4 -0
- package/dist/actions/fix-imports.js +25 -0
- package/dist/actions/init.d.ts +62 -0
- package/dist/actions/init.js +460 -0
- package/dist/actions/project-token.d.ts +6 -0
- package/dist/actions/project-token.js +42 -0
- package/dist/actions/sync-components.d.ts +10 -0
- package/dist/actions/sync-components.js +242 -0
- package/dist/actions/sync-global-variants.d.ts +3 -0
- package/dist/actions/sync-global-variants.js +89 -0
- package/dist/actions/sync-icons.d.ts +7 -0
- package/dist/actions/sync-icons.js +92 -0
- package/dist/actions/sync-images.d.ts +6 -0
- package/dist/actions/sync-images.js +137 -0
- package/dist/actions/sync-styles.d.ts +3 -0
- package/dist/actions/sync-styles.js +58 -0
- package/dist/actions/sync.d.ts +25 -0
- package/dist/actions/sync.js +417 -0
- package/dist/actions/upload-bundle.d.ts +15 -0
- package/dist/actions/upload-bundle.js +28 -0
- package/dist/actions/watch.d.ts +14 -0
- package/dist/actions/watch.js +90 -0
- package/dist/api.d.ts +182 -0
- package/dist/api.js +202 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +247 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +23 -0
- package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
- package/dist/migrations/0.1.110-fileLocks.js +15 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
- package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
- package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
- package/dist/migrations/0.1.27-migrateInit.js +8 -0
- package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
- package/dist/migrations/0.1.28-tsToTsx.js +33 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
- package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
- package/dist/migrations/0.1.42-ensureVersion.js +12 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
- package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
- package/dist/migrations/0.1.64-imageFiles.js +17 -0
- package/dist/migrations/0.1.95-componentType.d.ts +2 -0
- package/dist/migrations/0.1.95-componentType.js +16 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +119 -0
- package/dist/plasmic.schema.json +463 -0
- package/dist/test-common/fixtures.d.ts +13 -0
- package/dist/test-common/fixtures.js +165 -0
- package/dist/tsconfig-transform.json +68 -0
- package/dist/utils/auth-utils.d.ts +31 -0
- package/dist/utils/auth-utils.js +236 -0
- package/dist/utils/checksum.d.ts +4 -0
- package/dist/utils/checksum.js +63 -0
- package/dist/utils/code-utils.d.ts +46 -0
- package/dist/utils/code-utils.js +457 -0
- package/dist/utils/config-utils.d.ts +271 -0
- package/dist/utils/config-utils.js +178 -0
- package/dist/utils/envdetect.d.ts +4 -0
- package/dist/utils/envdetect.js +42 -0
- package/dist/utils/error.d.ts +14 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/file-utils.d.ts +71 -0
- package/dist/utils/file-utils.js +433 -0
- package/dist/utils/get-context.d.ts +40 -0
- package/dist/utils/get-context.js +339 -0
- package/dist/utils/help.d.ts +2 -0
- package/dist/utils/help.js +56 -0
- package/dist/utils/lang-utils.d.ts +10 -0
- package/dist/utils/lang-utils.js +52 -0
- package/dist/utils/npm-utils.d.ts +28 -0
- package/dist/utils/npm-utils.js +215 -0
- package/dist/utils/prompts.d.ts +6 -0
- package/dist/utils/prompts.js +23 -0
- package/dist/utils/resolve-utils.d.ts +13 -0
- package/dist/utils/resolve-utils.js +198 -0
- package/dist/utils/semver.d.ts +34 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/test-utils.d.ts +22 -0
- package/dist/utils/test-utils.js +106 -0
- package/dist/utils/user-utils.d.ts +7 -0
- package/dist/utils/user-utils.js +48 -0
- package/jest.config.js +6 -0
- package/package.json +80 -0
- package/src/__mocks__/api.ts +394 -0
- package/src/__tests__/code-utils-spec.ts +881 -0
- package/src/__tests__/ftue-spec.ts +43 -0
- package/src/__tests__/project-api-token-spec.ts +208 -0
- package/src/__tests__/versioned-sync-spec.ts +176 -0
- package/src/actions/auth.ts +43 -0
- package/src/actions/fix-imports.ts +13 -0
- package/src/actions/init.ts +638 -0
- package/src/actions/project-token.ts +36 -0
- package/src/actions/sync-components.ts +405 -0
- package/src/actions/sync-global-variants.ts +129 -0
- package/src/actions/sync-icons.ts +135 -0
- package/src/actions/sync-images.ts +191 -0
- package/src/actions/sync-styles.ts +71 -0
- package/src/actions/sync.ts +747 -0
- package/src/actions/upload-bundle.ts +38 -0
- package/src/actions/watch.ts +95 -0
- package/src/api.ts +407 -0
- package/src/deps.ts +18 -0
- package/src/index.ts +300 -0
- package/src/lib.ts +10 -0
- package/src/migrations/0.1.110-fileLocks.ts +16 -0
- package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
- package/src/migrations/0.1.27-migrateInit.ts +4 -0
- package/src/migrations/0.1.28-tsToTsx.ts +37 -0
- package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
- package/src/migrations/0.1.42-ensureVersion.ts +10 -0
- package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
- package/src/migrations/0.1.64-imageFiles.ts +15 -0
- package/src/migrations/0.1.95-componentType.ts +14 -0
- package/src/migrations/migrations.ts +147 -0
- package/src/test-common/fixtures.ts +178 -0
- package/src/utils/auth-utils.ts +276 -0
- package/src/utils/checksum.ts +106 -0
- package/src/utils/code-utils.ts +656 -0
- package/src/utils/config-utils.ts +551 -0
- package/src/utils/envdetect.ts +39 -0
- package/src/utils/error.ts +36 -0
- package/src/utils/file-utils.ts +526 -0
- package/src/utils/get-context.ts +451 -0
- package/src/utils/help.ts +75 -0
- package/src/utils/lang-utils.ts +52 -0
- package/src/utils/npm-utils.ts +223 -0
- package/src/utils/prompts.ts +22 -0
- package/src/utils/resolve-utils.ts +245 -0
- package/src/utils/semver.ts +67 -0
- package/src/utils/test-utils.ts +116 -0
- package/src/utils/user-utils.ts +37 -0
- package/testData/fixImports_plasmic.json +66 -0
- package/tsconfig-transform.json +68 -0
- package/tsconfig.json +67 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/// <reference types="socket.io-client" />
|
|
2
|
+
import { ProjectSyncMetadataModel } from "@plasmicapp/code-merger";
|
|
3
|
+
import { AuthConfig, CodeConfig, ImagesConfig, StyleConfig } from "./utils/config-utils";
|
|
4
|
+
import { Metadata } from "./utils/get-context";
|
|
5
|
+
export declare class AppServerError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentBundle {
|
|
9
|
+
renderModule: string;
|
|
10
|
+
skeletonModule: string;
|
|
11
|
+
cssRules: string;
|
|
12
|
+
renderModuleFileName: string;
|
|
13
|
+
skeletonModuleFileName: string;
|
|
14
|
+
cssFileName: string;
|
|
15
|
+
componentName: string;
|
|
16
|
+
id: string;
|
|
17
|
+
scheme: string;
|
|
18
|
+
nameInIdToUuid: Array<[string, string]>;
|
|
19
|
+
isPage: boolean;
|
|
20
|
+
plumeType?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GlobalVariantBundle {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
contextModule: string;
|
|
26
|
+
contextFileName: string;
|
|
27
|
+
}
|
|
28
|
+
export interface JsBundleTheme {
|
|
29
|
+
themeFileName: string;
|
|
30
|
+
themeModule: string;
|
|
31
|
+
bundleName: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ProjectMetaBundle {
|
|
34
|
+
projectId: string;
|
|
35
|
+
projectName: string;
|
|
36
|
+
cssFileName: string;
|
|
37
|
+
cssRules: string;
|
|
38
|
+
jsBundleThemes?: JsBundleTheme[];
|
|
39
|
+
}
|
|
40
|
+
export interface IconBundle {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
module: string;
|
|
44
|
+
fileName: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ImageBundle {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
blob: string;
|
|
50
|
+
fileName: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ProjectVersionMeta {
|
|
53
|
+
projectId: string;
|
|
54
|
+
projectApiToken: string;
|
|
55
|
+
version: string;
|
|
56
|
+
projectName: string;
|
|
57
|
+
componentIds: string[];
|
|
58
|
+
dependencies: {
|
|
59
|
+
[projectId: string]: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface VersionResolution {
|
|
63
|
+
projects: ProjectVersionMeta[];
|
|
64
|
+
dependencies: ProjectVersionMeta[];
|
|
65
|
+
conflicts: ProjectVersionMeta[];
|
|
66
|
+
}
|
|
67
|
+
export interface RequiredPackages {
|
|
68
|
+
"@plasmicapp/loader": string;
|
|
69
|
+
"@plasmicapp/cli": string;
|
|
70
|
+
"@plasmicapp/react-web": string;
|
|
71
|
+
"@plasmicapp/react-web-runtime": string;
|
|
72
|
+
}
|
|
73
|
+
export interface ProjectBundle {
|
|
74
|
+
components: ComponentBundle[];
|
|
75
|
+
codeComponentMetas: CodeComponentMeta[];
|
|
76
|
+
projectConfig: ProjectMetaBundle;
|
|
77
|
+
globalVariants: GlobalVariantBundle[];
|
|
78
|
+
usedTokens: StyleTokensMap;
|
|
79
|
+
iconAssets: IconBundle[];
|
|
80
|
+
imageAssets: ImageBundle[];
|
|
81
|
+
checksums: ChecksumBundle;
|
|
82
|
+
}
|
|
83
|
+
export declare type ProjectMeta = Omit<ProjectBundle, "projectConfig">;
|
|
84
|
+
export interface StyleConfigResponse {
|
|
85
|
+
defaultStyleCssFileName: string;
|
|
86
|
+
defaultStyleCssRules: string;
|
|
87
|
+
}
|
|
88
|
+
export interface StyleTokensMap {
|
|
89
|
+
props: {
|
|
90
|
+
name: string;
|
|
91
|
+
type: string;
|
|
92
|
+
value: string | number;
|
|
93
|
+
meta: {
|
|
94
|
+
projectId: string;
|
|
95
|
+
id: string;
|
|
96
|
+
};
|
|
97
|
+
}[];
|
|
98
|
+
global: {
|
|
99
|
+
meta: {
|
|
100
|
+
source: "plasmic.app";
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export interface ChecksumBundle {
|
|
105
|
+
renderModuleChecksums: Array<[string, string]>;
|
|
106
|
+
cssRulesChecksums: Array<[string, string]>;
|
|
107
|
+
imageChecksums: Array<[string, string]>;
|
|
108
|
+
iconChecksums: Array<[string, string]>;
|
|
109
|
+
globalVariantChecksums: Array<[string, string]>;
|
|
110
|
+
projectCssChecksum: string;
|
|
111
|
+
}
|
|
112
|
+
export interface CodeComponentMeta {
|
|
113
|
+
id: string;
|
|
114
|
+
name: string;
|
|
115
|
+
importPath: string;
|
|
116
|
+
}
|
|
117
|
+
export interface ProjectIconsResponse {
|
|
118
|
+
version: string;
|
|
119
|
+
icons: IconBundle[];
|
|
120
|
+
}
|
|
121
|
+
export interface ProjectIdAndToken {
|
|
122
|
+
projectId: string;
|
|
123
|
+
projectApiToken?: string;
|
|
124
|
+
}
|
|
125
|
+
export declare class PlasmicApi {
|
|
126
|
+
private auth;
|
|
127
|
+
constructor(auth: AuthConfig);
|
|
128
|
+
genStyleConfig(styleOpts?: StyleConfig): Promise<StyleConfigResponse>;
|
|
129
|
+
/**
|
|
130
|
+
* Sync resolution - Given a fuzzy idea of what the user wants,
|
|
131
|
+
* (i.e. a versionRange and component names),
|
|
132
|
+
* ask the server for the exact references for a later call to `projectComponents`
|
|
133
|
+
* - For components specified in the parameters - the server will return the latest version that satisfies the versionRange
|
|
134
|
+
* - Any conflicting versions will be returned in `conflicts`, and should cause the client's sync to abort
|
|
135
|
+
* @param projects
|
|
136
|
+
* @param recursive
|
|
137
|
+
*/
|
|
138
|
+
resolveSync(projects: {
|
|
139
|
+
projectId: string;
|
|
140
|
+
versionRange?: string;
|
|
141
|
+
componentIdOrNames: readonly string[] | undefined;
|
|
142
|
+
projectApiToken?: string;
|
|
143
|
+
}[], recursive?: boolean): Promise<VersionResolution>;
|
|
144
|
+
getCurrentUser(): Promise<import("axios").AxiosResponse<any>>;
|
|
145
|
+
requiredPackages(): Promise<RequiredPackages>;
|
|
146
|
+
/**
|
|
147
|
+
* Code-gen endpoint.
|
|
148
|
+
* This will fetch components at an exact specified version.
|
|
149
|
+
* If you don't know what version should be used, call `resolveSync` first.
|
|
150
|
+
* @param projectId
|
|
151
|
+
* @param cliVersion
|
|
152
|
+
* @param reactWebVersion
|
|
153
|
+
* @param newCompScheme
|
|
154
|
+
* @param existingCompScheme
|
|
155
|
+
* @param componentIdOrNames
|
|
156
|
+
* @param version
|
|
157
|
+
*/
|
|
158
|
+
projectComponents(projectId: string, opts: {
|
|
159
|
+
platform: string;
|
|
160
|
+
newCompScheme: "blackbox" | "direct";
|
|
161
|
+
existingCompScheme: Array<[string, "blackbox" | "direct"]>;
|
|
162
|
+
componentIdOrNames: readonly string[] | undefined;
|
|
163
|
+
version: string;
|
|
164
|
+
imageOpts: ImagesConfig;
|
|
165
|
+
stylesOpts: StyleConfig;
|
|
166
|
+
codeOpts: CodeConfig;
|
|
167
|
+
checksums: ChecksumBundle;
|
|
168
|
+
metadata?: Metadata;
|
|
169
|
+
}): Promise<ProjectBundle>;
|
|
170
|
+
uploadBundle(projectId: string, bundleName: string, bundleJs: string, css: string[], metaJson: string, genModulePath: string | undefined, genCssPaths: string[], pkgVersion: string | undefined, extraPropMetaJson: string | undefined, themeProviderWrapper: string | undefined, themeModule: string | undefined): Promise<StyleTokensMap>;
|
|
171
|
+
projectStyleTokens(projectId: string, versionRange?: string): Promise<StyleTokensMap>;
|
|
172
|
+
projectIcons(projectId: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
|
|
173
|
+
projectSyncMetadata(projectId: string, revision: number, rethrowAppError: boolean): Promise<ProjectSyncMetadataModel>;
|
|
174
|
+
connectSocket(): SocketIOClient.Socket;
|
|
175
|
+
private post;
|
|
176
|
+
private makeErrorMessage;
|
|
177
|
+
private makeHeaders;
|
|
178
|
+
private projectIdsAndTokens?;
|
|
179
|
+
attachProjectIdsAndTokens(idsAndTokens: ProjectIdAndToken[]): void;
|
|
180
|
+
private get studioHost();
|
|
181
|
+
private get codegenHost();
|
|
182
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PlasmicApi = exports.AppServerError = void 0;
|
|
16
|
+
const code_merger_1 = require("@plasmicapp/code-merger");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const socket_io_client_1 = __importDefault(require("socket.io-client"));
|
|
19
|
+
const config_utils_1 = require("./utils/config-utils");
|
|
20
|
+
const error_1 = require("./utils/error");
|
|
21
|
+
class AppServerError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AppServerError = AppServerError;
|
|
27
|
+
class PlasmicApi {
|
|
28
|
+
constructor(auth) {
|
|
29
|
+
this.auth = auth;
|
|
30
|
+
}
|
|
31
|
+
genStyleConfig(styleOpts) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/code/style-config`, styleOpts);
|
|
34
|
+
return result.data;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sync resolution - Given a fuzzy idea of what the user wants,
|
|
39
|
+
* (i.e. a versionRange and component names),
|
|
40
|
+
* ask the server for the exact references for a later call to `projectComponents`
|
|
41
|
+
* - For components specified in the parameters - the server will return the latest version that satisfies the versionRange
|
|
42
|
+
* - Any conflicting versions will be returned in `conflicts`, and should cause the client's sync to abort
|
|
43
|
+
* @param projects
|
|
44
|
+
* @param recursive
|
|
45
|
+
*/
|
|
46
|
+
resolveSync(projects, recursive) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const resp = yield this.post(`${this.codegenHost}/api/v1/code/resolve-sync`, {
|
|
49
|
+
projects,
|
|
50
|
+
recursive,
|
|
51
|
+
});
|
|
52
|
+
const versionResolution = resp.data;
|
|
53
|
+
return Object.assign({}, versionResolution);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getCurrentUser() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return yield axios_1.default.get(`${this.studioHost}/api/v1/auth/self`, {
|
|
59
|
+
headers: this.makeHeaders(),
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
requiredPackages() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const resp = yield this.post(`${this.codegenHost}/api/v1/code/required-packages`);
|
|
66
|
+
return Object.assign({}, resp.data);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Code-gen endpoint.
|
|
71
|
+
* This will fetch components at an exact specified version.
|
|
72
|
+
* If you don't know what version should be used, call `resolveSync` first.
|
|
73
|
+
* @param projectId
|
|
74
|
+
* @param cliVersion
|
|
75
|
+
* @param reactWebVersion
|
|
76
|
+
* @param newCompScheme
|
|
77
|
+
* @param existingCompScheme
|
|
78
|
+
* @param componentIdOrNames
|
|
79
|
+
* @param version
|
|
80
|
+
*/
|
|
81
|
+
projectComponents(projectId, opts) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/components`, Object.assign({}, opts));
|
|
84
|
+
return result.data;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
uploadBundle(projectId, bundleName, bundleJs, css, metaJson, genModulePath, genCssPaths, pkgVersion, extraPropMetaJson, themeProviderWrapper, themeModule) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/jsbundle/upload`, {
|
|
90
|
+
projectId,
|
|
91
|
+
bundleName,
|
|
92
|
+
bundleJs,
|
|
93
|
+
css,
|
|
94
|
+
metaJson,
|
|
95
|
+
genModulePath,
|
|
96
|
+
genCssPaths,
|
|
97
|
+
pkgVersion,
|
|
98
|
+
extraPropMetaJson,
|
|
99
|
+
themeProviderWrapper,
|
|
100
|
+
themeModule,
|
|
101
|
+
});
|
|
102
|
+
return result.data;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
projectStyleTokens(projectId, versionRange) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/tokens`, { versionRange });
|
|
108
|
+
return result.data;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
projectIcons(projectId, versionRange, iconIds) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/icons`, { versionRange, iconIds });
|
|
114
|
+
return result.data;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
projectSyncMetadata(projectId, revision, rethrowAppError) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata`, { revision }, rethrowAppError);
|
|
120
|
+
return code_merger_1.ProjectSyncMetadataModel.fromJson(result.data);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
connectSocket() {
|
|
124
|
+
const socket = socket_io_client_1.default.connect(this.studioHost, {
|
|
125
|
+
path: `/api/v1/socket`,
|
|
126
|
+
transportOptions: {
|
|
127
|
+
polling: {
|
|
128
|
+
extraHeaders: this.makeHeaders(),
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return socket;
|
|
133
|
+
}
|
|
134
|
+
// If rethrowAppError is true, we will throw an exception with the error
|
|
135
|
+
// message
|
|
136
|
+
post(url, data, rethrowAppError) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
try {
|
|
139
|
+
return yield axios_1.default.post(url, Object.assign({ projectIdsAndTokens: this.projectIdsAndTokens }, data), {
|
|
140
|
+
headers: this.makeHeaders(),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
const error = e;
|
|
145
|
+
const errorMsg = this.makeErrorMessage(error);
|
|
146
|
+
if (rethrowAppError) {
|
|
147
|
+
throw new AppServerError(errorMsg);
|
|
148
|
+
}
|
|
149
|
+
if (!errorMsg) {
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
throw new error_1.HandledError(errorMsg);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
makeErrorMessage(error) {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
const response = error.response;
|
|
159
|
+
if (!response) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
if (response.status === 403) {
|
|
163
|
+
return `Incorrect Plasmic credentials; please check your .plasmic.auth file or your project API tokens.`;
|
|
164
|
+
}
|
|
165
|
+
if ((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) {
|
|
166
|
+
return response.data.error.message;
|
|
167
|
+
}
|
|
168
|
+
else if (response.data) {
|
|
169
|
+
return `Error: request failed with status code ${response.status}. The response is
|
|
170
|
+
${response.data}`;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
makeHeaders() {
|
|
177
|
+
const headers = {
|
|
178
|
+
"x-plasmic-api-user": this.auth.user,
|
|
179
|
+
"x-plasmic-api-token": this.auth.token,
|
|
180
|
+
};
|
|
181
|
+
if (this.auth.basicAuthUser && this.auth.basicAuthPassword) {
|
|
182
|
+
const authString = Buffer.from(`${this.auth.basicAuthUser}:${this.auth.basicAuthPassword}`).toString("base64");
|
|
183
|
+
headers["Authorization"] = `Basic ${authString}`;
|
|
184
|
+
}
|
|
185
|
+
return headers;
|
|
186
|
+
}
|
|
187
|
+
attachProjectIdsAndTokens(idsAndTokens) {
|
|
188
|
+
this.projectIdsAndTokens = idsAndTokens;
|
|
189
|
+
}
|
|
190
|
+
get studioHost() {
|
|
191
|
+
return this.auth.host;
|
|
192
|
+
}
|
|
193
|
+
get codegenHost() {
|
|
194
|
+
if (!this.auth.host || this.auth.host === config_utils_1.DEFAULT_HOST) {
|
|
195
|
+
return "https://codegen.plasmic.app";
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return this.auth.host;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.PlasmicApi = PlasmicApi;
|
package/dist/deps.d.ts
ADDED
package/dist/deps.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
|
8
|
+
exports.logger = winston_1.default.createLogger({
|
|
9
|
+
level: "info",
|
|
10
|
+
format: winston_1.default.format.json(),
|
|
11
|
+
defaultMeta: {},
|
|
12
|
+
transports: [
|
|
13
|
+
new winston_1.default.transports.Console({
|
|
14
|
+
format: winston_1.default.format.printf((info) => `${info.message}`
|
|
15
|
+
//info => `${moment().format("HH:mm:ss")}:${info.level}\t${info.message}`
|
|
16
|
+
),
|
|
17
|
+
stderrLevels: ["error"],
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const semver_1 = __importDefault(require("semver"));
|
|
27
|
+
const update_notifier_1 = __importDefault(require("update-notifier"));
|
|
28
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
29
|
+
const auth = __importStar(require("./actions/auth"));
|
|
30
|
+
const fix_imports_1 = require("./actions/fix-imports");
|
|
31
|
+
const init_1 = require("./actions/init");
|
|
32
|
+
const projectToken = __importStar(require("./actions/project-token"));
|
|
33
|
+
const sync_1 = require("./actions/sync");
|
|
34
|
+
const upload_bundle_1 = require("./actions/upload-bundle");
|
|
35
|
+
const watch_1 = require("./actions/watch");
|
|
36
|
+
const config_utils_1 = require("./utils/config-utils");
|
|
37
|
+
const error_1 = require("./utils/error");
|
|
38
|
+
if (process.env.DEBUG_CHDIR) {
|
|
39
|
+
process.chdir(process.env.DEBUG_CHDIR);
|
|
40
|
+
}
|
|
41
|
+
// Check once an hour
|
|
42
|
+
const pkg = require("../package.json");
|
|
43
|
+
const notifier = update_notifier_1.default({ pkg, updateCheckInterval: 1000 * 60 * 60 });
|
|
44
|
+
// Workaround for this bug
|
|
45
|
+
// https://github.com/yeoman/update-notifier/issues/181
|
|
46
|
+
if (!!notifier.update &&
|
|
47
|
+
semver_1.default.gt(notifier.update.latest, notifier.update.current)) {
|
|
48
|
+
notifier.notify();
|
|
49
|
+
}
|
|
50
|
+
yargs_1.default
|
|
51
|
+
.usage("Usage: $0 <command> [options]")
|
|
52
|
+
.option("auth", {
|
|
53
|
+
describe: "Plasmic auth file to use; by default, uses ~/.plasmic.auth, or the first .plasmic.auth file found in current and parent directories",
|
|
54
|
+
})
|
|
55
|
+
.option("config", {
|
|
56
|
+
describe: "Plasmic config file to use; by default, uses the first plasmic.json file found in the current or parent directories",
|
|
57
|
+
})
|
|
58
|
+
.option("yes", {
|
|
59
|
+
type: "boolean",
|
|
60
|
+
describe: "Automatic yes to prompts.",
|
|
61
|
+
default: false,
|
|
62
|
+
})
|
|
63
|
+
.command("init", "Initializes Plasmic for a project.", (yags) => {
|
|
64
|
+
yags
|
|
65
|
+
.option("enable-skip-auth", {
|
|
66
|
+
describe: "Enable skipping auth, just initialize a plasmic.json",
|
|
67
|
+
type: "boolean",
|
|
68
|
+
default: false,
|
|
69
|
+
})
|
|
70
|
+
.option("host", init_1.getYargsOption("host", "https://studio.plasmic.app"))
|
|
71
|
+
.option("platform", init_1.getYargsOption("platform"))
|
|
72
|
+
.option("code-lang", init_1.getYargsOption("codeLang"))
|
|
73
|
+
.option("code-scheme", init_1.getYargsOption("codeScheme"))
|
|
74
|
+
.option("react-runtime", {
|
|
75
|
+
describe: "React runtime to use; either classic or automatic",
|
|
76
|
+
choices: ["classic", "automatic"],
|
|
77
|
+
default: "classic",
|
|
78
|
+
})
|
|
79
|
+
.option("src-dir", init_1.getYargsOption("srcDir"))
|
|
80
|
+
.option("plasmic-dir", init_1.getYargsOption("plasmicDir"))
|
|
81
|
+
.option("pages-dir", init_1.getYargsOption("pagesDir"))
|
|
82
|
+
.option("style-scheme", init_1.getYargsOption("styleScheme"))
|
|
83
|
+
.option("images-scheme", init_1.getYargsOption("imagesScheme"))
|
|
84
|
+
.option("images-public-dir", init_1.getYargsOption("imagesPublicDir"))
|
|
85
|
+
.option("images-public-url-prefix", init_1.getYargsOption("imagesPublicUrlPrefix"));
|
|
86
|
+
}, (argv) => error_1.handleError(init_1.initPlasmic(argv)))
|
|
87
|
+
.command("auth", "Authenticates you to plasmic.", (yags) => {
|
|
88
|
+
yags
|
|
89
|
+
.option("host", {
|
|
90
|
+
describe: "Plasmic host to use",
|
|
91
|
+
type: "string",
|
|
92
|
+
default: "https://studio.plasmic.app",
|
|
93
|
+
})
|
|
94
|
+
.option("check", {
|
|
95
|
+
alias: "c",
|
|
96
|
+
describe: "Just verifies if the current credentials are valid.",
|
|
97
|
+
type: "boolean",
|
|
98
|
+
})
|
|
99
|
+
.option("email", {
|
|
100
|
+
describe: "Print the email of the currently authenticated user and exit.",
|
|
101
|
+
type: "boolean",
|
|
102
|
+
});
|
|
103
|
+
}, (argv) => {
|
|
104
|
+
error_1.handleError(auth.auth(argv));
|
|
105
|
+
})
|
|
106
|
+
.command("sync", "Syncs designs from Plasmic to local files.", (yags) => configureSyncArgs(yags), (argv) => {
|
|
107
|
+
error_1.handleError(sync_1.sync(argv, {
|
|
108
|
+
source: "cli",
|
|
109
|
+
scheme: "codegen",
|
|
110
|
+
command: "sync",
|
|
111
|
+
}));
|
|
112
|
+
})
|
|
113
|
+
.command("watch", "Watches for updates to projects, and syncs them automatically to local files.", (yags) => configureSyncArgs(yags, false), (argv) => {
|
|
114
|
+
error_1.handleError(watch_1.watchProjects(argv, {
|
|
115
|
+
source: "cli",
|
|
116
|
+
scheme: "codegen",
|
|
117
|
+
command: "watch",
|
|
118
|
+
}));
|
|
119
|
+
})
|
|
120
|
+
.command("fix-imports", "Fixes import paths after you've moved around Plasmic blackbox files", (yags) => 0, (argv) => error_1.handleError(fix_imports_1.fixImports(argv)))
|
|
121
|
+
.command("upload-bundle", false, (yargs) => yargs
|
|
122
|
+
.option("project", {
|
|
123
|
+
alias: "p",
|
|
124
|
+
describe: "ID of Plasmic project to upload the bundle to.",
|
|
125
|
+
type: "string",
|
|
126
|
+
})
|
|
127
|
+
.option("bundleName", {
|
|
128
|
+
describe: "Name of the bundle",
|
|
129
|
+
type: "string",
|
|
130
|
+
})
|
|
131
|
+
.option("bundleJsFile", {
|
|
132
|
+
describe: "Path of the bundled Javascript file in AMD format",
|
|
133
|
+
type: "string",
|
|
134
|
+
})
|
|
135
|
+
.option("cssFiles", {
|
|
136
|
+
describe: "Path of the bundled css files to load",
|
|
137
|
+
type: "array",
|
|
138
|
+
default: [],
|
|
139
|
+
})
|
|
140
|
+
.option("metaJsonFile", {
|
|
141
|
+
describe: "Path of the meta data file (in JSON format) describing the component",
|
|
142
|
+
type: "string",
|
|
143
|
+
})
|
|
144
|
+
.option("extraPropMetaJsonFile", {
|
|
145
|
+
describe: "Path of the extra meta data file (in JSON format) describing the component's additional controlled properties and initial properties",
|
|
146
|
+
type: "string",
|
|
147
|
+
})
|
|
148
|
+
.option("pkgVersion", {
|
|
149
|
+
describe: "version of the package to include in the generated package.json",
|
|
150
|
+
type: "string",
|
|
151
|
+
default: "latest",
|
|
152
|
+
})
|
|
153
|
+
.option("genModulePath", {
|
|
154
|
+
describe: "the path of include when generating import statement and generate package.json for. Default to bundleName.",
|
|
155
|
+
type: "string",
|
|
156
|
+
})
|
|
157
|
+
.option("themeProviderWrapper", {
|
|
158
|
+
describe: "the wrapper that inject theme to the bundle.",
|
|
159
|
+
type: "string",
|
|
160
|
+
})
|
|
161
|
+
.option("themeModuleFile", {
|
|
162
|
+
describe: "the typescript file that contains and exports the implementation of themeProviderWrapper. Used for code generation. It must be specified together with themeProviderWrapper.",
|
|
163
|
+
type: "string",
|
|
164
|
+
})
|
|
165
|
+
.option("genCssPaths", {
|
|
166
|
+
describe: "the list of css paths to import in generate code whenever a component in this bundle is used",
|
|
167
|
+
type: "array",
|
|
168
|
+
default: [],
|
|
169
|
+
}), (argv) => error_1.handleError(upload_bundle_1.uploadJsBundle(argv)))
|
|
170
|
+
.command("project-token <projectId>", "Get projectApiToken for a given project", (yargs) => yargs
|
|
171
|
+
.positional("projectId", {
|
|
172
|
+
describe: "projectId",
|
|
173
|
+
type: "string",
|
|
174
|
+
})
|
|
175
|
+
.option("host", {
|
|
176
|
+
describe: "Plasmic host to use",
|
|
177
|
+
type: "string",
|
|
178
|
+
default: "https://studio.plasmic.app",
|
|
179
|
+
}), (argv) => error_1.handleError(projectToken.projectToken(argv)))
|
|
180
|
+
.demandCommand()
|
|
181
|
+
.strict()
|
|
182
|
+
.help("h")
|
|
183
|
+
.alias("h", "help").argv;
|
|
184
|
+
function configureSyncArgs(yags, includeQuietOption = true) {
|
|
185
|
+
let args = yags
|
|
186
|
+
.option("projects", {
|
|
187
|
+
alias: "p",
|
|
188
|
+
describe: "One or more projects to sync, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
|
|
189
|
+
type: "array",
|
|
190
|
+
default: [],
|
|
191
|
+
})
|
|
192
|
+
.option("force", {
|
|
193
|
+
type: "boolean",
|
|
194
|
+
describe: "Force sync to bypass specified version ranges.",
|
|
195
|
+
default: false,
|
|
196
|
+
})
|
|
197
|
+
.option("loader-config", {
|
|
198
|
+
type: "string",
|
|
199
|
+
describe: "Path to loader config file, and causes CLI to run in PlasmicLoader mode.",
|
|
200
|
+
hidden: true,
|
|
201
|
+
default: config_utils_1.LOADER_CONFIG_FILE_NAME,
|
|
202
|
+
})
|
|
203
|
+
.option("non-recursive", {
|
|
204
|
+
type: "boolean",
|
|
205
|
+
describe: "Do not recursively sync dependencies, only sync the specified projects",
|
|
206
|
+
default: false,
|
|
207
|
+
})
|
|
208
|
+
.option("force-overwrite", {
|
|
209
|
+
type: "boolean",
|
|
210
|
+
describe: "Overwrite the skeleton file with newly generated version. Useful when switching between codegen schemes.",
|
|
211
|
+
default: false,
|
|
212
|
+
})
|
|
213
|
+
.option("append-jsx-on-missing-base", {
|
|
214
|
+
type: "boolean",
|
|
215
|
+
describe: "When the base metadata is missing to perform the three-way merge for direct edit component, append the jsx of the new version so that user can perform manual merge.",
|
|
216
|
+
default: false,
|
|
217
|
+
})
|
|
218
|
+
.option("new-component-scheme", {
|
|
219
|
+
type: "string",
|
|
220
|
+
choices: ["blackbox", "direct"],
|
|
221
|
+
describe: "Sync the new components using this code scheme rather than the default code scheme.",
|
|
222
|
+
})
|
|
223
|
+
.option("ignore-post-sync", {
|
|
224
|
+
type: "boolean",
|
|
225
|
+
describe: "Ignore post-sync commands in plasmic.json",
|
|
226
|
+
default: false,
|
|
227
|
+
})
|
|
228
|
+
.option("metadata", {
|
|
229
|
+
type: "string",
|
|
230
|
+
describe: "Pass metadata through to the server. Use querystring format (e.g. command=sync&source=cli&cli_version=1.0.0",
|
|
231
|
+
default: "source=cli",
|
|
232
|
+
hidden: true,
|
|
233
|
+
})
|
|
234
|
+
.option("all-files", {
|
|
235
|
+
type: "boolean",
|
|
236
|
+
describe: "Sync all files, including those that haven't changed since last sync",
|
|
237
|
+
default: "",
|
|
238
|
+
});
|
|
239
|
+
if (includeQuietOption) {
|
|
240
|
+
args = args.option("quiet", {
|
|
241
|
+
type: "boolean",
|
|
242
|
+
describe: "Do not inform each asset to be synced",
|
|
243
|
+
default: false,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return args;
|
|
247
|
+
}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { auth, AuthArgs } from "./actions/auth";
|
|
2
|
+
export { fixImports, FixImportsArgs } from "./actions/fix-imports";
|
|
3
|
+
export { InitArgs, initPlasmic } from "./actions/init";
|
|
4
|
+
export { getProjectApiToken } from "./actions/project-token";
|
|
5
|
+
export { sync, SyncArgs } from "./actions/sync";
|
|
6
|
+
export { UploadBundleArgs, uploadJsBundle } from "./actions/upload-bundle";
|
|
7
|
+
export { WatchArgs, watchProjects } from "./actions/watch";
|
|
8
|
+
export { logger } from "./deps";
|
|
9
|
+
export { HandledError, handleError } from "./utils/error";
|
|
10
|
+
export { Metadata, setMetadataEnv } from "./utils/get-context";
|