@plasmicapp/cli 0.1.186 → 0.1.188
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.d.ts +2 -0
- package/dist/__mocks__/api.js +16 -11
- package/dist/__tests__/project-api-token-spec.js +2 -2
- package/dist/__tests__/versioned-sync-spec.js +4 -4
- package/dist/actions/localization-strings.d.ts +3 -1
- package/dist/actions/localization-strings.js +39 -8
- package/dist/actions/project-token.js +1 -1
- package/dist/actions/sync-components.js +1 -1
- package/dist/actions/sync-global-variants.d.ts +1 -1
- package/dist/actions/sync-global-variants.js +2 -2
- package/dist/actions/sync-icons.d.ts +1 -1
- package/dist/actions/sync-icons.js +2 -2
- package/dist/actions/sync-images.d.ts +1 -1
- package/dist/actions/sync-images.js +2 -2
- package/dist/actions/sync-styles.d.ts +1 -1
- package/dist/actions/sync-styles.js +14 -1
- package/dist/actions/sync.js +24 -19
- package/dist/api.d.ts +11 -8
- package/dist/api.js +19 -14
- package/dist/index.js +5 -0
- package/dist/plasmic.schema.json +4 -0
- package/dist/test-common/fixtures.js +3 -0
- package/dist/utils/auth-utils.js +2 -2
- package/dist/utils/config-utils.d.ts +4 -1
- package/dist/utils/config-utils.js +2 -1
- package/package.json +2 -3
- package/src/__mocks__/api.ts +28 -7
- package/src/__tests__/project-api-token-spec.ts +2 -2
- package/src/__tests__/versioned-sync-spec.ts +4 -4
- package/src/actions/localization-strings.ts +60 -12
- package/src/actions/project-token.ts +1 -1
- package/src/actions/sync-components.ts +6 -1
- package/src/actions/sync-global-variants.ts +8 -3
- package/src/actions/sync-icons.ts +3 -2
- package/src/actions/sync-images.ts +2 -1
- package/src/actions/sync-styles.ts +15 -1
- package/src/actions/sync.ts +43 -22
- package/src/api.ts +29 -12
- package/src/index.ts +6 -0
- package/src/test-common/fixtures.ts +3 -0
- package/src/utils/auth-utils.ts +3 -3
- package/src/utils/config-utils.ts +5 -0
package/src/actions/sync.ts
CHANGED
|
@@ -243,6 +243,7 @@ export async function sync(
|
|
|
243
243
|
const [projectId, projectApiToken] = projectIdToken.split(":");
|
|
244
244
|
return {
|
|
245
245
|
projectId,
|
|
246
|
+
branchName: projectConfigMap[projectId]?.projectBranchName ?? "main",
|
|
246
247
|
versionRange:
|
|
247
248
|
versionRange || projectConfigMap[projectId]?.version || "latest",
|
|
248
249
|
componentIdOrNames: undefined, // Get all components!
|
|
@@ -255,6 +256,7 @@ export async function sync(
|
|
|
255
256
|
? projectWithVersion
|
|
256
257
|
: context.config.projects.map((p) => ({
|
|
257
258
|
projectId: p.projectId,
|
|
259
|
+
branchName: p.projectBranchName ?? "main",
|
|
258
260
|
versionRange: p.version,
|
|
259
261
|
componentIdOrNames: undefined, // Get all components!
|
|
260
262
|
projectApiToken: p.projectApiToken,
|
|
@@ -341,6 +343,7 @@ export async function sync(
|
|
|
341
343
|
opts,
|
|
342
344
|
projectIdsAndTokens,
|
|
343
345
|
projectMeta.projectId,
|
|
346
|
+
projectMeta.branchName,
|
|
344
347
|
projectMeta.componentIds,
|
|
345
348
|
projectMeta.version,
|
|
346
349
|
projectMeta.dependencies,
|
|
@@ -557,6 +560,7 @@ async function syncProject(
|
|
|
557
560
|
opts: SyncArgs,
|
|
558
561
|
projectIdsAndTokens: ProjectIdAndToken[],
|
|
559
562
|
projectId: string,
|
|
563
|
+
branchName: string,
|
|
560
564
|
componentIds: string[],
|
|
561
565
|
projectVersion: string,
|
|
562
566
|
dependencies: { [projectId: string]: string },
|
|
@@ -591,26 +595,30 @@ async function syncProject(
|
|
|
591
595
|
);
|
|
592
596
|
|
|
593
597
|
// Server-side code-gen
|
|
594
|
-
const projectBundle = await context.api.projectComponents(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
598
|
+
const projectBundle = await context.api.projectComponents(
|
|
599
|
+
projectId,
|
|
600
|
+
branchName,
|
|
601
|
+
{
|
|
602
|
+
platform: context.config.platform,
|
|
603
|
+
newCompScheme: newComponentScheme,
|
|
604
|
+
existingCompScheme,
|
|
605
|
+
componentIdOrNames: componentIds,
|
|
606
|
+
version: projectVersion,
|
|
607
|
+
imageOpts: context.config.images,
|
|
608
|
+
stylesOpts: context.config.style,
|
|
609
|
+
checksums: existingChecksums,
|
|
610
|
+
codeOpts: context.config.code,
|
|
611
|
+
metadata: generateMetadata(
|
|
612
|
+
{
|
|
613
|
+
...metadataDefaults,
|
|
614
|
+
platform: context.config.platform,
|
|
615
|
+
},
|
|
616
|
+
opts.metadata
|
|
617
|
+
),
|
|
618
|
+
indirect,
|
|
619
|
+
wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
|
|
620
|
+
}
|
|
621
|
+
);
|
|
614
622
|
|
|
615
623
|
// Convert from TSX => JSX
|
|
616
624
|
if (context.config.code.lang === "js") {
|
|
@@ -653,6 +661,7 @@ async function syncProject(
|
|
|
653
661
|
projectBundle.projectConfig,
|
|
654
662
|
projectBundle.globalVariants,
|
|
655
663
|
projectBundle.checksums,
|
|
664
|
+
branchName,
|
|
656
665
|
opts.baseDir
|
|
657
666
|
);
|
|
658
667
|
|
|
@@ -660,6 +669,7 @@ async function syncProject(
|
|
|
660
669
|
context,
|
|
661
670
|
projectBundle.projectConfig,
|
|
662
671
|
projectApiToken,
|
|
672
|
+
branchName,
|
|
663
673
|
projectVersion,
|
|
664
674
|
dependencies,
|
|
665
675
|
projectBundle.components,
|
|
@@ -672,10 +682,15 @@ async function syncProject(
|
|
|
672
682
|
indirect
|
|
673
683
|
);
|
|
674
684
|
syncCodeComponentsMeta(context, projectId, projectBundle.codeComponentMetas);
|
|
675
|
-
await upsertStyleTokens(
|
|
685
|
+
await upsertStyleTokens(
|
|
686
|
+
context,
|
|
687
|
+
projectBundle.usedTokens,
|
|
688
|
+
projectBundle.projectConfig.projectId
|
|
689
|
+
);
|
|
676
690
|
await syncProjectIconAssets(
|
|
677
691
|
context,
|
|
678
692
|
projectId,
|
|
693
|
+
branchName,
|
|
679
694
|
projectVersion,
|
|
680
695
|
projectBundle.iconAssets,
|
|
681
696
|
projectBundle.checksums,
|
|
@@ -684,6 +699,7 @@ async function syncProject(
|
|
|
684
699
|
await syncProjectImageAssets(
|
|
685
700
|
context,
|
|
686
701
|
projectId,
|
|
702
|
+
branchName,
|
|
687
703
|
projectVersion,
|
|
688
704
|
projectBundle.imageAssets,
|
|
689
705
|
projectBundle.checksums
|
|
@@ -716,6 +732,7 @@ async function syncProjectConfig(
|
|
|
716
732
|
context: PlasmicContext,
|
|
717
733
|
projectBundle: ProjectMetaBundle,
|
|
718
734
|
projectApiToken: string,
|
|
735
|
+
branchName: string,
|
|
719
736
|
version: string,
|
|
720
737
|
dependencies: { [projectId: string]: string },
|
|
721
738
|
componentBundles: ComponentBundle[],
|
|
@@ -756,7 +773,11 @@ async function syncProjectConfig(
|
|
|
756
773
|
}
|
|
757
774
|
|
|
758
775
|
// plasmic.lock
|
|
759
|
-
const projectLock = getOrAddProjectLock(
|
|
776
|
+
const projectLock = getOrAddProjectLock(
|
|
777
|
+
context,
|
|
778
|
+
projectConfig.projectId,
|
|
779
|
+
branchName
|
|
780
|
+
);
|
|
760
781
|
projectLock.version = version;
|
|
761
782
|
projectLock.dependencies = dependencies;
|
|
762
783
|
projectLock.lang = context.config.code.lang;
|
package/src/api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProjectSyncMetadataModel } from "@plasmicapp/code-merger";
|
|
2
2
|
import axios, { AxiosError } from "axios";
|
|
3
|
-
import socketio from "socket.io-client";
|
|
3
|
+
import socketio, { Socket } from "socket.io-client";
|
|
4
4
|
import {
|
|
5
5
|
AuthConfig,
|
|
6
6
|
CodeConfig,
|
|
@@ -75,6 +75,7 @@ export interface ImageBundle {
|
|
|
75
75
|
|
|
76
76
|
export interface ProjectVersionMeta {
|
|
77
77
|
projectId: string;
|
|
78
|
+
branchName: string;
|
|
78
79
|
projectApiToken: string;
|
|
79
80
|
version: string;
|
|
80
81
|
projectName: string;
|
|
@@ -201,6 +202,7 @@ export class PlasmicApi {
|
|
|
201
202
|
async resolveSync(
|
|
202
203
|
projects: {
|
|
203
204
|
projectId: string;
|
|
205
|
+
branchName: string;
|
|
204
206
|
versionRange?: string;
|
|
205
207
|
componentIdOrNames: readonly string[] | undefined;
|
|
206
208
|
projectApiToken?: string;
|
|
@@ -243,9 +245,10 @@ export class PlasmicApi {
|
|
|
243
245
|
|
|
244
246
|
/**
|
|
245
247
|
* Code-gen endpoint.
|
|
246
|
-
* This will fetch components at an exact specified version.
|
|
248
|
+
* This will fetch components from a given branch at an exact specified version.
|
|
247
249
|
* If you don't know what version should be used, call `resolveSync` first.
|
|
248
250
|
* @param projectId
|
|
251
|
+
* @param branchName
|
|
249
252
|
* @param cliVersion
|
|
250
253
|
* @param reactWebVersion
|
|
251
254
|
* @param newCompScheme
|
|
@@ -255,6 +258,7 @@ export class PlasmicApi {
|
|
|
255
258
|
*/
|
|
256
259
|
async projectComponents(
|
|
257
260
|
projectId: string,
|
|
261
|
+
branchName: string,
|
|
258
262
|
opts: {
|
|
259
263
|
platform: string;
|
|
260
264
|
newCompScheme: "blackbox" | "direct";
|
|
@@ -272,7 +276,7 @@ export class PlasmicApi {
|
|
|
272
276
|
}
|
|
273
277
|
): Promise<ProjectBundle> {
|
|
274
278
|
const result = await this.post(
|
|
275
|
-
`${this.codegenHost}/api/v1/projects/${projectId}/code/components`,
|
|
279
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/components?branchName=${branchName}`,
|
|
276
280
|
{
|
|
277
281
|
...opts,
|
|
278
282
|
}
|
|
@@ -289,14 +293,24 @@ export class PlasmicApi {
|
|
|
289
293
|
|
|
290
294
|
async genLocalizationStrings(
|
|
291
295
|
projects: readonly string[],
|
|
292
|
-
format: "po" | "json" | "lingui"
|
|
296
|
+
format: "po" | "json" | "lingui",
|
|
297
|
+
projectIdsAndTokens: ProjectIdAndToken[]
|
|
293
298
|
) {
|
|
294
299
|
const result = await this.get(
|
|
295
300
|
`${
|
|
296
301
|
this.codegenHost
|
|
297
302
|
}/api/v1/localization/gen-texts?format=${format}&preview=true&${projects
|
|
298
303
|
.map((p) => `projectId=${p}`)
|
|
299
|
-
.join("&")}
|
|
304
|
+
.join("&")}`,
|
|
305
|
+
undefined,
|
|
306
|
+
{
|
|
307
|
+
"x-plasmic-api-project-tokens": projectIdsAndTokens
|
|
308
|
+
.map(
|
|
309
|
+
({ projectId, projectApiToken }) =>
|
|
310
|
+
`${projectId}:${projectApiToken}`
|
|
311
|
+
)
|
|
312
|
+
.join(","),
|
|
313
|
+
}
|
|
300
314
|
);
|
|
301
315
|
return result.data as string;
|
|
302
316
|
}
|
|
@@ -335,10 +349,11 @@ export class PlasmicApi {
|
|
|
335
349
|
|
|
336
350
|
async projectStyleTokens(
|
|
337
351
|
projectId: string,
|
|
352
|
+
branchName: string,
|
|
338
353
|
versionRange?: string
|
|
339
354
|
): Promise<StyleTokensMap> {
|
|
340
355
|
const result = await this.post(
|
|
341
|
-
`${this.codegenHost}/api/v1/projects/${projectId}/code/tokens`,
|
|
356
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/tokens?branchName=${branchName}`,
|
|
342
357
|
{ versionRange }
|
|
343
358
|
);
|
|
344
359
|
return result.data as StyleTokensMap;
|
|
@@ -346,11 +361,12 @@ export class PlasmicApi {
|
|
|
346
361
|
|
|
347
362
|
async projectIcons(
|
|
348
363
|
projectId: string,
|
|
364
|
+
branchName: string,
|
|
349
365
|
versionRange?: string,
|
|
350
366
|
iconIds?: string[]
|
|
351
367
|
): Promise<ProjectIconsResponse> {
|
|
352
368
|
const result = await this.post(
|
|
353
|
-
`${this.codegenHost}/api/v1/projects/${projectId}/code/icons`,
|
|
369
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/icons?branchName=${branchName}`,
|
|
354
370
|
{ versionRange, iconIds }
|
|
355
371
|
);
|
|
356
372
|
return result.data as ProjectIconsResponse;
|
|
@@ -358,19 +374,20 @@ export class PlasmicApi {
|
|
|
358
374
|
|
|
359
375
|
async projectSyncMetadata(
|
|
360
376
|
projectId: string,
|
|
377
|
+
branchName: string,
|
|
361
378
|
revision: number,
|
|
362
379
|
rethrowAppError: boolean
|
|
363
380
|
): Promise<ProjectSyncMetadataModel> {
|
|
364
381
|
const result = await this.post(
|
|
365
|
-
`${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata`,
|
|
382
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata?branchName=${branchName}`,
|
|
366
383
|
{ revision },
|
|
367
384
|
rethrowAppError
|
|
368
385
|
);
|
|
369
386
|
return ProjectSyncMetadataModel.fromJson(result.data);
|
|
370
387
|
}
|
|
371
388
|
|
|
372
|
-
connectSocket():
|
|
373
|
-
const socket = socketio
|
|
389
|
+
connectSocket(): Socket {
|
|
390
|
+
const socket = socketio(this.studioHost, {
|
|
374
391
|
path: `/api/v1/socket`,
|
|
375
392
|
transportOptions: {
|
|
376
393
|
polling: {
|
|
@@ -408,10 +425,10 @@ export class PlasmicApi {
|
|
|
408
425
|
}
|
|
409
426
|
}
|
|
410
427
|
|
|
411
|
-
private async get(url: string, rethrowAppError?: boolean) {
|
|
428
|
+
private async get(url: string, rethrowAppError?: boolean, extraHeaders?: {}) {
|
|
412
429
|
try {
|
|
413
430
|
return await axios.get(url, {
|
|
414
|
-
headers: this.makeHeaders(),
|
|
431
|
+
headers: { ...this.makeHeaders(), ...(extraHeaders ?? {}) },
|
|
415
432
|
});
|
|
416
433
|
} catch (e) {
|
|
417
434
|
const error = e as AxiosError;
|
package/src/index.ts
CHANGED
|
@@ -261,6 +261,12 @@ yargs
|
|
|
261
261
|
type: "boolean",
|
|
262
262
|
describe: "Overwrite the output file.",
|
|
263
263
|
default: false,
|
|
264
|
+
})
|
|
265
|
+
.option("project-tokens", {
|
|
266
|
+
type: "array",
|
|
267
|
+
default: [],
|
|
268
|
+
describe:
|
|
269
|
+
"(Optional) List of project API tokens to be used for auth, in the format PROJECT_ID:PROJECT_API_TOKEN (the pairs should be separated by comma)",
|
|
264
270
|
}),
|
|
265
271
|
(argv) => handleError(localizationStrings(argv))
|
|
266
272
|
)
|
|
@@ -43,6 +43,7 @@ export function standardTestSetup(includeDep = true) {
|
|
|
43
43
|
// Setup server-side mock data
|
|
44
44
|
const project1: MockProject = {
|
|
45
45
|
projectId: "projectId1",
|
|
46
|
+
branchName: "main",
|
|
46
47
|
projectApiToken: "abc",
|
|
47
48
|
version: "1.2.3",
|
|
48
49
|
projectName: "project1",
|
|
@@ -64,6 +65,7 @@ export function standardTestSetup(includeDep = true) {
|
|
|
64
65
|
};
|
|
65
66
|
const dependency: MockProject = {
|
|
66
67
|
projectId: "dependencyId1",
|
|
68
|
+
branchName: "main",
|
|
67
69
|
projectApiToken: "def",
|
|
68
70
|
version: "2.3.4",
|
|
69
71
|
projectName: "dependency1",
|
|
@@ -128,6 +130,7 @@ export function expectProject1Components() {
|
|
|
128
130
|
export const project1Config: ProjectConfig = {
|
|
129
131
|
projectId: "projectId1",
|
|
130
132
|
projectName: "Project 1",
|
|
133
|
+
projectBranchName: "main",
|
|
131
134
|
version: "latest",
|
|
132
135
|
cssFilePath: "plasmic/PP__demo.css",
|
|
133
136
|
components: [
|
package/src/utils/auth-utils.ts
CHANGED
|
@@ -38,7 +38,7 @@ export function authByPolling(
|
|
|
38
38
|
host: string,
|
|
39
39
|
initToken: string
|
|
40
40
|
): CancellablePromise<AuthData> {
|
|
41
|
-
const socket = socketio
|
|
41
|
+
const socket = socketio(host, {
|
|
42
42
|
path: `/api/v1/init-token`,
|
|
43
43
|
transportOptions: {
|
|
44
44
|
polling: {
|
|
@@ -50,7 +50,7 @@ export function authByPolling(
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
const promise = new Promise<AuthData>((resolve, reject) => {
|
|
53
|
-
socket.on("connect", (
|
|
53
|
+
socket.on("connect", () => {
|
|
54
54
|
logger.info("Waiting for token...");
|
|
55
55
|
});
|
|
56
56
|
|
|
@@ -219,7 +219,7 @@ export async function getCurrentAuth(authPath?: string) {
|
|
|
219
219
|
await api.getCurrentUser();
|
|
220
220
|
return auth;
|
|
221
221
|
} catch (e) {
|
|
222
|
-
if (e.response?.status === 401) {
|
|
222
|
+
if ((e as any).response?.status === 401) {
|
|
223
223
|
logger.error(`The current credentials expired or are not valid.`);
|
|
224
224
|
return undefined;
|
|
225
225
|
}
|
|
@@ -155,6 +155,8 @@ export interface ProjectConfig {
|
|
|
155
155
|
projectApiToken?: string;
|
|
156
156
|
/** Project name synced down from Studio */
|
|
157
157
|
projectName: string;
|
|
158
|
+
/** Project branch to be synced */
|
|
159
|
+
projectBranchName?: string;
|
|
158
160
|
/**
|
|
159
161
|
* A version range for syncing this project. Can be:
|
|
160
162
|
* * "latest" - always syncs down whatever has been saved in the project.
|
|
@@ -317,6 +319,7 @@ export interface FileLock {
|
|
|
317
319
|
|
|
318
320
|
export interface ProjectLock {
|
|
319
321
|
projectId: string;
|
|
322
|
+
branchName: string;
|
|
320
323
|
// The exact version that was last synced
|
|
321
324
|
version: string;
|
|
322
325
|
dependencies: {
|
|
@@ -550,6 +553,7 @@ export function getOrAddProjectConfig(
|
|
|
550
553
|
export function getOrAddProjectLock(
|
|
551
554
|
context: PlasmicContext,
|
|
552
555
|
projectId: string,
|
|
556
|
+
branchName: string,
|
|
553
557
|
base?: ProjectLock // if one doesn't exist, start with this
|
|
554
558
|
): ProjectLock {
|
|
555
559
|
let project = context.lock.projects.find((p) => p.projectId === projectId);
|
|
@@ -558,6 +562,7 @@ export function getOrAddProjectLock(
|
|
|
558
562
|
? L.cloneDeep(base)
|
|
559
563
|
: {
|
|
560
564
|
projectId,
|
|
565
|
+
branchName,
|
|
561
566
|
version: "",
|
|
562
567
|
dependencies: {},
|
|
563
568
|
lang: context.config.code.lang,
|