@plasmicapp/cli 0.1.311 → 0.1.314
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/dist/api.d.ts +2 -1
- package/dist/index.js +967 -482
- package/dist/lib.js +967 -482
- package/dist/plasmic.schema.json +35 -0
- package/dist/utils/code-utils.d.ts +3 -11
- package/dist/utils/config-utils.d.ts +8 -0
- package/package.json +2 -2
- package/src/__mocks__/api.ts +1 -0
- package/src/actions/export.ts +10 -1
- package/src/actions/sync.ts +23 -5
- package/src/api.ts +2 -0
- package/src/utils/code-utils.ts +52 -4
- package/src/utils/config-utils.ts +10 -1
package/dist/plasmic.schema.json
CHANGED
|
@@ -142,6 +142,35 @@
|
|
|
142
142
|
],
|
|
143
143
|
"type": "object"
|
|
144
144
|
},
|
|
145
|
+
"CustomFunctionConfig": {
|
|
146
|
+
"properties": {
|
|
147
|
+
"defaultExport": {
|
|
148
|
+
"type": "boolean"
|
|
149
|
+
},
|
|
150
|
+
"id": {
|
|
151
|
+
"type": "string"
|
|
152
|
+
},
|
|
153
|
+
"importPath": {
|
|
154
|
+
"type": "string"
|
|
155
|
+
},
|
|
156
|
+
"name": {
|
|
157
|
+
"type": "string"
|
|
158
|
+
},
|
|
159
|
+
"namespace": {
|
|
160
|
+
"type": [
|
|
161
|
+
"null",
|
|
162
|
+
"string"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"required": [
|
|
167
|
+
"defaultExport",
|
|
168
|
+
"id",
|
|
169
|
+
"importPath",
|
|
170
|
+
"name"
|
|
171
|
+
],
|
|
172
|
+
"type": "object"
|
|
173
|
+
},
|
|
145
174
|
"GlobalVariantGroupConfig": {
|
|
146
175
|
"properties": {
|
|
147
176
|
"contextFilePath": {
|
|
@@ -325,6 +354,12 @@
|
|
|
325
354
|
"description": "File location for the project-wide css styles. Relative to srcDir",
|
|
326
355
|
"type": "string"
|
|
327
356
|
},
|
|
357
|
+
"customFunctions": {
|
|
358
|
+
"items": {
|
|
359
|
+
"$ref": "#/definitions/CustomFunctionConfig"
|
|
360
|
+
},
|
|
361
|
+
"type": "array"
|
|
362
|
+
},
|
|
328
363
|
"globalContextsFilePath": {
|
|
329
364
|
"description": "File location for the project-wide global contexts. Relative to srcDir",
|
|
330
365
|
"type": "string"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ImportDeclaration } from "@babel/types";
|
|
2
|
-
import L from "lodash";
|
|
3
2
|
import { Options } from "prettier";
|
|
4
|
-
import { CodeComponentConfig, ComponentConfig, GlobalVariantGroupConfig, IconConfig, ImageConfig, PlasmicConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
3
|
+
import { CodeComponentConfig, ComponentConfig, CustomFunctionConfig, GlobalVariantGroupConfig, IconConfig, ImageConfig, PlasmicConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
5
4
|
export declare const formatAsLocal: (content: string, filePath: string, baseDir: string, defaultOpts?: Options) => string;
|
|
6
5
|
export declare function ensureImportSpecifierWithAlias(decl: ImportDeclaration, imported: string, alias: string): void;
|
|
7
6
|
export declare function ensureImportDefaultSpecifier(decl: ImportDeclaration, defaultExport: string): void;
|
|
@@ -22,20 +21,13 @@ export interface FixImportContext {
|
|
|
22
21
|
config: PlasmicConfig;
|
|
23
22
|
components: Record<string, ComponentConfig>;
|
|
24
23
|
codeComponentMetas: Record<string, CodeComponentConfig>;
|
|
24
|
+
customFunctionMetas: Record<string, CustomFunctionConfig>;
|
|
25
25
|
globalVariants: Record<string, GlobalVariantGroupConfig>;
|
|
26
26
|
icons: Record<string, IconConfig>;
|
|
27
27
|
images: Record<string, ImageConfig>;
|
|
28
28
|
projects: Record<string, ProjectConfig>;
|
|
29
29
|
}
|
|
30
|
-
export declare const mkFixImportContext: (config: PlasmicConfig) =>
|
|
31
|
-
config: PlasmicConfig;
|
|
32
|
-
components: L.Dictionary<ComponentConfig>;
|
|
33
|
-
codeComponentMetas: L.Dictionary<CodeComponentConfig>;
|
|
34
|
-
globalVariants: L.Dictionary<GlobalVariantGroupConfig>;
|
|
35
|
-
icons: L.Dictionary<IconConfig>;
|
|
36
|
-
images: L.Dictionary<ImageConfig>;
|
|
37
|
-
projects: L.Dictionary<ProjectConfig>;
|
|
38
|
-
};
|
|
30
|
+
export declare const mkFixImportContext: (config: PlasmicConfig) => FixImportContext;
|
|
39
31
|
/**
|
|
40
32
|
* Assuming that all the files referenced in PlasmicConfig are correct, fixes import statements using PlasmicConfig
|
|
41
33
|
* file locations as the source of truth.
|
|
@@ -108,6 +108,13 @@ export interface CodeComponentConfig {
|
|
|
108
108
|
importPath: string;
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
+
export interface CustomFunctionConfig {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
namespace?: string | null;
|
|
115
|
+
importPath: string;
|
|
116
|
+
defaultExport: boolean;
|
|
117
|
+
}
|
|
111
118
|
export interface ProjectConfig {
|
|
112
119
|
/** Project ID */
|
|
113
120
|
projectId: string;
|
|
@@ -130,6 +137,7 @@ export interface ProjectConfig {
|
|
|
130
137
|
globalContextsFilePath: string;
|
|
131
138
|
jsBundleThemes?: JsBundleThemeConfig[];
|
|
132
139
|
codeComponents?: CodeComponentConfig[];
|
|
140
|
+
customFunctions?: CustomFunctionConfig[];
|
|
133
141
|
/** Metadata for each synced component in this project. */
|
|
134
142
|
components: ComponentConfig[];
|
|
135
143
|
/** Metadata for each synced icon in this project */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.314",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"wrap-ansi": "^7.0.0",
|
|
79
79
|
"yargs": "^15.4.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "6e966ef24adb9af472b56a5051faf2b8e6e04f12"
|
|
82
82
|
}
|
package/src/__mocks__/api.ts
CHANGED
package/src/actions/export.ts
CHANGED
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
} from "../utils/code-utils";
|
|
11
11
|
import {
|
|
12
12
|
CodeConfig,
|
|
13
|
+
findConfigFile,
|
|
13
14
|
I18NConfig,
|
|
14
15
|
ImagesConfig,
|
|
15
16
|
PlasmicConfig,
|
|
16
17
|
StyleConfig,
|
|
17
|
-
findConfigFile,
|
|
18
18
|
} from "../utils/config-utils";
|
|
19
19
|
import { getContext, getCurrentOrDefaultAuth } from "../utils/get-context";
|
|
20
20
|
import { tuple } from "../utils/lang-utils";
|
|
@@ -200,6 +200,15 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
|
|
|
200
200
|
componentImportPath: comp.importPath,
|
|
201
201
|
helper: comp.helper,
|
|
202
202
|
})),
|
|
203
|
+
customFunctionMetas: (bundle.customFunctionMetas ?? []).map(
|
|
204
|
+
(meta) => ({
|
|
205
|
+
id: meta.id,
|
|
206
|
+
name: meta.name,
|
|
207
|
+
importPath: meta.importPath,
|
|
208
|
+
defaultExport: meta.defaultExport,
|
|
209
|
+
namespace: meta.namespace ?? null,
|
|
210
|
+
})
|
|
211
|
+
),
|
|
203
212
|
icons: bundle.iconAssets.map((icon) => ({
|
|
204
213
|
id: icon.id,
|
|
205
214
|
name: icon.name,
|
package/src/actions/sync.ts
CHANGED
|
@@ -22,25 +22,23 @@ import {
|
|
|
22
22
|
} from "../utils/code-utils";
|
|
23
23
|
import {
|
|
24
24
|
CONFIG_FILE_NAME,
|
|
25
|
-
PlasmicContext,
|
|
26
25
|
createProjectConfig,
|
|
26
|
+
CustomFunctionConfig,
|
|
27
27
|
getOrAddProjectConfig,
|
|
28
28
|
getOrAddProjectLock,
|
|
29
|
+
PlasmicContext,
|
|
29
30
|
updateConfig,
|
|
30
31
|
} from "../utils/config-utils";
|
|
31
32
|
import { HandledError } from "../utils/error";
|
|
32
33
|
import {
|
|
33
34
|
assertAllPathsInRootDir,
|
|
34
35
|
defaultResourcePath,
|
|
35
|
-
existsBuffered,
|
|
36
|
-
readFileText,
|
|
37
36
|
renameFile,
|
|
38
37
|
stripExtension,
|
|
39
38
|
withBufferedFs,
|
|
40
39
|
writeFileContent,
|
|
41
|
-
writeFileText,
|
|
42
40
|
} from "../utils/file-utils";
|
|
43
|
-
import {
|
|
41
|
+
import { generateMetadata, getContext, Metadata } from "../utils/get-context";
|
|
44
42
|
import { printFirstSyncInfo } from "../utils/help";
|
|
45
43
|
import { ensure, tuple } from "../utils/lang-utils";
|
|
46
44
|
import {
|
|
@@ -604,6 +602,11 @@ async function syncProject(
|
|
|
604
602
|
indirect
|
|
605
603
|
);
|
|
606
604
|
syncCodeComponentsMeta(context, projectId, projectBundle.codeComponentMetas);
|
|
605
|
+
await syncCustomFunctionsMeta(
|
|
606
|
+
context,
|
|
607
|
+
projectId,
|
|
608
|
+
projectBundle.customFunctionMetas
|
|
609
|
+
);
|
|
607
610
|
await upsertStyleTokens(
|
|
608
611
|
context,
|
|
609
612
|
projectBundle.usedTokens,
|
|
@@ -807,3 +810,18 @@ function syncCodeComponentsMeta(
|
|
|
807
810
|
: {}),
|
|
808
811
|
}));
|
|
809
812
|
}
|
|
813
|
+
|
|
814
|
+
function syncCustomFunctionsMeta(
|
|
815
|
+
context: PlasmicContext,
|
|
816
|
+
projectId: string,
|
|
817
|
+
customFunctionBundles: CustomFunctionConfig[]
|
|
818
|
+
) {
|
|
819
|
+
const projectConfig = getOrAddProjectConfig(context, projectId);
|
|
820
|
+
projectConfig.customFunctions = customFunctionBundles.map((meta) => ({
|
|
821
|
+
defaultExport: meta.defaultExport,
|
|
822
|
+
id: meta.id,
|
|
823
|
+
importPath: meta.importPath,
|
|
824
|
+
name: meta.name,
|
|
825
|
+
namespace: meta.namespace ?? null,
|
|
826
|
+
}));
|
|
827
|
+
}
|
package/src/api.ts
CHANGED
|
@@ -3,6 +3,7 @@ import socketio, { Socket } from "socket.io-client";
|
|
|
3
3
|
import {
|
|
4
4
|
AuthConfig,
|
|
5
5
|
CodeConfig,
|
|
6
|
+
CustomFunctionConfig,
|
|
6
7
|
DEFAULT_HOST,
|
|
7
8
|
I18NConfig,
|
|
8
9
|
ImagesConfig,
|
|
@@ -112,6 +113,7 @@ export interface ProjectMetaInfo {
|
|
|
112
113
|
export interface ProjectBundle {
|
|
113
114
|
components: ComponentBundle[];
|
|
114
115
|
codeComponentMetas: CodeComponentMeta[];
|
|
116
|
+
customFunctionMetas: CustomFunctionConfig[];
|
|
115
117
|
projectConfig: ProjectMetaBundle;
|
|
116
118
|
globalVariants: GlobalVariantBundle[];
|
|
117
119
|
usedTokens: StyleTokensMap;
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import traverse, { Node } from "@babel/traverse";
|
|
|
5
5
|
import { ImportDeclaration } from "@babel/types";
|
|
6
6
|
import L from "lodash";
|
|
7
7
|
import * as Prettier from "prettier";
|
|
8
|
-
import { Options
|
|
8
|
+
import { Options } from "prettier";
|
|
9
9
|
import * as ts from "typescript";
|
|
10
10
|
import path from "upath";
|
|
11
11
|
import { getGlobalContextsResourcePath } from "../actions/sync-global-contexts";
|
|
@@ -14,11 +14,13 @@ import {
|
|
|
14
14
|
fixComponentImagesReferences,
|
|
15
15
|
} from "../actions/sync-images";
|
|
16
16
|
import { logger } from "../deps";
|
|
17
|
+
import { GLOBAL_SETTINGS } from "../globals";
|
|
17
18
|
import { HandledError } from "../utils/error";
|
|
18
19
|
import {
|
|
19
20
|
CodeComponentConfig,
|
|
20
21
|
ComponentConfig,
|
|
21
22
|
CONFIG_FILE_NAME,
|
|
23
|
+
CustomFunctionConfig,
|
|
22
24
|
GlobalVariantGroupConfig,
|
|
23
25
|
IconConfig,
|
|
24
26
|
ImageConfig,
|
|
@@ -34,7 +36,6 @@ import {
|
|
|
34
36
|
writeFileContent,
|
|
35
37
|
} from "./file-utils";
|
|
36
38
|
import { assert, flatMap } from "./lang-utils";
|
|
37
|
-
import { GLOBAL_SETTINGS } from "../globals";
|
|
38
39
|
|
|
39
40
|
export const formatAsLocal = (
|
|
40
41
|
content: string,
|
|
@@ -169,15 +170,38 @@ type PlasmicImportType =
|
|
|
169
170
|
| "codeComponent"
|
|
170
171
|
| "codeComponentHelper"
|
|
171
172
|
| "globalContext"
|
|
173
|
+
| "customFunction"
|
|
172
174
|
| undefined;
|
|
173
175
|
|
|
176
|
+
const validJsIdentifierChars = [
|
|
177
|
+
"\\u0621-\\u064A", // arabic
|
|
178
|
+
"\\u3400-\\u4DB5", // chinese
|
|
179
|
+
"\\u4E00-\\u9FCC", // chinese
|
|
180
|
+
"\\u0400-\\u04FF", // cyrillic
|
|
181
|
+
"\\u0370-\\u03ff", // greek
|
|
182
|
+
"\\u1f00-\\u1fff", // greek
|
|
183
|
+
"\\u0900-\\u097F", // hindi
|
|
184
|
+
"\\u3041-\\u3094", // japanese
|
|
185
|
+
"\\u30A1-\\u30FB", // japanese
|
|
186
|
+
"\\u0E00-\\u0E7F", // thai
|
|
187
|
+
"\\w",
|
|
188
|
+
"-_",
|
|
189
|
+
];
|
|
190
|
+
|
|
174
191
|
function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
175
192
|
const c = node.trailingComments?.[0];
|
|
176
193
|
if (!c) {
|
|
177
194
|
return undefined;
|
|
178
195
|
}
|
|
179
196
|
const m = c.value.match(
|
|
180
|
-
|
|
197
|
+
new RegExp(
|
|
198
|
+
[
|
|
199
|
+
"plasmic-import:\\s+([",
|
|
200
|
+
...validJsIdentifierChars,
|
|
201
|
+
"\\.",
|
|
202
|
+
"]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction))?",
|
|
203
|
+
].join("")
|
|
204
|
+
)
|
|
181
205
|
);
|
|
182
206
|
if (m) {
|
|
183
207
|
return { id: m[1], type: m[2] as PlasmicImportType } as PlasmicImportSpec;
|
|
@@ -384,6 +408,23 @@ export function replaceImports(
|
|
|
384
408
|
true
|
|
385
409
|
);
|
|
386
410
|
stmt.source.value = realPath;
|
|
411
|
+
} else if (type === "customFunction") {
|
|
412
|
+
const meta = fixImportContext.customFunctionMetas[uuid];
|
|
413
|
+
if (!meta?.importPath) {
|
|
414
|
+
throw new HandledError(
|
|
415
|
+
`Encountered custom function "${uuid}" that was not registered with an importPath, so we don't know where to import this function from. Please see https://docs.plasmic.app/learn/code-components-ref/`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
if (meta.importPath[0] === ".") {
|
|
419
|
+
// Relative path from the project root
|
|
420
|
+
const toPath = path.join(context.rootDir, meta.importPath);
|
|
421
|
+
assert(path.isAbsolute(toPath));
|
|
422
|
+
const realPath = makeImportPath(context, fromPath, toPath, true, true);
|
|
423
|
+
stmt.source.value = realPath;
|
|
424
|
+
} else {
|
|
425
|
+
// npm package
|
|
426
|
+
stmt.source.value = meta.importPath;
|
|
427
|
+
}
|
|
387
428
|
}
|
|
388
429
|
});
|
|
389
430
|
|
|
@@ -454,20 +495,26 @@ export interface FixImportContext {
|
|
|
454
495
|
config: PlasmicConfig;
|
|
455
496
|
components: Record<string, ComponentConfig>;
|
|
456
497
|
codeComponentMetas: Record<string, CodeComponentConfig>;
|
|
498
|
+
customFunctionMetas: Record<string, CustomFunctionConfig>;
|
|
457
499
|
globalVariants: Record<string, GlobalVariantGroupConfig>;
|
|
458
500
|
icons: Record<string, IconConfig>;
|
|
459
501
|
images: Record<string, ImageConfig>;
|
|
460
502
|
projects: Record<string, ProjectConfig>;
|
|
461
503
|
}
|
|
462
504
|
|
|
463
|
-
export const mkFixImportContext = (config: PlasmicConfig) => {
|
|
505
|
+
export const mkFixImportContext = (config: PlasmicConfig): FixImportContext => {
|
|
464
506
|
const allComponents = flatMap(config.projects, (p) => p.components);
|
|
465
507
|
const components = L.keyBy(allComponents, (c) => c.id);
|
|
466
508
|
const allCodeComponents = flatMap(
|
|
467
509
|
config.projects,
|
|
468
510
|
(p) => p.codeComponents || []
|
|
469
511
|
);
|
|
512
|
+
const allCustomFunctions = flatMap(
|
|
513
|
+
config.projects,
|
|
514
|
+
(p) => p.customFunctions ?? []
|
|
515
|
+
);
|
|
470
516
|
const codeComponentMetas = L.keyBy(allCodeComponents, (c) => c.id);
|
|
517
|
+
const customFunctionMetas = L.keyBy(allCustomFunctions, (fn) => fn.id);
|
|
471
518
|
const globalVariants = L.keyBy(
|
|
472
519
|
config.globalVariants.variantGroups,
|
|
473
520
|
(c) => c.id
|
|
@@ -485,6 +532,7 @@ export const mkFixImportContext = (config: PlasmicConfig) => {
|
|
|
485
532
|
config,
|
|
486
533
|
components,
|
|
487
534
|
codeComponentMetas,
|
|
535
|
+
customFunctionMetas,
|
|
488
536
|
globalVariants,
|
|
489
537
|
icons,
|
|
490
538
|
images,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import L from "lodash";
|
|
2
2
|
import { DeepPartial } from "utility-types";
|
|
3
|
-
import { PlasmicApi
|
|
3
|
+
import { PlasmicApi } from "../api";
|
|
4
4
|
import { logger } from "../deps";
|
|
5
5
|
import { HandledError } from "../utils/error";
|
|
6
6
|
import { formatAsLocal } from "./code-utils";
|
|
@@ -152,6 +152,14 @@ export interface CodeComponentConfig {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
export interface CustomFunctionConfig {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
namespace?: string | null;
|
|
159
|
+
importPath: string;
|
|
160
|
+
defaultExport: boolean;
|
|
161
|
+
}
|
|
162
|
+
|
|
155
163
|
export interface ProjectConfig {
|
|
156
164
|
/** Project ID */
|
|
157
165
|
projectId: string;
|
|
@@ -177,6 +185,7 @@ export interface ProjectConfig {
|
|
|
177
185
|
// to the users nor appear to be missing in the documentation.
|
|
178
186
|
jsBundleThemes?: JsBundleThemeConfig[];
|
|
179
187
|
codeComponents?: CodeComponentConfig[];
|
|
188
|
+
customFunctions?: CustomFunctionConfig[];
|
|
180
189
|
|
|
181
190
|
/** Metadata for each synced component in this project. */
|
|
182
191
|
components: ComponentConfig[];
|