@plasmicapp/cli 0.1.334 → 0.1.336
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 +8 -2
- package/dist/index.js +35140 -36833
- package/dist/lib.js +35159 -36852
- package/dist/plasmic.schema.json +15 -0
- package/dist/utils/code-utils.d.ts +1 -0
- package/dist/utils/config-utils.d.ts +4 -0
- package/dist/utils/rsc-config.d.ts +3 -0
- package/package.json +2 -2
- package/src/actions/sync-components.ts +4 -1
- package/src/actions/sync.ts +3 -3
- package/src/api.ts +15 -2
- package/src/utils/code-utils.ts +95 -2
- package/src/utils/config-utils.ts +5 -0
- package/src/utils/file-utils.ts +24 -13
- package/src/utils/rsc-config.ts +51 -0
package/dist/plasmic.schema.json
CHANGED
|
@@ -112,6 +112,21 @@
|
|
|
112
112
|
"description": "The file path for the blackbox render module, relative to srcDir.",
|
|
113
113
|
"type": "string"
|
|
114
114
|
},
|
|
115
|
+
"rsc": {
|
|
116
|
+
"properties": {
|
|
117
|
+
"clientModulePath": {
|
|
118
|
+
"type": "string"
|
|
119
|
+
},
|
|
120
|
+
"serverModulePath": {
|
|
121
|
+
"type": "string"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"required": [
|
|
125
|
+
"clientModulePath",
|
|
126
|
+
"serverModulePath"
|
|
127
|
+
],
|
|
128
|
+
"type": "object"
|
|
129
|
+
},
|
|
115
130
|
"scheme": {
|
|
116
131
|
"description": "Code generation scheme used for this component",
|
|
117
132
|
"enum": [
|
|
@@ -36,3 +36,4 @@ export declare function fixAllImportStatements(context: PlasmicContext, baseDir:
|
|
|
36
36
|
export declare const tsxToJsx: (code: string) => string;
|
|
37
37
|
export declare function maybeConvertTsxToJsx(fileName: string, content: string, baseDir: string): string[];
|
|
38
38
|
export declare const formatScript: (code: string, baseDir: string) => string;
|
|
39
|
+
export declare function fixRscModulesImports(context: PlasmicContext, baseDir: string, fixImportContext: FixImportContext, compConfig: ComponentConfig): Promise<void>;
|
|
@@ -206,6 +206,10 @@ export interface ComponentConfig {
|
|
|
206
206
|
path?: string;
|
|
207
207
|
/** Plume type if component is a Plume component */
|
|
208
208
|
plumeType?: string;
|
|
209
|
+
rsc?: {
|
|
210
|
+
serverModulePath: string;
|
|
211
|
+
clientModulePath: string;
|
|
212
|
+
};
|
|
209
213
|
}
|
|
210
214
|
export interface IconConfig {
|
|
211
215
|
/** ID of icon */
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ComponentBundle } from "../api";
|
|
2
|
+
import { ComponentConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
3
|
+
export declare function syncRscFiles(context: PlasmicContext, project: ProjectConfig, bundle: ComponentBundle, compConfig: ComponentConfig): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.336",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"wrap-ansi": "^7.0.0",
|
|
84
84
|
"yargs": "^15.4.1"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "e390ac2d296d887f8ed34f29fd85f21a315c35da"
|
|
87
87
|
}
|
|
@@ -5,10 +5,10 @@ import { logger } from "../deps";
|
|
|
5
5
|
import { ComponentUpdateSummary, formatAsLocal } from "../utils/code-utils";
|
|
6
6
|
import {
|
|
7
7
|
CONFIG_FILE_NAME,
|
|
8
|
-
isPageAwarePlatform,
|
|
9
8
|
PlasmicContext,
|
|
10
9
|
ProjectConfig,
|
|
11
10
|
ProjectLock,
|
|
11
|
+
isPageAwarePlatform,
|
|
12
12
|
} from "../utils/config-utils";
|
|
13
13
|
import {
|
|
14
14
|
defaultPagePath,
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
writeFileContent,
|
|
22
22
|
} from "../utils/file-utils";
|
|
23
23
|
import { assert, ensure } from "../utils/lang-utils";
|
|
24
|
+
import { syncRscFiles } from "../utils/rsc-config";
|
|
24
25
|
import { confirmWithUser } from "../utils/user-utils";
|
|
25
26
|
|
|
26
27
|
export async function syncProjectComponents(
|
|
@@ -304,5 +305,7 @@ export async function syncProjectComponents(
|
|
|
304
305
|
);
|
|
305
306
|
}
|
|
306
307
|
summary.set(id, { skeletonModuleModified });
|
|
308
|
+
|
|
309
|
+
await syncRscFiles(context, project, bundle, compConfig);
|
|
307
310
|
}
|
|
308
311
|
}
|
package/src/actions/sync.ts
CHANGED
|
@@ -22,11 +22,11 @@ import {
|
|
|
22
22
|
} from "../utils/code-utils";
|
|
23
23
|
import {
|
|
24
24
|
CONFIG_FILE_NAME,
|
|
25
|
-
createProjectConfig,
|
|
26
25
|
CustomFunctionConfig,
|
|
26
|
+
PlasmicContext,
|
|
27
|
+
createProjectConfig,
|
|
27
28
|
getOrAddProjectConfig,
|
|
28
29
|
getOrAddProjectLock,
|
|
29
|
-
PlasmicContext,
|
|
30
30
|
updateConfig,
|
|
31
31
|
} from "../utils/config-utils";
|
|
32
32
|
import { HandledError } from "../utils/error";
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
withBufferedFs,
|
|
39
39
|
writeFileContent,
|
|
40
40
|
} from "../utils/file-utils";
|
|
41
|
-
import { generateMetadata, getContext
|
|
41
|
+
import { Metadata, generateMetadata, getContext } from "../utils/get-context";
|
|
42
42
|
import { printFirstSyncInfo } from "../utils/help";
|
|
43
43
|
import { ensure, tuple } from "../utils/lang-utils";
|
|
44
44
|
import {
|
package/src/api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosError } from "axios";
|
|
2
|
-
import socketio
|
|
2
|
+
import socketio from "socket.io-client";
|
|
3
3
|
import {
|
|
4
4
|
AuthConfig,
|
|
5
5
|
CodeConfig,
|
|
@@ -33,6 +33,19 @@ export interface ComponentBundle {
|
|
|
33
33
|
isPage: boolean;
|
|
34
34
|
path?: string;
|
|
35
35
|
plumeType?: string;
|
|
36
|
+
rscMetadata?: {
|
|
37
|
+
// When we generate code for RSC, we generate two additional files per page, those files are used to increment the user experience,
|
|
38
|
+
// it's added one managed server file which is responsible for performing the server actions and one skeleton file which allows the
|
|
39
|
+
// user to add client side logic to the page (the `renderModule` will contain a server component for entry point allowing the user to
|
|
40
|
+
// perform additional server operations).
|
|
41
|
+
pageWrappers: Record<
|
|
42
|
+
"client" | "server",
|
|
43
|
+
{
|
|
44
|
+
module: string;
|
|
45
|
+
fileName: string;
|
|
46
|
+
}
|
|
47
|
+
>;
|
|
48
|
+
};
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
export interface GlobalVariantBundle {
|
|
@@ -440,7 +453,7 @@ export class PlasmicApi {
|
|
|
440
453
|
return result.data as ProjectIconsResponse;
|
|
441
454
|
}
|
|
442
455
|
|
|
443
|
-
connectSocket():
|
|
456
|
+
connectSocket(): ReturnType<typeof socketio> {
|
|
444
457
|
const socket = socketio(this.studioHost, {
|
|
445
458
|
path: `/api/v1/socket`,
|
|
446
459
|
transportOptions: {
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -18,9 +18,9 @@ import { logger } from "../deps";
|
|
|
18
18
|
import { GLOBAL_SETTINGS } from "../globals";
|
|
19
19
|
import { HandledError } from "../utils/error";
|
|
20
20
|
import {
|
|
21
|
+
CONFIG_FILE_NAME,
|
|
21
22
|
CodeComponentConfig,
|
|
22
23
|
ComponentConfig,
|
|
23
|
-
CONFIG_FILE_NAME,
|
|
24
24
|
CustomFunctionConfig,
|
|
25
25
|
GlobalVariantGroupConfig,
|
|
26
26
|
IconConfig,
|
|
@@ -173,6 +173,8 @@ type PlasmicImportType =
|
|
|
173
173
|
| "globalContext"
|
|
174
174
|
| "customFunction"
|
|
175
175
|
| "splitsProvider"
|
|
176
|
+
| "rscClient"
|
|
177
|
+
| "rscServer"
|
|
176
178
|
| undefined;
|
|
177
179
|
|
|
178
180
|
const validJsIdentifierChars = [
|
|
@@ -201,7 +203,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
|
201
203
|
"plasmic-import:\\s+([",
|
|
202
204
|
...validJsIdentifierChars,
|
|
203
205
|
"\\.",
|
|
204
|
-
"]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider))?",
|
|
206
|
+
"]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider|rscClient|rscServer))?",
|
|
205
207
|
].join("")
|
|
206
208
|
)
|
|
207
209
|
);
|
|
@@ -439,6 +441,46 @@ export function replaceImports(
|
|
|
439
441
|
true
|
|
440
442
|
);
|
|
441
443
|
stmt.source.value = realPath;
|
|
444
|
+
} else if (type === "rscClient") {
|
|
445
|
+
const compConfig = fixImportContext.components[uuid];
|
|
446
|
+
if (!compConfig) {
|
|
447
|
+
throwMissingReference(context, "component", uuid, fromPath);
|
|
448
|
+
}
|
|
449
|
+
const clientModulePath = compConfig.rsc?.clientModulePath;
|
|
450
|
+
if (!clientModulePath) {
|
|
451
|
+
throw new HandledError(
|
|
452
|
+
`Encountered Plasmic component "${uuid}" that is missing a rscClientModulePath.`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
stmt.source.value = makeImportPath(
|
|
457
|
+
context,
|
|
458
|
+
fromPath,
|
|
459
|
+
clientModulePath,
|
|
460
|
+
true
|
|
461
|
+
);
|
|
462
|
+
} else if (type === "rscServer") {
|
|
463
|
+
const compConfig = fixImportContext.components[uuid];
|
|
464
|
+
if (!compConfig) {
|
|
465
|
+
throwMissingReference(context, "component", uuid, fromPath);
|
|
466
|
+
}
|
|
467
|
+
const serverModulePath = compConfig.rsc?.serverModulePath;
|
|
468
|
+
if (!serverModulePath) {
|
|
469
|
+
throw new HandledError(
|
|
470
|
+
`Encountered Plasmic component "${uuid}" that is missing a rscServerModulePath.`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
logger.info(
|
|
475
|
+
`Fixing "rscServer" with "${serverModulePath}" and from "${fromPath}"`
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
stmt.source.value = makeImportPath(
|
|
479
|
+
context,
|
|
480
|
+
fromPath,
|
|
481
|
+
serverModulePath,
|
|
482
|
+
true
|
|
483
|
+
);
|
|
442
484
|
}
|
|
443
485
|
});
|
|
444
486
|
|
|
@@ -569,6 +611,17 @@ export async function fixAllImportStatements(
|
|
|
569
611
|
let lastError: any = undefined;
|
|
570
612
|
for (const project of config.projects) {
|
|
571
613
|
for (const compConfig of project.components) {
|
|
614
|
+
try {
|
|
615
|
+
await fixRscModulesImports(
|
|
616
|
+
context,
|
|
617
|
+
baseDir,
|
|
618
|
+
fixImportContext,
|
|
619
|
+
compConfig
|
|
620
|
+
);
|
|
621
|
+
} catch (err) {
|
|
622
|
+
lastError = err;
|
|
623
|
+
}
|
|
624
|
+
|
|
572
625
|
const compSummary = summary?.get(compConfig.id);
|
|
573
626
|
if (summary && !compSummary) {
|
|
574
627
|
continue;
|
|
@@ -876,3 +929,43 @@ async function fixSplitsProviderImportStatements(
|
|
|
876
929
|
}
|
|
877
930
|
}
|
|
878
931
|
}
|
|
932
|
+
|
|
933
|
+
export async function fixRscModulesImports(
|
|
934
|
+
context: PlasmicContext,
|
|
935
|
+
baseDir: string,
|
|
936
|
+
fixImportContext: FixImportContext,
|
|
937
|
+
compConfig: ComponentConfig
|
|
938
|
+
) {
|
|
939
|
+
const errors: any[] = [];
|
|
940
|
+
|
|
941
|
+
for (const modulePath of [
|
|
942
|
+
compConfig.rsc?.clientModulePath,
|
|
943
|
+
compConfig.rsc?.serverModulePath,
|
|
944
|
+
]) {
|
|
945
|
+
if (!modulePath) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
logger.info(`Fixing rsc import statements... ${modulePath}`);
|
|
950
|
+
|
|
951
|
+
try {
|
|
952
|
+
await fixFileImportStatements(
|
|
953
|
+
context,
|
|
954
|
+
modulePath,
|
|
955
|
+
fixImportContext,
|
|
956
|
+
false,
|
|
957
|
+
baseDir
|
|
958
|
+
);
|
|
959
|
+
} catch (err) {
|
|
960
|
+
logger.error(
|
|
961
|
+
`Error encountered while fixing imports for rsc modules ${compConfig.name}: ${err}`
|
|
962
|
+
);
|
|
963
|
+
|
|
964
|
+
errors.push(err);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
if (errors.length) {
|
|
969
|
+
throw errors[0];
|
|
970
|
+
}
|
|
971
|
+
}
|
|
@@ -288,6 +288,11 @@ export interface ComponentConfig {
|
|
|
288
288
|
|
|
289
289
|
/** Plume type if component is a Plume component */
|
|
290
290
|
plumeType?: string;
|
|
291
|
+
|
|
292
|
+
rsc?: {
|
|
293
|
+
serverModulePath: string;
|
|
294
|
+
clientModulePath: string;
|
|
295
|
+
};
|
|
291
296
|
}
|
|
292
297
|
|
|
293
298
|
export interface IconConfig {
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -264,20 +264,31 @@ export function findFile(
|
|
|
264
264
|
traverseParents?: boolean;
|
|
265
265
|
}
|
|
266
266
|
): string | undefined {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
267
|
+
try {
|
|
268
|
+
const files = fs.readdirSync(dir);
|
|
269
|
+
const found = files.find((f) => pred(f));
|
|
270
|
+
if (found) {
|
|
271
|
+
return path.join(dir, found);
|
|
272
|
+
}
|
|
273
|
+
if (!opts.traverseParents) {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
const parent = path.dirname(dir);
|
|
277
|
+
if (parent === dir) {
|
|
278
|
+
// We've hit the root dir already
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
return findFile(path.dirname(dir), pred, opts);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
if (err instanceof Error && "code" in err && err.code === "EACCES") {
|
|
284
|
+
// If the user is lacking file system permissions,
|
|
285
|
+
// show the error and assume the file is missing.
|
|
286
|
+
logger.warn(err);
|
|
287
|
+
return undefined;
|
|
288
|
+
} else {
|
|
289
|
+
throw err;
|
|
290
|
+
}
|
|
279
291
|
}
|
|
280
|
-
return findFile(path.dirname(dir), pred, opts);
|
|
281
292
|
}
|
|
282
293
|
|
|
283
294
|
type BundleKeyPair = {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentBundle } from "../api";
|
|
2
|
+
import { ComponentConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
3
|
+
import { defaultResourcePath, writeFileContent } from "./file-utils";
|
|
4
|
+
|
|
5
|
+
export async function syncRscFiles(
|
|
6
|
+
context: PlasmicContext,
|
|
7
|
+
project: ProjectConfig,
|
|
8
|
+
bundle: ComponentBundle,
|
|
9
|
+
compConfig: ComponentConfig
|
|
10
|
+
) {
|
|
11
|
+
const rscMetadata = bundle.rscMetadata;
|
|
12
|
+
if (rscMetadata) {
|
|
13
|
+
if (!compConfig.rsc) {
|
|
14
|
+
compConfig.rsc = {
|
|
15
|
+
serverModulePath: "",
|
|
16
|
+
clientModulePath: "",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const serverModuleFilePath = defaultResourcePath(
|
|
21
|
+
context,
|
|
22
|
+
project,
|
|
23
|
+
rscMetadata.pageWrappers.server.fileName
|
|
24
|
+
);
|
|
25
|
+
compConfig.rsc.serverModulePath = serverModuleFilePath;
|
|
26
|
+
|
|
27
|
+
await writeFileContent(
|
|
28
|
+
context,
|
|
29
|
+
serverModuleFilePath,
|
|
30
|
+
rscMetadata.pageWrappers.server.module,
|
|
31
|
+
{
|
|
32
|
+
force: true,
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const clientModuleFilePath = compConfig.importSpec.modulePath.replace(
|
|
37
|
+
/\.tsx$/,
|
|
38
|
+
"-client.tsx"
|
|
39
|
+
);
|
|
40
|
+
compConfig.rsc.clientModulePath = clientModuleFilePath;
|
|
41
|
+
|
|
42
|
+
await writeFileContent(
|
|
43
|
+
context,
|
|
44
|
+
clientModuleFilePath,
|
|
45
|
+
rscMetadata.pageWrappers.client.module,
|
|
46
|
+
{
|
|
47
|
+
force: false,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|