@plasmicapp/cli 0.1.167 → 0.1.168
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/sync.js +6 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.js +9 -0
- package/dist/index.js +0 -0
- package/dist/utils/config-utils.d.ts +1 -0
- package/dist/utils/resolve-utils.js +32 -4
- package/package.json +1 -1
- package/src/__mocks__/api.ts +4 -0
- package/src/actions/sync.ts +6 -0
- package/src/api.ts +11 -0
- package/src/utils/config-utils.ts +2 -0
- package/src/utils/resolve-utils.ts +46 -10
package/dist/__mocks__/api.js
CHANGED
|
@@ -276,6 +276,12 @@ class PlasmicApi {
|
|
|
276
276
|
throw new Error("Unimplemented");
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
|
+
latestCodegenVersion() {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
return "0.0.1";
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
;
|
|
279
285
|
requiredPackages() {
|
|
280
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
287
|
return {
|
package/dist/actions/sync.js
CHANGED
|
@@ -257,6 +257,12 @@ function sync(opts, metadataDefaults) {
|
|
|
257
257
|
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
258
|
writeLoaderConfig(opts, config);
|
|
259
259
|
}
|
|
260
|
+
const codegenVersion = yield context.api.latestCodegenVersion();
|
|
261
|
+
context.lock.projects.forEach(p => {
|
|
262
|
+
if (projectsToSync.some(syncedProject => syncedProject.projectId === p.projectId)) {
|
|
263
|
+
p.codegenVersion = codegenVersion;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
260
266
|
// Write the new ComponentConfigs to disk
|
|
261
267
|
yield config_utils_1.updateConfig(context, context.config, baseDir);
|
|
262
268
|
}));
|
package/dist/api.d.ts
CHANGED
|
@@ -127,6 +127,7 @@ export interface ProjectIdAndToken {
|
|
|
127
127
|
}
|
|
128
128
|
export declare class PlasmicApi {
|
|
129
129
|
private auth;
|
|
130
|
+
private codegenVersion?;
|
|
130
131
|
constructor(auth: AuthConfig);
|
|
131
132
|
genStyleConfig(styleOpts?: StyleConfig): Promise<StyleConfigResponse>;
|
|
132
133
|
/**
|
|
@@ -146,6 +147,7 @@ export declare class PlasmicApi {
|
|
|
146
147
|
}[], recursive?: boolean): Promise<VersionResolution>;
|
|
147
148
|
getCurrentUser(): Promise<import("axios").AxiosResponse<any>>;
|
|
148
149
|
requiredPackages(): Promise<RequiredPackages>;
|
|
150
|
+
latestCodegenVersion(): Promise<string>;
|
|
149
151
|
/**
|
|
150
152
|
* Code-gen endpoint.
|
|
151
153
|
* 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.
|
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -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
package/src/__mocks__/api.ts
CHANGED
|
@@ -372,6 +372,10 @@ class PlasmicApi {
|
|
|
372
372
|
throw new Error("Unimplemented");
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
async latestCodegenVersion(): Promise<string> {
|
|
376
|
+
return "0.0.1";
|
|
377
|
+
};
|
|
378
|
+
|
|
375
379
|
async requiredPackages(): Promise<RequiredPackages> {
|
|
376
380
|
return {
|
|
377
381
|
"@plasmicapp/loader": "0.0.1",
|
package/src/actions/sync.ts
CHANGED
|
@@ -416,6 +416,12 @@ export async function sync(
|
|
|
416
416
|
writeLoaderConfig(opts, config);
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
const codegenVersion = await context.api.latestCodegenVersion();
|
|
420
|
+
context.lock.projects.forEach(p => {
|
|
421
|
+
if (projectsToSync.some(syncedProject => syncedProject.projectId === p.projectId)) {
|
|
422
|
+
p.codegenVersion = codegenVersion;
|
|
423
|
+
}
|
|
424
|
+
})
|
|
419
425
|
// Write the new ComponentConfigs to disk
|
|
420
426
|
await updateConfig(context, context.config, baseDir);
|
|
421
427
|
});
|
package/src/api.ts
CHANGED
|
@@ -161,6 +161,7 @@ export interface ProjectIdAndToken {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
export class PlasmicApi {
|
|
164
|
+
private codegenVersion?: string;
|
|
164
165
|
constructor(private auth: AuthConfig) {}
|
|
165
166
|
|
|
166
167
|
async genStyleConfig(styleOpts?: StyleConfig): Promise<StyleConfigResponse> {
|
|
@@ -213,6 +214,16 @@ export class PlasmicApi {
|
|
|
213
214
|
return { ...resp.data } as RequiredPackages;
|
|
214
215
|
}
|
|
215
216
|
|
|
217
|
+
async latestCodegenVersion(): Promise<string> {
|
|
218
|
+
if (!this.codegenVersion) {
|
|
219
|
+
const resp = await this.post(
|
|
220
|
+
`${this.codegenHost}/api/v1/code/latest-codegen-version`
|
|
221
|
+
);
|
|
222
|
+
this.codegenVersion = resp.data as string;
|
|
223
|
+
}
|
|
224
|
+
return this.codegenVersion;
|
|
225
|
+
}
|
|
226
|
+
|
|
216
227
|
/**
|
|
217
228
|
* Code-gen endpoint.
|
|
218
229
|
* This will fetch components at an exact specified version.
|
|
@@ -318,6 +318,8 @@ export interface ProjectLock {
|
|
|
318
318
|
lang: "ts" | "js";
|
|
319
319
|
// One for each file whose checksum is computed
|
|
320
320
|
fileLocks: FileLock[];
|
|
321
|
+
// The version of Codegen when this project was written
|
|
322
|
+
codegenVersion?: string;
|
|
321
323
|
}
|
|
322
324
|
|
|
323
325
|
export interface PlasmicLock {
|
|
@@ -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
|
/**
|