@plasmicapp/cli 0.1.173 → 0.1.176
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/sync.js +17 -6
- package/dist/api.d.ts +1 -0
- package/dist/plasmic.schema.json +6 -1
- package/dist/test-common/fixtures.js +1 -0
- package/dist/utils/code-utils.js +13 -3
- package/dist/utils/config-utils.d.ts +2 -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/sync.ts +21 -6
- package/src/api.ts +1 -0
- package/src/test-common/fixtures.ts +1 -0
- package/src/utils/code-utils.ts +18 -3
- package/src/utils/config-utils.ts +4 -0
- package/src/utils/get-context.ts +15 -3
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
|
@@ -184,6 +184,7 @@ export declare class PlasmicApi {
|
|
|
184
184
|
codeOpts: CodeConfig;
|
|
185
185
|
checksums: ChecksumBundle;
|
|
186
186
|
indirect: boolean;
|
|
187
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
187
188
|
metadata?: Metadata;
|
|
188
189
|
}): Promise<ProjectBundle>;
|
|
189
190
|
projectMeta(projectId: string): Promise<ProjectMetaInfo>;
|
package/dist/plasmic.schema.json
CHANGED
|
@@ -458,6 +458,10 @@
|
|
|
458
458
|
"tokens": {
|
|
459
459
|
"$ref": "#/definitions/TokensConfig",
|
|
460
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"
|
|
461
465
|
}
|
|
462
466
|
},
|
|
463
467
|
"required": [
|
|
@@ -469,7 +473,8 @@
|
|
|
469
473
|
"projects",
|
|
470
474
|
"srcDir",
|
|
471
475
|
"style",
|
|
472
|
-
"tokens"
|
|
476
|
+
"tokens",
|
|
477
|
+
"wrapPagesWithGlobalContexts"
|
|
473
478
|
],
|
|
474
479
|
"type": "object"
|
|
475
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;
|
|
@@ -297,8 +305,10 @@ function makeImportPath(context, fromPath, toPath, stripExt, forceRelative = fal
|
|
|
297
305
|
* a local file
|
|
298
306
|
*/
|
|
299
307
|
function isLocalModulePath(modulePath) {
|
|
300
|
-
// It is a local file reference if the importPath includes the file extension
|
|
301
|
-
|
|
308
|
+
// It is a local file reference if the importPath includes the file extension, and
|
|
309
|
+
// modulePath doesn't start with "@" (like an alias by convention, or scoped npm
|
|
310
|
+
// package). This is not a reliable way to detect scoped npm package, but :shrug:
|
|
311
|
+
return !!upath_1.default.extname(modulePath) && !modulePath.startsWith("@");
|
|
302
312
|
}
|
|
303
313
|
exports.isLocalModulePath = isLocalModulePath;
|
|
304
314
|
exports.mkFixImportContext = (config) => {
|
|
@@ -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 */
|
|
@@ -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
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
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
|
|
|
@@ -392,8 +405,10 @@ function makeImportPath(
|
|
|
392
405
|
* a local file
|
|
393
406
|
*/
|
|
394
407
|
export function isLocalModulePath(modulePath: string) {
|
|
395
|
-
// It is a local file reference if the importPath includes the file extension
|
|
396
|
-
|
|
408
|
+
// It is a local file reference if the importPath includes the file extension, and
|
|
409
|
+
// modulePath doesn't start with "@" (like an alias by convention, or scoped npm
|
|
410
|
+
// package). This is not a reliable way to detect scoped npm package, but :shrug:
|
|
411
|
+
return !!path.extname(modulePath) && !modulePath.startsWith("@");
|
|
397
412
|
}
|
|
398
413
|
|
|
399
414
|
export interface ComponentUpdateSummary {
|
|
@@ -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
|
|
|
@@ -411,6 +414,7 @@ export const DEFAULT_CONFIG: PlasmicConfig = {
|
|
|
411
414
|
globalVariants: {
|
|
412
415
|
variantGroups: [],
|
|
413
416
|
},
|
|
417
|
+
wrapPagesWithGlobalContexts: true,
|
|
414
418
|
};
|
|
415
419
|
|
|
416
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");
|