@plasmicapp/cli 0.1.167 → 0.1.171
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/__mocks__/api.js +6 -0
- package/dist/actions/fix-imports.js +2 -2
- package/dist/actions/info.d.ts +5 -0
- package/dist/actions/info.js +27 -0
- package/dist/actions/sync-global-contexts.d.ts +4 -0
- package/dist/actions/sync-global-contexts.js +61 -0
- package/dist/actions/sync.js +8 -0
- package/dist/api.d.ts +8 -0
- package/dist/api.js +9 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/plasmic.schema.json +5 -0
- package/dist/test-common/fixtures.js +1 -0
- package/dist/utils/checksum.js +7 -0
- package/dist/utils/code-utils.js +28 -1
- package/dist/utils/config-utils.d.ts +4 -1
- package/dist/utils/config-utils.js +2 -0
- package/dist/utils/file-utils.d.ts +0 -5
- package/dist/utils/file-utils.js +2 -32
- package/dist/utils/get-context.js +8 -4
- package/dist/utils/resolve-utils.js +32 -4
- package/package.json +2 -2
- package/src/__mocks__/api.ts +5 -0
- package/src/actions/fix-imports.ts +2 -3
- package/src/actions/sync-global-contexts.ts +87 -0
- package/src/actions/sync.ts +20 -0
- package/src/api.ts +19 -0
- package/src/test-common/fixtures.ts +1 -0
- package/src/utils/checksum.ts +12 -0
- package/src/utils/code-utils.ts +43 -0
- package/src/utils/config-utils.ts +8 -1
- package/src/utils/file-utils.ts +1 -38
- package/src/utils/get-context.ts +13 -4
- package/src/utils/resolve-utils.ts +46 -10
package/dist/__mocks__/api.js
CHANGED
|
@@ -249,6 +249,7 @@ class PlasmicApi {
|
|
|
249
249
|
iconChecksums: [],
|
|
250
250
|
globalVariantChecksums: [],
|
|
251
251
|
projectCssChecksum: "",
|
|
252
|
+
globalContextsChecksum: "",
|
|
252
253
|
},
|
|
253
254
|
usedNpmPackages: [],
|
|
254
255
|
externalCssImports: [],
|
|
@@ -276,6 +277,11 @@ class PlasmicApi {
|
|
|
276
277
|
throw new Error("Unimplemented");
|
|
277
278
|
});
|
|
278
279
|
}
|
|
280
|
+
latestCodegenVersion() {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
return "0.0.1";
|
|
283
|
+
});
|
|
284
|
+
}
|
|
279
285
|
requiredPackages() {
|
|
280
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
287
|
return {
|
|
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.fixImports = void 0;
|
|
13
13
|
const code_utils_1 = require("../utils/code-utils");
|
|
14
|
-
const
|
|
14
|
+
const config_utils_1 = require("../utils/config-utils");
|
|
15
15
|
const get_context_1 = require("../utils/get-context");
|
|
16
16
|
function fixImports(opts) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
if (!opts.baseDir)
|
|
19
19
|
opts.baseDir = process.cwd();
|
|
20
20
|
const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
|
|
21
|
-
yield
|
|
21
|
+
yield config_utils_1.updateConfig(context, context.config, opts.baseDir);
|
|
22
22
|
yield code_utils_1.fixAllImportStatements(context, opts.baseDir);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.printProjectInfo = void 0;
|
|
13
|
+
const deps_1 = require("../deps");
|
|
14
|
+
const get_context_1 = require("../utils/get-context");
|
|
15
|
+
function printProjectInfo(opts) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
let context = yield get_context_1.getContext(opts);
|
|
18
|
+
const results = yield Promise.all(opts.projects.map((p) => __awaiter(this, void 0, void 0, function* () { return yield context.api.projectMeta(p); })));
|
|
19
|
+
for (const meta of results) {
|
|
20
|
+
deps_1.logger.info(`Id: ${meta.id}`);
|
|
21
|
+
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}`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.printProjectInfo = printProjectInfo;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ChecksumBundle, ProjectMetaBundle } from "../api";
|
|
2
|
+
import { PlasmicContext, ProjectConfig, ProjectLock } from "../utils/config-utils";
|
|
3
|
+
export declare function syncGlobalContexts(context: PlasmicContext, projectMeta: ProjectMetaBundle, projectConfig: ProjectConfig, projectLock: ProjectLock, checksums: ChecksumBundle, baseDir: string): Promise<void>;
|
|
4
|
+
export declare function getGlobalContextsResourcePath(context: PlasmicContext, projectConfig: ProjectConfig): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
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.getGlobalContextsResourcePath = exports.syncGlobalContexts = void 0;
|
|
16
|
+
const deps_1 = require("../deps");
|
|
17
|
+
const code_utils_1 = require("../utils/code-utils");
|
|
18
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
19
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
20
|
+
const COMPONENT_NAME = "PlasmicGlobalContextsProvider";
|
|
21
|
+
function syncGlobalContexts(context, projectMeta, projectConfig, projectLock, checksums, baseDir) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const resourcePath = getGlobalContextsResourcePath(context, projectConfig);
|
|
24
|
+
if (checksums.globalContextsChecksum && projectMeta.globalContextBundle) {
|
|
25
|
+
if (context.cliArgs.quiet !== true) {
|
|
26
|
+
deps_1.logger.info(`Syncing component: ${COMPONENT_NAME}@${projectLock.version}\t['${projectConfig.projectName}' ${projectConfig.projectId} ${projectConfig.version}]`);
|
|
27
|
+
}
|
|
28
|
+
if (context.config.code.lang === "js") {
|
|
29
|
+
projectMeta.globalContextBundle.contextModule = code_utils_1.formatScript(code_utils_1.tsxToJsx(projectMeta.globalContextBundle.contextModule), baseDir);
|
|
30
|
+
}
|
|
31
|
+
file_utils_1.writeFileContent(context, resourcePath, projectMeta.globalContextBundle.contextModule, { force: false });
|
|
32
|
+
projectConfig.globalContextsFilePath = resourcePath;
|
|
33
|
+
const fl = projectLock.fileLocks.find((fl) => fl.assetId === projectConfig.projectId && fl.type === "globalContexts");
|
|
34
|
+
if (fl) {
|
|
35
|
+
fl.checksum = checksums.globalContextsChecksum;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
projectLock.fileLocks.push({
|
|
39
|
+
assetId: projectConfig.projectId,
|
|
40
|
+
checksum: checksums.globalContextsChecksum,
|
|
41
|
+
type: "globalContexts",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (!checksums.globalContextsChecksum &&
|
|
46
|
+
!projectMeta.globalContextBundle) {
|
|
47
|
+
if (file_utils_1.fileExists(context, resourcePath)) {
|
|
48
|
+
file_utils_1.deleteFile(context, resourcePath);
|
|
49
|
+
}
|
|
50
|
+
projectConfig.globalContextsFilePath = "";
|
|
51
|
+
lodash_1.default.remove(projectLock.fileLocks, (fl) => fl.assetId === projectConfig.projectId && fl.type === "globalContexts");
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.syncGlobalContexts = syncGlobalContexts;
|
|
56
|
+
function getGlobalContextsResourcePath(context, projectConfig) {
|
|
57
|
+
return projectConfig.globalContextsFilePath !== ""
|
|
58
|
+
? projectConfig.globalContextsFilePath
|
|
59
|
+
: file_utils_1.defaultResourcePath(context, projectConfig, `${COMPONENT_NAME}.${context.config.code.lang === "ts" ? "tsx" : "jsx"}`);
|
|
60
|
+
}
|
|
61
|
+
exports.getGlobalContextsResourcePath = getGlobalContextsResourcePath;
|
package/dist/actions/sync.js
CHANGED
|
@@ -54,6 +54,7 @@ const sync_global_variants_1 = require("./sync-global-variants");
|
|
|
54
54
|
const sync_icons_1 = require("./sync-icons");
|
|
55
55
|
const sync_images_1 = require("./sync-images");
|
|
56
56
|
const sync_styles_1 = require("./sync-styles");
|
|
57
|
+
const sync_global_contexts_1 = require("./sync-global-contexts");
|
|
57
58
|
function ensureRequiredPackages(context, baseDir, yes) {
|
|
58
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
60
|
const requireds = yield context.api.requiredPackages();
|
|
@@ -257,6 +258,12 @@ function sync(opts, metadataDefaults) {
|
|
|
257
258
|
const config = Object.assign(Object.assign({}, loaderConfig), { projects: lodash_1.default.sortBy(lodash_1.default.uniqBy([...freshIdsAndTokens, ...((_b = loaderConfig === null || loaderConfig === void 0 ? void 0 : loaderConfig.projects) !== null && _b !== void 0 ? _b : [])], (p) => p.projectId), (p) => p.projectId) });
|
|
258
259
|
writeLoaderConfig(opts, config);
|
|
259
260
|
}
|
|
261
|
+
const codegenVersion = yield context.api.latestCodegenVersion();
|
|
262
|
+
context.lock.projects.forEach((p) => {
|
|
263
|
+
if (projectsToSync.some((syncedProject) => syncedProject.projectId === p.projectId)) {
|
|
264
|
+
p.codegenVersion = codegenVersion;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
260
267
|
// Write the new ComponentConfigs to disk
|
|
261
268
|
yield config_utils_1.updateConfig(context, context.config, baseDir);
|
|
262
269
|
}));
|
|
@@ -438,6 +445,7 @@ function syncProjectConfig(context, projectBundle, projectApiToken, version, dep
|
|
|
438
445
|
projectConfig.jsBundleThemes.length === 0) {
|
|
439
446
|
delete projectConfig.jsBundleThemes;
|
|
440
447
|
}
|
|
448
|
+
yield sync_global_contexts_1.syncGlobalContexts(context, projectBundle, projectConfig, projectLock, checksums, baseDir);
|
|
441
449
|
// Write out components
|
|
442
450
|
yield sync_components_1.syncProjectComponents(context, projectConfig, version, componentBundles, forceOverwrite, appendJsxOnMissingBase, summary, pendingMerge, projectLock, checksums, baseDir);
|
|
443
451
|
});
|
package/dist/api.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export interface GlobalVariantBundle {
|
|
|
25
25
|
contextModule: string;
|
|
26
26
|
contextFileName: string;
|
|
27
27
|
}
|
|
28
|
+
export interface GlobalContextBundle {
|
|
29
|
+
id: string;
|
|
30
|
+
contextModule: string;
|
|
31
|
+
}
|
|
28
32
|
export interface JsBundleTheme {
|
|
29
33
|
themeFileName: string;
|
|
30
34
|
themeModule: string;
|
|
@@ -36,6 +40,7 @@ export interface ProjectMetaBundle {
|
|
|
36
40
|
cssFileName: string;
|
|
37
41
|
cssRules: string;
|
|
38
42
|
jsBundleThemes?: JsBundleTheme[];
|
|
43
|
+
globalContextBundle?: GlobalContextBundle;
|
|
39
44
|
}
|
|
40
45
|
export interface IconBundle {
|
|
41
46
|
id: string;
|
|
@@ -111,6 +116,7 @@ export interface ChecksumBundle {
|
|
|
111
116
|
iconChecksums: Array<[string, string]>;
|
|
112
117
|
globalVariantChecksums: Array<[string, string]>;
|
|
113
118
|
projectCssChecksum: string;
|
|
119
|
+
globalContextsChecksum: string;
|
|
114
120
|
}
|
|
115
121
|
export interface CodeComponentMeta {
|
|
116
122
|
id: string;
|
|
@@ -127,6 +133,7 @@ export interface ProjectIdAndToken {
|
|
|
127
133
|
}
|
|
128
134
|
export declare class PlasmicApi {
|
|
129
135
|
private auth;
|
|
136
|
+
private codegenVersion?;
|
|
130
137
|
constructor(auth: AuthConfig);
|
|
131
138
|
genStyleConfig(styleOpts?: StyleConfig): Promise<StyleConfigResponse>;
|
|
132
139
|
/**
|
|
@@ -146,6 +153,7 @@ export declare class PlasmicApi {
|
|
|
146
153
|
}[], recursive?: boolean): Promise<VersionResolution>;
|
|
147
154
|
getCurrentUser(): Promise<import("axios").AxiosResponse<any>>;
|
|
148
155
|
requiredPackages(): Promise<RequiredPackages>;
|
|
156
|
+
latestCodegenVersion(): Promise<string>;
|
|
149
157
|
/**
|
|
150
158
|
* Code-gen endpoint.
|
|
151
159
|
* This will fetch components at an exact specified version.
|
package/dist/api.js
CHANGED
|
@@ -66,6 +66,15 @@ class PlasmicApi {
|
|
|
66
66
|
return Object.assign({}, resp.data);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
latestCodegenVersion() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (!this.codegenVersion) {
|
|
72
|
+
const resp = yield this.post(`${this.codegenHost}/api/v1/code/latest-codegen-version`);
|
|
73
|
+
this.codegenVersion = resp.data;
|
|
74
|
+
}
|
|
75
|
+
return this.codegenVersion;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
69
78
|
/**
|
|
70
79
|
* Code-gen endpoint.
|
|
71
80
|
* This will fetch components at an exact specified version.
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
package/dist/plasmic.schema.json
CHANGED
|
@@ -282,6 +282,10 @@
|
|
|
282
282
|
"description": "File location for the project-wide css styles. Relative to srcDir",
|
|
283
283
|
"type": "string"
|
|
284
284
|
},
|
|
285
|
+
"globalContextsFilePath": {
|
|
286
|
+
"description": "File location for the project-wide global contexts. Relative to srcDir",
|
|
287
|
+
"type": "string"
|
|
288
|
+
},
|
|
285
289
|
"icons": {
|
|
286
290
|
"description": "Metadata for each synced icon in this project",
|
|
287
291
|
"items": {
|
|
@@ -326,6 +330,7 @@
|
|
|
326
330
|
"required": [
|
|
327
331
|
"components",
|
|
328
332
|
"cssFilePath",
|
|
333
|
+
"globalContextsFilePath",
|
|
329
334
|
"icons",
|
|
330
335
|
"images",
|
|
331
336
|
"indirect",
|
package/dist/utils/checksum.js
CHANGED
|
@@ -13,6 +13,7 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
13
13
|
cssRulesChecksums: [],
|
|
14
14
|
globalVariantChecksums: [],
|
|
15
15
|
projectCssChecksum: "",
|
|
16
|
+
globalContextsChecksum: "",
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
const fileLocks = projectLock.fileLocks;
|
|
@@ -51,6 +52,11 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
51
52
|
const projectCssChecksums = fileLocks.filter((fileLock) => fileLock.type === "projectCss");
|
|
52
53
|
lang_utils_1.assert(projectCssChecksums.length < 2);
|
|
53
54
|
const projectCssChecksum = projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
55
|
+
const globalContextsChecksums = fileLocks.filter((fileLock) => fileLock.type === "globalContexts" && fileLock.assetId === projectId);
|
|
56
|
+
lang_utils_1.assert(globalContextsChecksums.length < 2);
|
|
57
|
+
const globalContextsChecksum = globalContextsChecksums.length > 0
|
|
58
|
+
? globalContextsChecksums[0].checksum
|
|
59
|
+
: "";
|
|
54
60
|
return {
|
|
55
61
|
imageChecksums,
|
|
56
62
|
iconChecksums,
|
|
@@ -58,6 +64,7 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
58
64
|
cssRulesChecksums,
|
|
59
65
|
globalVariantChecksums,
|
|
60
66
|
projectCssChecksum,
|
|
67
|
+
globalContextsChecksum,
|
|
61
68
|
};
|
|
62
69
|
}
|
|
63
70
|
exports.getChecksums = getChecksums;
|
package/dist/utils/code-utils.js
CHANGED
|
@@ -41,9 +41,11 @@ const Prettier = __importStar(require("prettier"));
|
|
|
41
41
|
const prettier_1 = require("prettier");
|
|
42
42
|
const ts = __importStar(require("typescript"));
|
|
43
43
|
const upath_1 = __importDefault(require("upath"));
|
|
44
|
+
const sync_global_contexts_1 = require("../actions/sync-global-contexts");
|
|
44
45
|
const sync_images_1 = require("../actions/sync-images");
|
|
45
46
|
const deps_1 = require("../deps");
|
|
46
47
|
const error_1 = require("../utils/error");
|
|
48
|
+
const config_utils_1 = require("./config-utils");
|
|
47
49
|
const file_utils_1 = require("./file-utils");
|
|
48
50
|
const lang_utils_1 = require("./lang-utils");
|
|
49
51
|
exports.formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
|
|
@@ -341,13 +343,15 @@ function fixAllImportStatements(context, baseDir, summary) {
|
|
|
341
343
|
}
|
|
342
344
|
}
|
|
343
345
|
}
|
|
346
|
+
fixGlobalContextImportStatements(context, fixImportContext, baseDir);
|
|
344
347
|
});
|
|
345
348
|
}
|
|
346
349
|
exports.fixAllImportStatements = fixAllImportStatements;
|
|
347
350
|
function fixComponentImportStatements(context, compConfig, fixImportContext, fixSkeletonModule, baseDir) {
|
|
348
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
352
|
// If ComponentConfig.importPath is still a local file, we best-effort also fix up the import statements there.
|
|
350
|
-
if (
|
|
353
|
+
if (compConfig.type !== "mapped" &&
|
|
354
|
+
isLocalModulePath(compConfig.importSpec.modulePath) &&
|
|
351
355
|
fixSkeletonModule) {
|
|
352
356
|
yield fixFileImportStatements(context, compConfig.importSpec.modulePath, fixImportContext, true, baseDir);
|
|
353
357
|
}
|
|
@@ -455,3 +459,26 @@ exports.formatScript = (code, baseDir) => {
|
|
|
455
459
|
useTabs: false,
|
|
456
460
|
});
|
|
457
461
|
};
|
|
462
|
+
function fixGlobalContextImportStatements(context, fixImportContext, baseDir) {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
for (const project of context.config.projects) {
|
|
465
|
+
if (!project.globalContextsFilePath)
|
|
466
|
+
continue;
|
|
467
|
+
const resourcePath = sync_global_contexts_1.getGlobalContextsResourcePath(context, project);
|
|
468
|
+
let prevContent;
|
|
469
|
+
try {
|
|
470
|
+
prevContent = file_utils_1.readFileText(file_utils_1.makeFilePath(context, resourcePath)).toString();
|
|
471
|
+
}
|
|
472
|
+
catch (e) {
|
|
473
|
+
deps_1.logger.warn(`${resourcePath} is missing. If you deleted this component, remember to remove the component from ${config_utils_1.CONFIG_FILE_NAME}`);
|
|
474
|
+
throw e;
|
|
475
|
+
}
|
|
476
|
+
const newContent = replaceImports(context, prevContent, resourcePath, fixImportContext, false, baseDir, true);
|
|
477
|
+
if (prevContent !== newContent) {
|
|
478
|
+
yield file_utils_1.writeFileContent(context, resourcePath, newContent, {
|
|
479
|
+
force: true,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
@@ -118,6 +118,8 @@ export interface ProjectConfig {
|
|
|
118
118
|
version: string;
|
|
119
119
|
/** File location for the project-wide css styles. Relative to srcDir */
|
|
120
120
|
cssFilePath: string;
|
|
121
|
+
/** File location for the project-wide global contexts. Relative to srcDir */
|
|
122
|
+
globalContextsFilePath: string;
|
|
121
123
|
jsBundleThemes?: JsBundleThemeConfig[];
|
|
122
124
|
codeComponents?: CodeComponentConfig[];
|
|
123
125
|
/** Metadata for each synced component in this project. */
|
|
@@ -213,7 +215,7 @@ export interface GlobalVariantGroupConfig {
|
|
|
213
215
|
contextFilePath: string;
|
|
214
216
|
}
|
|
215
217
|
export interface FileLock {
|
|
216
|
-
type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant";
|
|
218
|
+
type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant" | "globalContexts";
|
|
217
219
|
checksum: string;
|
|
218
220
|
assetId: string;
|
|
219
221
|
}
|
|
@@ -225,6 +227,7 @@ export interface ProjectLock {
|
|
|
225
227
|
};
|
|
226
228
|
lang: "ts" | "js";
|
|
227
229
|
fileLocks: FileLock[];
|
|
230
|
+
codegenVersion?: string;
|
|
228
231
|
}
|
|
229
232
|
export interface PlasmicLock {
|
|
230
233
|
projects: ProjectLock[];
|
|
@@ -40,6 +40,7 @@ function createProjectConfig(base) {
|
|
|
40
40
|
icons: [],
|
|
41
41
|
images: [],
|
|
42
42
|
indirect: base.indirect,
|
|
43
|
+
globalContextsFilePath: "",
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
exports.createProjectConfig = createProjectConfig;
|
|
@@ -150,6 +151,7 @@ function getOrAddProjectConfig(context, projectId, base // if one doesn't exist,
|
|
|
150
151
|
images: [],
|
|
151
152
|
jsBundleThemes: [],
|
|
152
153
|
indirect: false,
|
|
154
|
+
globalContextsFilePath: "",
|
|
153
155
|
};
|
|
154
156
|
context.config.projects.push(project);
|
|
155
157
|
}
|
|
@@ -45,11 +45,6 @@ export declare function findSrcDirPath(absoluteSrcDir: string, expectedPath: str
|
|
|
45
45
|
export declare function findFile(dir: string, pred: (name: string) => boolean, opts: {
|
|
46
46
|
traverseParents?: boolean;
|
|
47
47
|
}): string | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
50
|
-
* movement on disk.
|
|
51
|
-
*/
|
|
52
|
-
export declare function fixAllFilePaths(context: PlasmicContext, baseDir: string): Promise<void>;
|
|
53
48
|
/**
|
|
54
49
|
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
55
50
|
* directory (i.e., the directory containing plasmic.json).
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.existsBuffered = exports.deleteFileBuffered = exports.renameFileBuffered = exports.readFileText = exports.writeFileText = exports.withBufferedFs = exports.assertAllPathsInRootDir = exports.
|
|
15
|
+
exports.existsBuffered = exports.deleteFileBuffered = exports.renameFileBuffered = exports.readFileText = exports.writeFileText = exports.withBufferedFs = exports.assertAllPathsInRootDir = exports.findFile = exports.findSrcDirPath = exports.buildBaseNameToFiles = exports.renameFile = exports.makeFilePath = exports.fileExists = exports.deleteFile = exports.readFileContent = exports.writeFileContent = exports.defaultPagePath = exports.defaultPublicResourcePath = exports.defaultResourcePath = exports.writeFileContentRaw = exports.stripExtension = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const glob_1 = __importDefault(require("glob"));
|
|
18
18
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -188,6 +188,7 @@ function getAllPaths(context) {
|
|
|
188
188
|
};
|
|
189
189
|
const pushProject = (proj) => {
|
|
190
190
|
pushPath(proj, "cssFilePath");
|
|
191
|
+
pushPath(proj, "globalContextsFilePath");
|
|
191
192
|
for (const component of proj.components) {
|
|
192
193
|
pushComponent(component);
|
|
193
194
|
}
|
|
@@ -218,37 +219,6 @@ function getAllPaths(context) {
|
|
|
218
219
|
}
|
|
219
220
|
return pairs;
|
|
220
221
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
223
|
-
* movement on disk.
|
|
224
|
-
*/
|
|
225
|
-
function fixAllFilePaths(context, baseDir) {
|
|
226
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
const baseNameToFiles = buildBaseNameToFiles(context);
|
|
228
|
-
let changed = false;
|
|
229
|
-
const paths = getAllPaths(context);
|
|
230
|
-
for (const { bundle, key } of paths) {
|
|
231
|
-
const known = bundle[key];
|
|
232
|
-
// Check null and undefined
|
|
233
|
-
if (known == null) {
|
|
234
|
-
throw new error_1.HandledError(`"${key} is required, but missing in ${config_utils_1.CONFIG_FILE_NAME}. Please restore the file or delete from ${config_utils_1.CONFIG_FILE_NAME} and run plasmic sync: ${bundle}"`);
|
|
235
|
-
}
|
|
236
|
-
// Check falsey values (e.g. "")
|
|
237
|
-
if (!known) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
const found = findSrcDirPath(context.absoluteSrcDir, known, baseNameToFiles);
|
|
241
|
-
if (known !== found) {
|
|
242
|
-
bundle[key] = found;
|
|
243
|
-
changed = true;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (changed) {
|
|
247
|
-
yield config_utils_1.updateConfig(context, context.config, baseDir);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
exports.fixAllFilePaths = fixAllFilePaths;
|
|
252
222
|
/**
|
|
253
223
|
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
254
224
|
* directory (i.e., the directory containing plasmic.json).
|
|
@@ -81,10 +81,7 @@ function removeMissingFilesFromLock(context, config, lock) {
|
|
|
81
81
|
image.id,
|
|
82
82
|
image,
|
|
83
83
|
]));
|
|
84
|
-
const knownIcons = Object.fromEntries(knownProjects[project.projectId].icons.map((icons) => [
|
|
85
|
-
icons.id,
|
|
86
|
-
icons,
|
|
87
|
-
]));
|
|
84
|
+
const knownIcons = Object.fromEntries(knownProjects[project.projectId].icons.map((icons) => [icons.id, icons]));
|
|
88
85
|
project.fileLocks = project.fileLocks.filter((lock) => {
|
|
89
86
|
switch (lock.type) {
|
|
90
87
|
default:
|
|
@@ -100,6 +97,8 @@ function removeMissingFilesFromLock(context, config, lock) {
|
|
|
100
97
|
return knownImages[lock.assetId];
|
|
101
98
|
case "icon":
|
|
102
99
|
return knownIcons[lock.assetId];
|
|
100
|
+
case "globalContexts":
|
|
101
|
+
return knownProjects[project.projectId].globalContextsFilePath;
|
|
103
102
|
}
|
|
104
103
|
});
|
|
105
104
|
return project;
|
|
@@ -169,6 +168,11 @@ function resolveMissingFilesInConfig(context, config) {
|
|
|
169
168
|
for (const project of config.projects) {
|
|
170
169
|
project.cssFilePath =
|
|
171
170
|
(yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) || "";
|
|
171
|
+
if (!project.globalContextsFilePath) {
|
|
172
|
+
project.globalContextsFilePath = "";
|
|
173
|
+
}
|
|
174
|
+
project.globalContextsFilePath =
|
|
175
|
+
(yield attemptToRestoreFilePath(context, project.globalContextsFilePath, baseNameToFiles)) || "";
|
|
172
176
|
project.images = yield filterFiles(project.images, "filePath");
|
|
173
177
|
project.icons = yield filterFiles(project.icons, "moduleFilePath");
|
|
174
178
|
project.jsBundleThemes = yield filterFiles(project.jsBundleThemes || [], "themeFilePath");
|
|
@@ -75,6 +75,15 @@ function checkProjectMeta(meta, root, context, opts) {
|
|
|
75
75
|
const projectName = meta.projectName;
|
|
76
76
|
const newVersion = meta.version;
|
|
77
77
|
const indirect = meta.indirect;
|
|
78
|
+
// If the codegen version on-disk is invalid, we will sync again the project.
|
|
79
|
+
const checkCodegenVersion = () => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const projectLock = context.lock.projects.find((p) => p.projectId === projectId);
|
|
81
|
+
if (!!(projectLock === null || projectLock === void 0 ? void 0 : projectLock.codegenVersion) && semver.gte(projectLock.codegenVersion, yield context.api.latestCodegenVersion())) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
const isOnDiskCodeInvalid = yield checkCodegenVersion();
|
|
78
87
|
// Checks newVersion against plasmic.lock
|
|
79
88
|
const checkVersionLock = () => __awaiter(this, void 0, void 0, function* () {
|
|
80
89
|
const projectLock = context.lock.projects.find((p) => p.projectId === projectId);
|
|
@@ -88,7 +97,9 @@ function checkProjectMeta(meta, root, context, opts) {
|
|
|
88
97
|
meta !== root) {
|
|
89
98
|
// If this is a dependency (not root), and we're dealing with latest dep version
|
|
90
99
|
// just skip, it's confusing
|
|
91
|
-
|
|
100
|
+
if (!isOnDiskCodeInvalid) {
|
|
101
|
+
deps_1.logger.warn(`'${root.projectName}' depends on ${projectName}@${newVersion}. To update this project, explicitly specify this project for sync. Skipping...`);
|
|
102
|
+
}
|
|
92
103
|
return false;
|
|
93
104
|
}
|
|
94
105
|
if (semver.isLatest(newVersion)) {
|
|
@@ -106,7 +117,9 @@ function checkProjectMeta(meta, root, context, opts) {
|
|
|
106
117
|
return true;
|
|
107
118
|
}
|
|
108
119
|
else {
|
|
109
|
-
|
|
120
|
+
if (!isOnDiskCodeInvalid) {
|
|
121
|
+
deps_1.logger.info(`Project '${projectName}'@${newVersion} is already up to date; skipping. (To force an update, run again with "--force")`);
|
|
122
|
+
}
|
|
110
123
|
return false;
|
|
111
124
|
}
|
|
112
125
|
}
|
|
@@ -164,9 +177,24 @@ function checkProjectMeta(meta, root, context, opts) {
|
|
|
164
177
|
// we should always sync it, even if nothing has changed
|
|
165
178
|
return true;
|
|
166
179
|
}
|
|
167
|
-
|
|
180
|
+
const checkedVersion = (yield checkVersionLock()) &&
|
|
168
181
|
(yield checkVersionRange()) &&
|
|
169
|
-
(yield checkIndirect())
|
|
182
|
+
(yield checkIndirect());
|
|
183
|
+
if (!checkedVersion && isOnDiskCodeInvalid) {
|
|
184
|
+
// sync, but try to keep the current version on disk
|
|
185
|
+
const projectLock = context.lock.projects.find((p) => p.projectId === projectId);
|
|
186
|
+
const versionOnDisk = projectLock === null || projectLock === void 0 ? void 0 : projectLock.version;
|
|
187
|
+
deps_1.logger.warn(`Project '${projectName}' was synced by an incompatible version of Plasmic Codegen. Syncing again on the same version ${projectName}@${versionOnDisk}`);
|
|
188
|
+
meta.version = versionOnDisk !== null && versionOnDisk !== void 0 ? versionOnDisk : meta.version;
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
else if (checkedVersion) {
|
|
192
|
+
// sync and upgrade the version
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
170
198
|
});
|
|
171
199
|
}
|
|
172
200
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.171",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-typescript": "^7.12.1",
|
|
23
|
-
"@plasmicapp/react-web": "^0.2.
|
|
23
|
+
"@plasmicapp/react-web": "^0.2.91",
|
|
24
24
|
"@types/findup-sync": "^2.0.2",
|
|
25
25
|
"@types/glob": "^7.1.3",
|
|
26
26
|
"@types/inquirer": "^6.5.0",
|
package/src/__mocks__/api.ts
CHANGED
|
@@ -339,6 +339,7 @@ class PlasmicApi {
|
|
|
339
339
|
iconChecksums: [],
|
|
340
340
|
globalVariantChecksums: [],
|
|
341
341
|
projectCssChecksum: "",
|
|
342
|
+
globalContextsChecksum: "",
|
|
342
343
|
} as ChecksumBundle,
|
|
343
344
|
usedNpmPackages: [],
|
|
344
345
|
externalCssImports: [],
|
|
@@ -372,6 +373,10 @@ class PlasmicApi {
|
|
|
372
373
|
throw new Error("Unimplemented");
|
|
373
374
|
}
|
|
374
375
|
|
|
376
|
+
async latestCodegenVersion(): Promise<string> {
|
|
377
|
+
return "0.0.1";
|
|
378
|
+
}
|
|
379
|
+
|
|
375
380
|
async requiredPackages(): Promise<RequiredPackages> {
|
|
376
381
|
return {
|
|
377
382
|
"@plasmicapp/loader": "0.0.1",
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { CommonArgs } from "..";
|
|
2
2
|
import { fixAllImportStatements } from "../utils/code-utils";
|
|
3
|
-
import {
|
|
3
|
+
import { updateConfig } from "../utils/config-utils";
|
|
4
4
|
import { getContext } from "../utils/get-context";
|
|
5
5
|
|
|
6
6
|
export interface FixImportsArgs extends CommonArgs {}
|
|
7
7
|
export async function fixImports(opts: FixImportsArgs) {
|
|
8
8
|
if (!opts.baseDir) opts.baseDir = process.cwd();
|
|
9
9
|
const context = await getContext(opts, { enableSkipAuth: true });
|
|
10
|
-
|
|
11
|
-
await fixAllFilePaths(context, opts.baseDir);
|
|
10
|
+
await updateConfig(context, context.config, opts.baseDir);
|
|
12
11
|
await fixAllImportStatements(context, opts.baseDir);
|
|
13
12
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ChecksumBundle, ProjectMetaBundle } from "../api";
|
|
2
|
+
import { logger } from "../deps";
|
|
3
|
+
import { formatScript, tsxToJsx } from "../utils/code-utils";
|
|
4
|
+
import L from "lodash";
|
|
5
|
+
import {
|
|
6
|
+
PlasmicContext,
|
|
7
|
+
ProjectConfig,
|
|
8
|
+
ProjectLock,
|
|
9
|
+
} from "../utils/config-utils";
|
|
10
|
+
import {
|
|
11
|
+
defaultResourcePath,
|
|
12
|
+
deleteFile,
|
|
13
|
+
fileExists,
|
|
14
|
+
writeFileContent,
|
|
15
|
+
} from "../utils/file-utils";
|
|
16
|
+
|
|
17
|
+
const COMPONENT_NAME = "PlasmicGlobalContextsProvider";
|
|
18
|
+
|
|
19
|
+
export async function syncGlobalContexts(
|
|
20
|
+
context: PlasmicContext,
|
|
21
|
+
projectMeta: ProjectMetaBundle,
|
|
22
|
+
projectConfig: ProjectConfig,
|
|
23
|
+
projectLock: ProjectLock,
|
|
24
|
+
checksums: ChecksumBundle,
|
|
25
|
+
baseDir: string
|
|
26
|
+
) {
|
|
27
|
+
const resourcePath = getGlobalContextsResourcePath(context, projectConfig);
|
|
28
|
+
if (checksums.globalContextsChecksum && projectMeta.globalContextBundle) {
|
|
29
|
+
if (context.cliArgs.quiet !== true) {
|
|
30
|
+
logger.info(
|
|
31
|
+
`Syncing component: ${COMPONENT_NAME}@${projectLock.version}\t['${projectConfig.projectName}' ${projectConfig.projectId} ${projectConfig.version}]`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (context.config.code.lang === "js") {
|
|
35
|
+
projectMeta.globalContextBundle.contextModule = formatScript(
|
|
36
|
+
tsxToJsx(projectMeta.globalContextBundle.contextModule),
|
|
37
|
+
baseDir
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
writeFileContent(
|
|
41
|
+
context,
|
|
42
|
+
resourcePath,
|
|
43
|
+
projectMeta.globalContextBundle.contextModule,
|
|
44
|
+
{ force: false }
|
|
45
|
+
);
|
|
46
|
+
projectConfig.globalContextsFilePath = resourcePath;
|
|
47
|
+
const fl = projectLock.fileLocks.find(
|
|
48
|
+
(fl) =>
|
|
49
|
+
fl.assetId === projectConfig.projectId && fl.type === "globalContexts"
|
|
50
|
+
);
|
|
51
|
+
if (fl) {
|
|
52
|
+
fl.checksum = checksums.globalContextsChecksum;
|
|
53
|
+
} else {
|
|
54
|
+
projectLock.fileLocks.push({
|
|
55
|
+
assetId: projectConfig.projectId,
|
|
56
|
+
checksum: checksums.globalContextsChecksum,
|
|
57
|
+
type: "globalContexts",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} else if (
|
|
61
|
+
!checksums.globalContextsChecksum &&
|
|
62
|
+
!projectMeta.globalContextBundle
|
|
63
|
+
) {
|
|
64
|
+
if (fileExists(context, resourcePath)) {
|
|
65
|
+
deleteFile(context, resourcePath);
|
|
66
|
+
}
|
|
67
|
+
projectConfig.globalContextsFilePath = "";
|
|
68
|
+
L.remove(
|
|
69
|
+
projectLock.fileLocks,
|
|
70
|
+
(fl) =>
|
|
71
|
+
fl.assetId === projectConfig.projectId && fl.type === "globalContexts"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getGlobalContextsResourcePath(
|
|
77
|
+
context: PlasmicContext,
|
|
78
|
+
projectConfig: ProjectConfig
|
|
79
|
+
) {
|
|
80
|
+
return projectConfig.globalContextsFilePath !== ""
|
|
81
|
+
? projectConfig.globalContextsFilePath
|
|
82
|
+
: defaultResourcePath(
|
|
83
|
+
context,
|
|
84
|
+
projectConfig,
|
|
85
|
+
`${COMPONENT_NAME}.${context.config.code.lang === "ts" ? "tsx" : "jsx"}`
|
|
86
|
+
);
|
|
87
|
+
}
|
package/src/actions/sync.ts
CHANGED
|
@@ -64,6 +64,7 @@ import { syncGlobalVariants } from "./sync-global-variants";
|
|
|
64
64
|
import { syncProjectIconAssets } from "./sync-icons";
|
|
65
65
|
import { syncProjectImageAssets } from "./sync-images";
|
|
66
66
|
import { upsertStyleTokens } from "./sync-styles";
|
|
67
|
+
import { syncGlobalContexts } from "./sync-global-contexts";
|
|
67
68
|
|
|
68
69
|
export interface SyncArgs extends CommonArgs {
|
|
69
70
|
projects: readonly string[];
|
|
@@ -416,6 +417,16 @@ export async function sync(
|
|
|
416
417
|
writeLoaderConfig(opts, config);
|
|
417
418
|
}
|
|
418
419
|
|
|
420
|
+
const codegenVersion = await context.api.latestCodegenVersion();
|
|
421
|
+
context.lock.projects.forEach((p) => {
|
|
422
|
+
if (
|
|
423
|
+
projectsToSync.some(
|
|
424
|
+
(syncedProject) => syncedProject.projectId === p.projectId
|
|
425
|
+
)
|
|
426
|
+
) {
|
|
427
|
+
p.codegenVersion = codegenVersion;
|
|
428
|
+
}
|
|
429
|
+
});
|
|
419
430
|
// Write the new ComponentConfigs to disk
|
|
420
431
|
await updateConfig(context, context.config, baseDir);
|
|
421
432
|
});
|
|
@@ -781,6 +792,15 @@ async function syncProjectConfig(
|
|
|
781
792
|
delete projectConfig.jsBundleThemes;
|
|
782
793
|
}
|
|
783
794
|
|
|
795
|
+
await syncGlobalContexts(
|
|
796
|
+
context,
|
|
797
|
+
projectBundle,
|
|
798
|
+
projectConfig,
|
|
799
|
+
projectLock,
|
|
800
|
+
checksums,
|
|
801
|
+
baseDir
|
|
802
|
+
);
|
|
803
|
+
|
|
784
804
|
// Write out components
|
|
785
805
|
await syncProjectComponents(
|
|
786
806
|
context,
|
package/src/api.ts
CHANGED
|
@@ -39,6 +39,11 @@ export interface GlobalVariantBundle {
|
|
|
39
39
|
contextFileName: string;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export interface GlobalContextBundle {
|
|
43
|
+
id: string;
|
|
44
|
+
contextModule: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
export interface JsBundleTheme {
|
|
43
48
|
themeFileName: string;
|
|
44
49
|
themeModule: string;
|
|
@@ -51,6 +56,7 @@ export interface ProjectMetaBundle {
|
|
|
51
56
|
cssFileName: string;
|
|
52
57
|
cssRules: string;
|
|
53
58
|
jsBundleThemes?: JsBundleTheme[];
|
|
59
|
+
globalContextBundle?: GlobalContextBundle;
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
export interface IconBundle {
|
|
@@ -142,6 +148,8 @@ export interface ChecksumBundle {
|
|
|
142
148
|
globalVariantChecksums: Array<[string, string]>;
|
|
143
149
|
// Checksum of projectCss file
|
|
144
150
|
projectCssChecksum: string;
|
|
151
|
+
// Checksum of project global contexts
|
|
152
|
+
globalContextsChecksum: string;
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
export interface CodeComponentMeta {
|
|
@@ -161,6 +169,7 @@ export interface ProjectIdAndToken {
|
|
|
161
169
|
}
|
|
162
170
|
|
|
163
171
|
export class PlasmicApi {
|
|
172
|
+
private codegenVersion?: string;
|
|
164
173
|
constructor(private auth: AuthConfig) {}
|
|
165
174
|
|
|
166
175
|
async genStyleConfig(styleOpts?: StyleConfig): Promise<StyleConfigResponse> {
|
|
@@ -213,6 +222,16 @@ export class PlasmicApi {
|
|
|
213
222
|
return { ...resp.data } as RequiredPackages;
|
|
214
223
|
}
|
|
215
224
|
|
|
225
|
+
async latestCodegenVersion(): Promise<string> {
|
|
226
|
+
if (!this.codegenVersion) {
|
|
227
|
+
const resp = await this.post(
|
|
228
|
+
`${this.codegenHost}/api/v1/code/latest-codegen-version`
|
|
229
|
+
);
|
|
230
|
+
this.codegenVersion = resp.data as string;
|
|
231
|
+
}
|
|
232
|
+
return this.codegenVersion;
|
|
233
|
+
}
|
|
234
|
+
|
|
216
235
|
/**
|
|
217
236
|
* Code-gen endpoint.
|
|
218
237
|
* This will fetch components at an exact specified version.
|
package/src/utils/checksum.ts
CHANGED
|
@@ -25,6 +25,7 @@ export function getChecksums(
|
|
|
25
25
|
cssRulesChecksums: [],
|
|
26
26
|
globalVariantChecksums: [],
|
|
27
27
|
projectCssChecksum: "",
|
|
28
|
+
globalContextsChecksum: "",
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -95,6 +96,16 @@ export function getChecksums(
|
|
|
95
96
|
const projectCssChecksum =
|
|
96
97
|
projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
97
98
|
|
|
99
|
+
const globalContextsChecksums = fileLocks.filter(
|
|
100
|
+
(fileLock) =>
|
|
101
|
+
fileLock.type === "globalContexts" && fileLock.assetId === projectId
|
|
102
|
+
);
|
|
103
|
+
assert(globalContextsChecksums.length < 2);
|
|
104
|
+
const globalContextsChecksum =
|
|
105
|
+
globalContextsChecksums.length > 0
|
|
106
|
+
? globalContextsChecksums[0].checksum
|
|
107
|
+
: "";
|
|
108
|
+
|
|
98
109
|
return {
|
|
99
110
|
imageChecksums,
|
|
100
111
|
iconChecksums,
|
|
@@ -102,5 +113,6 @@ export function getChecksums(
|
|
|
102
113
|
cssRulesChecksums,
|
|
103
114
|
globalVariantChecksums,
|
|
104
115
|
projectCssChecksum,
|
|
116
|
+
globalContextsChecksum,
|
|
105
117
|
};
|
|
106
118
|
}
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as Prettier from "prettier";
|
|
|
8
8
|
import { Options, resolveConfig } from "prettier";
|
|
9
9
|
import * as ts from "typescript";
|
|
10
10
|
import path from "upath";
|
|
11
|
+
import { getGlobalContextsResourcePath } from "../actions/sync-global-contexts";
|
|
11
12
|
import {
|
|
12
13
|
fixComponentCssReferences,
|
|
13
14
|
fixComponentImagesReferences,
|
|
@@ -17,6 +18,7 @@ import { HandledError } from "../utils/error";
|
|
|
17
18
|
import {
|
|
18
19
|
CodeComponentConfig,
|
|
19
20
|
ComponentConfig,
|
|
21
|
+
CONFIG_FILE_NAME,
|
|
20
22
|
GlobalVariantGroupConfig,
|
|
21
23
|
IconConfig,
|
|
22
24
|
ImageConfig,
|
|
@@ -473,6 +475,7 @@ export async function fixAllImportStatements(
|
|
|
473
475
|
}
|
|
474
476
|
}
|
|
475
477
|
}
|
|
478
|
+
fixGlobalContextImportStatements(context, fixImportContext, baseDir);
|
|
476
479
|
}
|
|
477
480
|
|
|
478
481
|
async function fixComponentImportStatements(
|
|
@@ -484,6 +487,7 @@ async function fixComponentImportStatements(
|
|
|
484
487
|
) {
|
|
485
488
|
// If ComponentConfig.importPath is still a local file, we best-effort also fix up the import statements there.
|
|
486
489
|
if (
|
|
490
|
+
compConfig.type !== "mapped" &&
|
|
487
491
|
isLocalModulePath(compConfig.importSpec.modulePath) &&
|
|
488
492
|
fixSkeletonModule
|
|
489
493
|
) {
|
|
@@ -654,3 +658,42 @@ export const formatScript = (code: string, baseDir: string) => {
|
|
|
654
658
|
useTabs: false,
|
|
655
659
|
});
|
|
656
660
|
};
|
|
661
|
+
|
|
662
|
+
async function fixGlobalContextImportStatements(
|
|
663
|
+
context: PlasmicContext,
|
|
664
|
+
fixImportContext: FixImportContext,
|
|
665
|
+
baseDir: string
|
|
666
|
+
) {
|
|
667
|
+
for (const project of context.config.projects) {
|
|
668
|
+
if (!project.globalContextsFilePath) continue;
|
|
669
|
+
const resourcePath = getGlobalContextsResourcePath(context, project);
|
|
670
|
+
|
|
671
|
+
let prevContent: string;
|
|
672
|
+
try {
|
|
673
|
+
prevContent = readFileText(
|
|
674
|
+
makeFilePath(context, resourcePath)
|
|
675
|
+
).toString();
|
|
676
|
+
} catch (e) {
|
|
677
|
+
logger.warn(
|
|
678
|
+
`${resourcePath} is missing. If you deleted this component, remember to remove the component from ${CONFIG_FILE_NAME}`
|
|
679
|
+
);
|
|
680
|
+
throw e;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const newContent = replaceImports(
|
|
684
|
+
context,
|
|
685
|
+
prevContent,
|
|
686
|
+
resourcePath,
|
|
687
|
+
fixImportContext,
|
|
688
|
+
false,
|
|
689
|
+
baseDir,
|
|
690
|
+
true
|
|
691
|
+
);
|
|
692
|
+
|
|
693
|
+
if (prevContent !== newContent) {
|
|
694
|
+
await writeFileContent(context, resourcePath, newContent, {
|
|
695
|
+
force: true,
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
@@ -159,6 +159,8 @@ export interface ProjectConfig {
|
|
|
159
159
|
version: string;
|
|
160
160
|
/** File location for the project-wide css styles. Relative to srcDir */
|
|
161
161
|
cssFilePath: string;
|
|
162
|
+
/** File location for the project-wide global contexts. Relative to srcDir */
|
|
163
|
+
globalContextsFilePath: string;
|
|
162
164
|
|
|
163
165
|
// Code-component-related fields can be treated as optional not to be shown
|
|
164
166
|
// to the users nor appear to be missing in the documentation.
|
|
@@ -197,6 +199,7 @@ export function createProjectConfig(base: {
|
|
|
197
199
|
icons: [],
|
|
198
200
|
images: [],
|
|
199
201
|
indirect: base.indirect,
|
|
202
|
+
globalContextsFilePath: "",
|
|
200
203
|
};
|
|
201
204
|
}
|
|
202
205
|
|
|
@@ -299,7 +302,8 @@ export interface FileLock {
|
|
|
299
302
|
| "icon"
|
|
300
303
|
| "image"
|
|
301
304
|
| "projectCss"
|
|
302
|
-
| "globalVariant"
|
|
305
|
+
| "globalVariant"
|
|
306
|
+
| "globalContexts";
|
|
303
307
|
// The checksum value for the file
|
|
304
308
|
checksum: string;
|
|
305
309
|
// The component id, or the image asset id
|
|
@@ -318,6 +322,8 @@ export interface ProjectLock {
|
|
|
318
322
|
lang: "ts" | "js";
|
|
319
323
|
// One for each file whose checksum is computed
|
|
320
324
|
fileLocks: FileLock[];
|
|
325
|
+
// The version of Codegen when this project was written
|
|
326
|
+
codegenVersion?: string;
|
|
321
327
|
}
|
|
322
328
|
|
|
323
329
|
export interface PlasmicLock {
|
|
@@ -528,6 +534,7 @@ export function getOrAddProjectConfig(
|
|
|
528
534
|
images: [],
|
|
529
535
|
jsBundleThemes: [],
|
|
530
536
|
indirect: false,
|
|
537
|
+
globalContextsFilePath: "",
|
|
531
538
|
};
|
|
532
539
|
context.config.projects.push(project);
|
|
533
540
|
}
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
CONFIG_FILE_NAME,
|
|
12
12
|
PlasmicContext,
|
|
13
13
|
ProjectConfig,
|
|
14
|
-
updateConfig,
|
|
15
14
|
} from "./config-utils";
|
|
16
15
|
import { ensureString } from "./lang-utils";
|
|
17
16
|
import { confirmWithUser } from "./user-utils";
|
|
@@ -242,6 +241,7 @@ function getAllPaths(context: PlasmicContext): BundleKeyPair[] {
|
|
|
242
241
|
|
|
243
242
|
const pushProject = (proj: ProjectConfig) => {
|
|
244
243
|
pushPath(proj, "cssFilePath");
|
|
244
|
+
pushPath(proj, "globalContextsFilePath");
|
|
245
245
|
for (const component of proj.components) {
|
|
246
246
|
pushComponent(component);
|
|
247
247
|
}
|
|
@@ -278,43 +278,6 @@ function getAllPaths(context: PlasmicContext): BundleKeyPair[] {
|
|
|
278
278
|
return pairs;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
/**
|
|
282
|
-
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
283
|
-
* movement on disk.
|
|
284
|
-
*/
|
|
285
|
-
export async function fixAllFilePaths(context: PlasmicContext, baseDir: string) {
|
|
286
|
-
const baseNameToFiles = buildBaseNameToFiles(context);
|
|
287
|
-
let changed = false;
|
|
288
|
-
|
|
289
|
-
const paths = getAllPaths(context);
|
|
290
|
-
for (const { bundle, key } of paths) {
|
|
291
|
-
const known = bundle[key];
|
|
292
|
-
// Check null and undefined
|
|
293
|
-
if (known == null) {
|
|
294
|
-
throw new HandledError(
|
|
295
|
-
`"${key} is required, but missing in ${CONFIG_FILE_NAME}. Please restore the file or delete from ${CONFIG_FILE_NAME} and run plasmic sync: ${bundle}"`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
// Check falsey values (e.g. "")
|
|
299
|
-
if (!known) {
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
const found = findSrcDirPath(
|
|
303
|
-
context.absoluteSrcDir,
|
|
304
|
-
known,
|
|
305
|
-
baseNameToFiles
|
|
306
|
-
);
|
|
307
|
-
if (known !== found) {
|
|
308
|
-
bundle[key] = found;
|
|
309
|
-
changed = true;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (changed) {
|
|
314
|
-
await updateConfig(context, context.config, baseDir);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
281
|
/**
|
|
319
282
|
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
320
283
|
* directory (i.e., the directory containing plasmic.json).
|
package/src/utils/get-context.ts
CHANGED
|
@@ -79,10 +79,7 @@ function removeMissingFilesFromLock(
|
|
|
79
79
|
])
|
|
80
80
|
);
|
|
81
81
|
const knownIcons = Object.fromEntries(
|
|
82
|
-
knownProjects[project.projectId].icons.map((icons) => [
|
|
83
|
-
icons.id,
|
|
84
|
-
icons,
|
|
85
|
-
])
|
|
82
|
+
knownProjects[project.projectId].icons.map((icons) => [icons.id, icons])
|
|
86
83
|
);
|
|
87
84
|
|
|
88
85
|
project.fileLocks = project.fileLocks.filter((lock) => {
|
|
@@ -100,6 +97,8 @@ function removeMissingFilesFromLock(
|
|
|
100
97
|
return knownImages[lock.assetId];
|
|
101
98
|
case "icon":
|
|
102
99
|
return knownIcons[lock.assetId];
|
|
100
|
+
case "globalContexts":
|
|
101
|
+
return knownProjects[project.projectId].globalContextsFilePath;
|
|
103
102
|
}
|
|
104
103
|
});
|
|
105
104
|
|
|
@@ -209,6 +208,16 @@ async function resolveMissingFilesInConfig(
|
|
|
209
208
|
baseNameToFiles
|
|
210
209
|
)) || "";
|
|
211
210
|
|
|
211
|
+
if (!project.globalContextsFilePath) {
|
|
212
|
+
project.globalContextsFilePath = "";
|
|
213
|
+
}
|
|
214
|
+
project.globalContextsFilePath =
|
|
215
|
+
(await attemptToRestoreFilePath(
|
|
216
|
+
context,
|
|
217
|
+
project.globalContextsFilePath,
|
|
218
|
+
baseNameToFiles
|
|
219
|
+
)) || "";
|
|
220
|
+
|
|
212
221
|
project.images = await filterFiles(project.images, "filePath");
|
|
213
222
|
project.icons = await filterFiles(project.icons, "moduleFilePath");
|
|
214
223
|
project.jsBundleThemes = await filterFiles(
|
|
@@ -68,6 +68,21 @@ async function checkProjectMeta(
|
|
|
68
68
|
const newVersion = meta.version;
|
|
69
69
|
const indirect = meta.indirect;
|
|
70
70
|
|
|
71
|
+
// If the codegen version on-disk is invalid, we will sync again the project.
|
|
72
|
+
const checkCodegenVersion = async (): Promise<boolean> => {
|
|
73
|
+
const projectLock = context.lock.projects.find(
|
|
74
|
+
(p) => p.projectId === projectId
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (!!projectLock?.codegenVersion && semver.gte(projectLock.codegenVersion, await context.api.latestCodegenVersion())) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const isOnDiskCodeInvalid = await checkCodegenVersion();
|
|
85
|
+
|
|
71
86
|
// Checks newVersion against plasmic.lock
|
|
72
87
|
const checkVersionLock = async (): Promise<boolean> => {
|
|
73
88
|
const projectLock = context.lock.projects.find(
|
|
@@ -87,9 +102,11 @@ async function checkProjectMeta(
|
|
|
87
102
|
) {
|
|
88
103
|
// If this is a dependency (not root), and we're dealing with latest dep version
|
|
89
104
|
// just skip, it's confusing
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
if (!isOnDiskCodeInvalid) {
|
|
106
|
+
logger.warn(
|
|
107
|
+
`'${root.projectName}' depends on ${projectName}@${newVersion}. To update this project, explicitly specify this project for sync. Skipping...`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
93
110
|
return false;
|
|
94
111
|
}
|
|
95
112
|
|
|
@@ -111,9 +128,11 @@ async function checkProjectMeta(
|
|
|
111
128
|
);
|
|
112
129
|
return true;
|
|
113
130
|
} else {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
if (!isOnDiskCodeInvalid) {
|
|
132
|
+
logger.info(
|
|
133
|
+
`Project '${projectName}'@${newVersion} is already up to date; skipping. (To force an update, run again with "--force")`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
117
136
|
return false;
|
|
118
137
|
}
|
|
119
138
|
}
|
|
@@ -211,12 +230,29 @@ async function checkProjectMeta(
|
|
|
211
230
|
// we should always sync it, even if nothing has changed
|
|
212
231
|
return true;
|
|
213
232
|
}
|
|
214
|
-
|
|
215
|
-
return (
|
|
233
|
+
const checkedVersion =
|
|
216
234
|
(await checkVersionLock()) &&
|
|
217
235
|
(await checkVersionRange()) &&
|
|
218
|
-
(await checkIndirect())
|
|
219
|
-
|
|
236
|
+
(await checkIndirect());
|
|
237
|
+
|
|
238
|
+
if(!checkedVersion && isOnDiskCodeInvalid) {
|
|
239
|
+
// sync, but try to keep the current version on disk
|
|
240
|
+
const projectLock = context.lock.projects.find(
|
|
241
|
+
(p) => p.projectId === projectId
|
|
242
|
+
);
|
|
243
|
+
const versionOnDisk = projectLock?.version;
|
|
244
|
+
logger.warn(
|
|
245
|
+
`Project '${projectName}' was synced by an incompatible version of Plasmic Codegen. Syncing again on the same version ${projectName}@${versionOnDisk}`
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
meta.version = versionOnDisk ?? meta.version;
|
|
249
|
+
return true;
|
|
250
|
+
} else if (checkedVersion) {
|
|
251
|
+
// sync and upgrade the version
|
|
252
|
+
return true;
|
|
253
|
+
} else {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
220
256
|
}
|
|
221
257
|
|
|
222
258
|
/**
|