@plasmicapp/cli 0.1.171 → 0.1.175
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/actions/info.js +3 -2
- package/dist/actions/sync.js +17 -6
- package/dist/api.d.ts +9 -0
- package/dist/api.js +6 -0
- package/dist/index.js +9 -0
- package/dist/plasmic.schema.json +9 -1
- package/dist/test-common/fixtures.js +1 -0
- package/dist/utils/code-utils.js +9 -1
- package/dist/utils/config-utils.d.ts +3 -0
- package/dist/utils/config-utils.js +1 -0
- package/dist/utils/get-context.js +14 -3
- package/package.json +1 -1
- package/src/actions/info.ts +20 -0
- package/src/actions/sync.ts +21 -6
- package/src/api.ts +16 -0
- package/src/index.ts +15 -0
- package/src/test-common/fixtures.ts +1 -0
- package/src/utils/code-utils.ts +14 -1
- package/src/utils/config-utils.ts +6 -0
- package/src/utils/get-context.ts +15 -3
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +0 -2
- package/dist/migrations/0.1.143-ensureImportModuleType.js +0 -12
package/dist/actions/info.js
CHANGED
|
@@ -13,14 +13,15 @@ exports.printProjectInfo = void 0;
|
|
|
13
13
|
const deps_1 = require("../deps");
|
|
14
14
|
const get_context_1 = require("../utils/get-context");
|
|
15
15
|
function printProjectInfo(opts) {
|
|
16
|
+
var _a, _b;
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
18
|
let context = yield get_context_1.getContext(opts);
|
|
18
19
|
const results = yield Promise.all(opts.projects.map((p) => __awaiter(this, void 0, void 0, function* () { return yield context.api.projectMeta(p); })));
|
|
19
20
|
for (const meta of results) {
|
|
20
21
|
deps_1.logger.info(`Id: ${meta.id}`);
|
|
21
22
|
deps_1.logger.info(`Name: ${meta.name}`);
|
|
22
|
-
deps_1.logger.info(`Host URL: ${meta.hostUrl}`);
|
|
23
|
-
deps_1.logger.info(`Last published version: ${meta.lastPublishedVersion}`);
|
|
23
|
+
deps_1.logger.info(`Host URL: ${(_a = meta.hostUrl) !== null && _a !== void 0 ? _a : null}`);
|
|
24
|
+
deps_1.logger.info(`Last published version: ${(_b = meta.lastPublishedVersion) !== null && _b !== void 0 ? _b : null}`);
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
}
|
package/dist/actions/sync.js
CHANGED
|
@@ -50,11 +50,11 @@ const resolve_utils_1 = require("../utils/resolve-utils");
|
|
|
50
50
|
const semver = __importStar(require("../utils/semver"));
|
|
51
51
|
const user_utils_1 = require("../utils/user-utils");
|
|
52
52
|
const sync_components_1 = require("./sync-components");
|
|
53
|
+
const sync_global_contexts_1 = require("./sync-global-contexts");
|
|
53
54
|
const sync_global_variants_1 = require("./sync-global-variants");
|
|
54
55
|
const sync_icons_1 = require("./sync-icons");
|
|
55
56
|
const sync_images_1 = require("./sync-images");
|
|
56
57
|
const sync_styles_1 = require("./sync-styles");
|
|
57
|
-
const sync_global_contexts_1 = require("./sync-global-contexts");
|
|
58
58
|
function ensureRequiredPackages(context, baseDir, yes) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
60
|
const requireds = yield context.api.requiredPackages();
|
|
@@ -302,23 +302,33 @@ function checkExternalPkgs(context, baseDir, opts, pkgs) {
|
|
|
302
302
|
}
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
|
-
function maybeRenamePathExt(context, path, ext) {
|
|
305
|
+
function maybeRenamePathExt(context, path, ext, opts) {
|
|
306
306
|
if (!path) {
|
|
307
307
|
return path;
|
|
308
308
|
}
|
|
309
309
|
const correctPath = `${file_utils_1.stripExtension(path, true)}${ext}`;
|
|
310
310
|
if (path !== correctPath) {
|
|
311
|
-
|
|
311
|
+
try {
|
|
312
|
+
file_utils_1.renameFile(context, path, correctPath);
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.continueOnFailure)) {
|
|
316
|
+
throw e;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
deps_1.logger.warn(e);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
312
322
|
}
|
|
313
323
|
return correctPath;
|
|
314
324
|
}
|
|
315
325
|
function fixFileExtension(context) {
|
|
316
326
|
const cssExt = context.config.style.scheme === "css-modules" ? ".module.css" : ".css";
|
|
317
|
-
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(context, context.config.style.defaultStyleCssFilePath, cssExt);
|
|
327
|
+
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(context, context.config.style.defaultStyleCssFilePath, cssExt, { continueOnFailure: true });
|
|
318
328
|
context.config.projects.forEach((project) => {
|
|
319
|
-
project.cssFilePath = maybeRenamePathExt(context, project.cssFilePath, cssExt);
|
|
329
|
+
project.cssFilePath = maybeRenamePathExt(context, project.cssFilePath, cssExt, { continueOnFailure: true });
|
|
320
330
|
project.components.forEach((component) => {
|
|
321
|
-
component.cssFilePath = maybeRenamePathExt(context, component.cssFilePath, cssExt);
|
|
331
|
+
component.cssFilePath = maybeRenamePathExt(context, component.cssFilePath, cssExt, { continueOnFailure: true });
|
|
322
332
|
});
|
|
323
333
|
});
|
|
324
334
|
}
|
|
@@ -343,6 +353,7 @@ function syncProject(context, opts, projectIdsAndTokens, projectId, componentIds
|
|
|
343
353
|
codeOpts: context.config.code,
|
|
344
354
|
metadata: get_context_1.generateMetadata(Object.assign(Object.assign({}, metadataDefaults), { platform: context.config.platform }), opts.metadata),
|
|
345
355
|
indirect,
|
|
356
|
+
wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
|
|
346
357
|
});
|
|
347
358
|
// Convert from TSX => JSX
|
|
348
359
|
if (context.config.code.lang === "js") {
|
package/dist/api.d.ts
CHANGED
|
@@ -76,6 +76,13 @@ export interface RequiredPackages {
|
|
|
76
76
|
"@plasmicapp/react-web": string;
|
|
77
77
|
"@plasmicapp/react-web-runtime": string;
|
|
78
78
|
}
|
|
79
|
+
export interface ProjectMetaInfo {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
workspaceId?: string;
|
|
83
|
+
hostUrl?: string;
|
|
84
|
+
lastPublishedVersion?: string;
|
|
85
|
+
}
|
|
79
86
|
export interface ProjectBundle {
|
|
80
87
|
components: ComponentBundle[];
|
|
81
88
|
codeComponentMetas: CodeComponentMeta[];
|
|
@@ -177,8 +184,10 @@ export declare class PlasmicApi {
|
|
|
177
184
|
codeOpts: CodeConfig;
|
|
178
185
|
checksums: ChecksumBundle;
|
|
179
186
|
indirect: boolean;
|
|
187
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
180
188
|
metadata?: Metadata;
|
|
181
189
|
}): Promise<ProjectBundle>;
|
|
190
|
+
projectMeta(projectId: string): Promise<ProjectMetaInfo>;
|
|
182
191
|
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>;
|
|
183
192
|
projectStyleTokens(projectId: string, versionRange?: string): Promise<StyleTokensMap>;
|
|
184
193
|
projectIcons(projectId: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
|
package/dist/api.js
CHANGED
|
@@ -93,6 +93,12 @@ class PlasmicApi {
|
|
|
93
93
|
return result.data;
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
projectMeta(projectId) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/meta`);
|
|
99
|
+
return result.data;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
96
102
|
uploadBundle(projectId, bundleName, bundleJs, css, metaJson, genModulePath, genCssPaths, pkgVersion, extraPropMetaJson, themeProviderWrapper, themeModule) {
|
|
97
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
104
|
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/jsbundle/upload`, {
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const update_notifier_1 = __importDefault(require("update-notifier"));
|
|
|
28
28
|
const yargs_1 = __importDefault(require("yargs"));
|
|
29
29
|
const auth = __importStar(require("./actions/auth"));
|
|
30
30
|
const fix_imports_1 = require("./actions/fix-imports");
|
|
31
|
+
const info_1 = require("./actions/info");
|
|
31
32
|
const init_1 = require("./actions/init");
|
|
32
33
|
const projectToken = __importStar(require("./actions/project-token"));
|
|
33
34
|
const sync_1 = require("./actions/sync");
|
|
@@ -118,6 +119,14 @@ yargs_1.default
|
|
|
118
119
|
}));
|
|
119
120
|
})
|
|
120
121
|
.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)))
|
|
122
|
+
.command("info", "Fetches metadata for projects", (yags) => yags.option("projects", {
|
|
123
|
+
alias: "p",
|
|
124
|
+
describe: "ID of plasmic project to check",
|
|
125
|
+
type: "array",
|
|
126
|
+
default: [],
|
|
127
|
+
}), (argv) => {
|
|
128
|
+
error_1.handleError(info_1.printProjectInfo(argv));
|
|
129
|
+
})
|
|
121
130
|
.command("upload-bundle", false, (yargs) => yargs
|
|
122
131
|
.option("project", {
|
|
123
132
|
alias: "p",
|
package/dist/plasmic.schema.json
CHANGED
|
@@ -353,6 +353,9 @@
|
|
|
353
353
|
"css-modules"
|
|
354
354
|
],
|
|
355
355
|
"type": "string"
|
|
356
|
+
},
|
|
357
|
+
"skipGlobalCssImport": {
|
|
358
|
+
"type": "boolean"
|
|
356
359
|
}
|
|
357
360
|
},
|
|
358
361
|
"required": [
|
|
@@ -455,6 +458,10 @@
|
|
|
455
458
|
"tokens": {
|
|
456
459
|
"$ref": "#/definitions/TokensConfig",
|
|
457
460
|
"description": "Config for style tokens"
|
|
461
|
+
},
|
|
462
|
+
"wrapPagesWithGlobalContexts": {
|
|
463
|
+
"description": "Wether we should wrap the pages with the project global contexts or not",
|
|
464
|
+
"type": "boolean"
|
|
458
465
|
}
|
|
459
466
|
},
|
|
460
467
|
"required": [
|
|
@@ -466,7 +473,8 @@
|
|
|
466
473
|
"projects",
|
|
467
474
|
"srcDir",
|
|
468
475
|
"style",
|
|
469
|
-
"tokens"
|
|
476
|
+
"tokens",
|
|
477
|
+
"wrapPagesWithGlobalContexts"
|
|
470
478
|
],
|
|
471
479
|
"type": "object"
|
|
472
480
|
}
|
package/dist/utils/code-utils.js
CHANGED
|
@@ -125,7 +125,7 @@ function tryParsePlasmicImportSpec(node) {
|
|
|
125
125
|
if (!c) {
|
|
126
126
|
return undefined;
|
|
127
127
|
}
|
|
128
|
-
const m = c.value.match(/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent))?/);
|
|
128
|
+
const m = c.value.match(/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext))?/);
|
|
129
129
|
if (m) {
|
|
130
130
|
return { id: m[1], type: m[2] };
|
|
131
131
|
}
|
|
@@ -262,6 +262,14 @@ function replaceImports(context, code, fromPath, fixImportContext, removeImportD
|
|
|
262
262
|
stmt.source.value = meta.componentImportPath;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
+
else if (type === "globalContext") {
|
|
266
|
+
const projectConfig = fixImportContext.projects[uuid];
|
|
267
|
+
if (!projectConfig) {
|
|
268
|
+
throwMissingReference(context, "project", uuid, fromPath);
|
|
269
|
+
}
|
|
270
|
+
const realPath = makeImportPath(context, fromPath, projectConfig.globalContextsFilePath, true);
|
|
271
|
+
stmt.source.value = realPath;
|
|
272
|
+
}
|
|
265
273
|
});
|
|
266
274
|
if (!changed) {
|
|
267
275
|
return code;
|
|
@@ -56,6 +56,8 @@ export interface PlasmicConfig {
|
|
|
56
56
|
globalVariants: GlobalVariantsConfig;
|
|
57
57
|
/** Metadata for each project that has been synced */
|
|
58
58
|
projects: ProjectConfig[];
|
|
59
|
+
/** Wether we should wrap the pages with the project global contexts or not */
|
|
60
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
59
61
|
/** The version of cli when this file was written */
|
|
60
62
|
cliVersion?: string;
|
|
61
63
|
/** Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files */
|
|
@@ -73,6 +75,7 @@ export interface StyleConfig {
|
|
|
73
75
|
scheme: "css" | "css-modules";
|
|
74
76
|
/** File location for global css styles shared by all components. Relative to srcDir */
|
|
75
77
|
defaultStyleCssFilePath: string;
|
|
78
|
+
skipGlobalCssImport?: boolean;
|
|
76
79
|
}
|
|
77
80
|
export interface ImagesConfig {
|
|
78
81
|
/**
|
|
@@ -104,6 +104,14 @@ function removeMissingFilesFromLock(context, config, lock) {
|
|
|
104
104
|
return project;
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @param context
|
|
110
|
+
* @param expectedPath
|
|
111
|
+
* @param baseNameToFiles
|
|
112
|
+
* @returns The path if we are able to find the file, undefined if we need to recreate it
|
|
113
|
+
* @throws if the user interrupts flow
|
|
114
|
+
*/
|
|
107
115
|
function attemptToRestoreFilePath(context, expectedPath, baseNameToFiles) {
|
|
108
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
117
|
// If the path is not set, always recreate.
|
|
@@ -163,16 +171,19 @@ function resolveMissingFilesInConfig(context, config) {
|
|
|
163
171
|
});
|
|
164
172
|
}
|
|
165
173
|
context.config.globalVariants.variantGroups = yield filterFiles(context.config.globalVariants.variantGroups, "contextFilePath");
|
|
174
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
166
175
|
context.config.style.defaultStyleCssFilePath =
|
|
167
|
-
(yield attemptToRestoreFilePath(context, context.config.style.defaultStyleCssFilePath, baseNameToFiles)) ||
|
|
176
|
+
(yield attemptToRestoreFilePath(context, context.config.style.defaultStyleCssFilePath, baseNameToFiles)) || context.config.style.defaultStyleCssFilePath;
|
|
177
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
168
178
|
for (const project of config.projects) {
|
|
169
179
|
project.cssFilePath =
|
|
170
|
-
(yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) ||
|
|
180
|
+
(yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) || project.cssFilePath;
|
|
171
181
|
if (!project.globalContextsFilePath) {
|
|
172
182
|
project.globalContextsFilePath = "";
|
|
173
183
|
}
|
|
184
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
174
185
|
project.globalContextsFilePath =
|
|
175
|
-
(yield attemptToRestoreFilePath(context, project.globalContextsFilePath, baseNameToFiles)) ||
|
|
186
|
+
(yield attemptToRestoreFilePath(context, project.globalContextsFilePath, baseNameToFiles)) || project.globalContextsFilePath;
|
|
176
187
|
project.images = yield filterFiles(project.images, "filePath");
|
|
177
188
|
project.icons = yield filterFiles(project.icons, "moduleFilePath");
|
|
178
189
|
project.jsBundleThemes = yield filterFiles(project.jsBundleThemes || [], "themeFilePath");
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommonArgs } from "..";
|
|
2
|
+
import { logger } from "../deps";
|
|
3
|
+
import { getContext } from "../utils/get-context";
|
|
4
|
+
|
|
5
|
+
export interface InfoArgs extends CommonArgs {
|
|
6
|
+
projects: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function printProjectInfo(opts: InfoArgs): Promise<void> {
|
|
10
|
+
let context = await getContext(opts);
|
|
11
|
+
const results = await Promise.all(
|
|
12
|
+
opts.projects.map(async (p) => await context.api.projectMeta(p))
|
|
13
|
+
);
|
|
14
|
+
for (const meta of results) {
|
|
15
|
+
logger.info(`Id: ${meta.id}`);
|
|
16
|
+
logger.info(`Name: ${meta.name}`);
|
|
17
|
+
logger.info(`Host URL: ${meta.hostUrl ?? null}`);
|
|
18
|
+
logger.info(`Last published version: ${meta.lastPublishedVersion ?? null}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/actions/sync.ts
CHANGED
|
@@ -60,11 +60,11 @@ import {
|
|
|
60
60
|
ComponentPendingMerge,
|
|
61
61
|
syncProjectComponents,
|
|
62
62
|
} from "./sync-components";
|
|
63
|
+
import { syncGlobalContexts } from "./sync-global-contexts";
|
|
63
64
|
import { syncGlobalVariants } from "./sync-global-variants";
|
|
64
65
|
import { syncProjectIconAssets } from "./sync-icons";
|
|
65
66
|
import { syncProjectImageAssets } from "./sync-images";
|
|
66
67
|
import { upsertStyleTokens } from "./sync-styles";
|
|
67
|
-
import { syncGlobalContexts } from "./sync-global-contexts";
|
|
68
68
|
|
|
69
69
|
export interface SyncArgs extends CommonArgs {
|
|
70
70
|
projects: readonly string[];
|
|
@@ -488,14 +488,25 @@ async function checkExternalPkgs(
|
|
|
488
488
|
function maybeRenamePathExt(
|
|
489
489
|
context: PlasmicContext,
|
|
490
490
|
path: string,
|
|
491
|
-
ext: string
|
|
491
|
+
ext: string,
|
|
492
|
+
opts?: {
|
|
493
|
+
continueOnFailure?: boolean;
|
|
494
|
+
}
|
|
492
495
|
) {
|
|
493
496
|
if (!path) {
|
|
494
497
|
return path;
|
|
495
498
|
}
|
|
496
499
|
const correctPath = `${stripExtension(path, true)}${ext}`;
|
|
497
500
|
if (path !== correctPath) {
|
|
498
|
-
|
|
501
|
+
try {
|
|
502
|
+
renameFile(context, path, correctPath);
|
|
503
|
+
} catch (e) {
|
|
504
|
+
if (!opts?.continueOnFailure) {
|
|
505
|
+
throw e;
|
|
506
|
+
} else {
|
|
507
|
+
logger.warn(e);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
499
510
|
}
|
|
500
511
|
return correctPath;
|
|
501
512
|
}
|
|
@@ -506,19 +517,22 @@ function fixFileExtension(context: PlasmicContext) {
|
|
|
506
517
|
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(
|
|
507
518
|
context,
|
|
508
519
|
context.config.style.defaultStyleCssFilePath,
|
|
509
|
-
cssExt
|
|
520
|
+
cssExt,
|
|
521
|
+
{ continueOnFailure: true }
|
|
510
522
|
);
|
|
511
523
|
context.config.projects.forEach((project) => {
|
|
512
524
|
project.cssFilePath = maybeRenamePathExt(
|
|
513
525
|
context,
|
|
514
526
|
project.cssFilePath,
|
|
515
|
-
cssExt
|
|
527
|
+
cssExt,
|
|
528
|
+
{ continueOnFailure: true }
|
|
516
529
|
);
|
|
517
530
|
project.components.forEach((component) => {
|
|
518
531
|
component.cssFilePath = maybeRenamePathExt(
|
|
519
532
|
context,
|
|
520
533
|
component.cssFilePath,
|
|
521
|
-
cssExt
|
|
534
|
+
cssExt,
|
|
535
|
+
{ continueOnFailure: true }
|
|
522
536
|
);
|
|
523
537
|
});
|
|
524
538
|
});
|
|
@@ -581,6 +595,7 @@ async function syncProject(
|
|
|
581
595
|
opts.metadata
|
|
582
596
|
),
|
|
583
597
|
indirect,
|
|
598
|
+
wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
|
|
584
599
|
});
|
|
585
600
|
|
|
586
601
|
// Convert from TSX => JSX
|
package/src/api.ts
CHANGED
|
@@ -98,6 +98,14 @@ export interface RequiredPackages {
|
|
|
98
98
|
"@plasmicapp/react-web-runtime": string;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export interface ProjectMetaInfo {
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
workspaceId?: string;
|
|
105
|
+
hostUrl?: string;
|
|
106
|
+
lastPublishedVersion?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
export interface ProjectBundle {
|
|
102
110
|
components: ComponentBundle[];
|
|
103
111
|
codeComponentMetas: CodeComponentMeta[];
|
|
@@ -258,6 +266,7 @@ export class PlasmicApi {
|
|
|
258
266
|
codeOpts: CodeConfig;
|
|
259
267
|
checksums: ChecksumBundle;
|
|
260
268
|
indirect: boolean;
|
|
269
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
261
270
|
metadata?: Metadata;
|
|
262
271
|
}
|
|
263
272
|
): Promise<ProjectBundle> {
|
|
@@ -270,6 +279,13 @@ export class PlasmicApi {
|
|
|
270
279
|
return result.data as ProjectBundle;
|
|
271
280
|
}
|
|
272
281
|
|
|
282
|
+
async projectMeta(projectId: string) {
|
|
283
|
+
const result = await this.post(
|
|
284
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/meta`
|
|
285
|
+
);
|
|
286
|
+
return result.data as ProjectMetaInfo;
|
|
287
|
+
}
|
|
288
|
+
|
|
273
289
|
async uploadBundle(
|
|
274
290
|
projectId: string,
|
|
275
291
|
bundleName: string,
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import updateNotifier from "update-notifier";
|
|
|
4
4
|
import yargs from "yargs";
|
|
5
5
|
import * as auth from "./actions/auth";
|
|
6
6
|
import { fixImports, FixImportsArgs } from "./actions/fix-imports";
|
|
7
|
+
import { InfoArgs, printProjectInfo } from "./actions/info";
|
|
7
8
|
import { getYargsOption, InitArgs, initPlasmic } from "./actions/init";
|
|
8
9
|
import * as projectToken from "./actions/project-token";
|
|
9
10
|
import { sync, SyncArgs } from "./actions/sync";
|
|
@@ -134,6 +135,20 @@ yargs
|
|
|
134
135
|
(yags) => 0,
|
|
135
136
|
(argv) => handleError(fixImports(argv))
|
|
136
137
|
)
|
|
138
|
+
.command<InfoArgs>(
|
|
139
|
+
"info",
|
|
140
|
+
"Fetches metadata for projects",
|
|
141
|
+
(yags) =>
|
|
142
|
+
yags.option("projects", {
|
|
143
|
+
alias: "p",
|
|
144
|
+
describe: "ID of plasmic project to check",
|
|
145
|
+
type: "array",
|
|
146
|
+
default: [],
|
|
147
|
+
}),
|
|
148
|
+
(argv) => {
|
|
149
|
+
handleError(printProjectInfo(argv));
|
|
150
|
+
}
|
|
151
|
+
)
|
|
137
152
|
.command<UploadBundleArgs>(
|
|
138
153
|
"upload-bundle",
|
|
139
154
|
false,
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -156,6 +156,7 @@ type PlasmicImportType =
|
|
|
156
156
|
| "picture"
|
|
157
157
|
| "jsBundle"
|
|
158
158
|
| "codeComponent"
|
|
159
|
+
| "globalContext"
|
|
159
160
|
| undefined;
|
|
160
161
|
|
|
161
162
|
function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
@@ -164,7 +165,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
|
164
165
|
return undefined;
|
|
165
166
|
}
|
|
166
167
|
const m = c.value.match(
|
|
167
|
-
/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent))?/
|
|
168
|
+
/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext))?/
|
|
168
169
|
);
|
|
169
170
|
if (m) {
|
|
170
171
|
return { id: m[1], type: m[2] as PlasmicImportType } as PlasmicImportSpec;
|
|
@@ -337,6 +338,18 @@ export function replaceImports(
|
|
|
337
338
|
// npm package
|
|
338
339
|
stmt.source.value = meta.componentImportPath;
|
|
339
340
|
}
|
|
341
|
+
} else if (type === "globalContext") {
|
|
342
|
+
const projectConfig = fixImportContext.projects[uuid];
|
|
343
|
+
if (!projectConfig) {
|
|
344
|
+
throwMissingReference(context, "project", uuid, fromPath);
|
|
345
|
+
}
|
|
346
|
+
const realPath = makeImportPath(
|
|
347
|
+
context,
|
|
348
|
+
fromPath,
|
|
349
|
+
projectConfig.globalContextsFilePath,
|
|
350
|
+
true
|
|
351
|
+
);
|
|
352
|
+
stmt.source.value = realPath;
|
|
340
353
|
}
|
|
341
354
|
});
|
|
342
355
|
|
|
@@ -85,6 +85,9 @@ export interface PlasmicConfig {
|
|
|
85
85
|
/** Metadata for each project that has been synced */
|
|
86
86
|
projects: ProjectConfig[];
|
|
87
87
|
|
|
88
|
+
/** Wether we should wrap the pages with the project global contexts or not */
|
|
89
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
90
|
+
|
|
88
91
|
/** The version of cli when this file was written */
|
|
89
92
|
cliVersion?: string;
|
|
90
93
|
|
|
@@ -108,6 +111,8 @@ export interface StyleConfig {
|
|
|
108
111
|
|
|
109
112
|
/** File location for global css styles shared by all components. Relative to srcDir */
|
|
110
113
|
defaultStyleCssFilePath: string;
|
|
114
|
+
|
|
115
|
+
skipGlobalCssImport?: boolean;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
export interface ImagesConfig {
|
|
@@ -409,6 +414,7 @@ export const DEFAULT_CONFIG: PlasmicConfig = {
|
|
|
409
414
|
globalVariants: {
|
|
410
415
|
variantGroups: [],
|
|
411
416
|
},
|
|
417
|
+
wrapPagesWithGlobalContexts: true,
|
|
412
418
|
};
|
|
413
419
|
|
|
414
420
|
export const DEFAULT_PUBLIC_FILES_CONFIG: ImagesConfig = {
|
package/src/utils/get-context.ts
CHANGED
|
@@ -106,6 +106,14 @@ function removeMissingFilesFromLock(
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param context
|
|
112
|
+
* @param expectedPath
|
|
113
|
+
* @param baseNameToFiles
|
|
114
|
+
* @returns The path if we are able to find the file, undefined if we need to recreate it
|
|
115
|
+
* @throws if the user interrupts flow
|
|
116
|
+
*/
|
|
109
117
|
async function attemptToRestoreFilePath(
|
|
110
118
|
context: PlasmicContext,
|
|
111
119
|
expectedPath: string,
|
|
@@ -193,30 +201,34 @@ async function resolveMissingFilesInConfig(
|
|
|
193
201
|
"contextFilePath"
|
|
194
202
|
);
|
|
195
203
|
|
|
204
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
196
205
|
context.config.style.defaultStyleCssFilePath =
|
|
197
206
|
(await attemptToRestoreFilePath(
|
|
198
207
|
context,
|
|
199
208
|
context.config.style.defaultStyleCssFilePath,
|
|
200
209
|
baseNameToFiles
|
|
201
|
-
)) ||
|
|
210
|
+
)) || context.config.style.defaultStyleCssFilePath;
|
|
202
211
|
|
|
212
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
203
213
|
for (const project of config.projects) {
|
|
204
214
|
project.cssFilePath =
|
|
205
215
|
(await attemptToRestoreFilePath(
|
|
206
216
|
context,
|
|
207
217
|
project.cssFilePath,
|
|
208
218
|
baseNameToFiles
|
|
209
|
-
)) ||
|
|
219
|
+
)) || project.cssFilePath;
|
|
210
220
|
|
|
211
221
|
if (!project.globalContextsFilePath) {
|
|
212
222
|
project.globalContextsFilePath = "";
|
|
213
223
|
}
|
|
224
|
+
|
|
225
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
214
226
|
project.globalContextsFilePath =
|
|
215
227
|
(await attemptToRestoreFilePath(
|
|
216
228
|
context,
|
|
217
229
|
project.globalContextsFilePath,
|
|
218
230
|
baseNameToFiles
|
|
219
|
-
)) ||
|
|
231
|
+
)) || project.globalContextsFilePath;
|
|
220
232
|
|
|
221
233
|
project.images = await filterFiles(project.images, "filePath");
|
|
222
234
|
project.icons = await filterFiles(project.icons, "moduleFilePath");
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureImportModuleType = void 0;
|
|
4
|
-
function ensureImportModuleType(config) {
|
|
5
|
-
for (const project of config.projects) {
|
|
6
|
-
for (const component of project.components) {
|
|
7
|
-
component.importSpec.moduleType = "local";
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return config;
|
|
11
|
-
}
|
|
12
|
-
exports.ensureImportModuleType = ensureImportModuleType;
|