@plasmicapp/cli 0.1.297 → 0.1.300
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/fix-imports.d.ts +1 -0
- package/dist/actions/info.d.ts +2 -0
- package/dist/actions/sync.d.ts +1 -0
- package/dist/globals.d.ts +3 -0
- package/dist/index.js +93 -19
- package/dist/lib.js +63 -11
- package/dist/utils/get-context.d.ts +2 -1
- package/package.json +2 -2
- package/src/actions/fix-imports.ts +7 -1
- package/src/actions/info.ts +14 -6
- package/src/actions/sync.ts +10 -4
- package/src/globals.ts +3 -0
- package/src/index.ts +28 -7
- package/src/utils/checksum.ts +62 -11
- package/src/utils/code-utils.ts +4 -0
- package/src/utils/get-context.ts +9 -5
package/dist/actions/info.d.ts
CHANGED
package/dist/actions/sync.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface SyncArgs extends CommonArgs {
|
|
|
12
12
|
metadata?: string;
|
|
13
13
|
allFiles?: boolean;
|
|
14
14
|
loaderConfig?: string;
|
|
15
|
+
skipFormatting?: boolean;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Sync will always try to sync down a set of components that are version-consistent among specified projects.
|
package/dist/index.js
CHANGED
|
@@ -735124,8 +735124,16 @@ async function fixComponentImagesReferences(context, fixImportContext, renderMod
|
|
|
735124
735124
|
return false;
|
|
735125
735125
|
}
|
|
735126
735126
|
|
|
735127
|
+
// src/globals.ts
|
|
735128
|
+
var GLOBAL_SETTINGS = {
|
|
735129
|
+
skipFormatting: false
|
|
735130
|
+
};
|
|
735131
|
+
|
|
735127
735132
|
// src/utils/code-utils.ts
|
|
735128
735133
|
var formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
|
|
735134
|
+
if (GLOBAL_SETTINGS.skipFormatting) {
|
|
735135
|
+
return content;
|
|
735136
|
+
}
|
|
735129
735137
|
const opts = { ...defaultOpts };
|
|
735130
735138
|
opts.filepath = filePath;
|
|
735131
735139
|
const res = Prettier.format(content, opts);
|
|
@@ -737708,7 +737716,10 @@ async function resolveMissingFilesInConfig(context, config) {
|
|
|
737708
737716
|
project.components = newComponents;
|
|
737709
737717
|
}
|
|
737710
737718
|
}
|
|
737711
|
-
async function getContext(args, {
|
|
737719
|
+
async function getContext(args, {
|
|
737720
|
+
enableSkipAuth = false,
|
|
737721
|
+
skipMissingFiles = false
|
|
737722
|
+
} = {}) {
|
|
737712
737723
|
if (!args.baseDir)
|
|
737713
737724
|
args.baseDir = process.cwd();
|
|
737714
737725
|
const auth2 = enableSkipAuth ? await getCurrentOrDefaultAuth(args) : await getOrInitAuth(args);
|
|
@@ -737752,8 +737763,10 @@ async function getContext(args, { enableSkipAuth = false } = {}) {
|
|
|
737752
737763
|
api: new PlasmicApi(auth2),
|
|
737753
737764
|
cliArgs: args
|
|
737754
737765
|
};
|
|
737755
|
-
|
|
737756
|
-
|
|
737766
|
+
if (!skipMissingFiles) {
|
|
737767
|
+
await resolveMissingFilesInConfig(context, config);
|
|
737768
|
+
removeMissingFilesFromLock(context, config, lock);
|
|
737769
|
+
}
|
|
737757
737770
|
return context;
|
|
737758
737771
|
}
|
|
737759
737772
|
async function getCurrentOrDefaultAuth(args) {
|
|
@@ -737809,6 +737822,9 @@ function generateMetadata(defaults, fromArgs) {
|
|
|
737809
737822
|
async function fixImports(opts) {
|
|
737810
737823
|
if (!opts.baseDir)
|
|
737811
737824
|
opts.baseDir = process.cwd();
|
|
737825
|
+
if (opts.skipFormatting) {
|
|
737826
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
737827
|
+
}
|
|
737812
737828
|
const context = await getContext(opts, { enableSkipAuth: true });
|
|
737813
737829
|
await updateConfig(context, context.config, opts.baseDir);
|
|
737814
737830
|
await fixAllImportStatements(context, opts.baseDir);
|
|
@@ -737817,15 +737833,21 @@ async function fixImports(opts) {
|
|
|
737817
737833
|
// src/actions/info.ts
|
|
737818
737834
|
async function printProjectInfo(opts) {
|
|
737819
737835
|
var _a, _b;
|
|
737820
|
-
let context = await getContext(opts);
|
|
737836
|
+
let context = await getContext(opts, { skipMissingFiles: true });
|
|
737821
737837
|
const results = await Promise.all(
|
|
737822
737838
|
opts.projects.map(async (p) => await context.api.projectMeta(p))
|
|
737823
737839
|
);
|
|
737824
|
-
|
|
737825
|
-
logger.info(
|
|
737826
|
-
|
|
737827
|
-
|
|
737828
|
-
|
|
737840
|
+
if (opts.json) {
|
|
737841
|
+
logger.info(JSON.stringify(results, null, 2));
|
|
737842
|
+
} else {
|
|
737843
|
+
for (const meta of results) {
|
|
737844
|
+
logger.info(`Id: ${meta.id}`);
|
|
737845
|
+
logger.info(`Name: ${meta.name}`);
|
|
737846
|
+
logger.info(`Host URL: ${(_a = meta.hostUrl) != null ? _a : null}`);
|
|
737847
|
+
logger.info(
|
|
737848
|
+
`Last published version: ${(_b = meta.lastPublishedVersion) != null ? _b : null}`
|
|
737849
|
+
);
|
|
737850
|
+
}
|
|
737829
737851
|
}
|
|
737830
737852
|
}
|
|
737831
737853
|
|
|
@@ -737867,6 +737889,29 @@ var import_lodash17 = __toESM(require_lodash());
|
|
|
737867
737889
|
var import_upath12 = __toESM(require_upath());
|
|
737868
737890
|
|
|
737869
737891
|
// src/utils/checksum.ts
|
|
737892
|
+
function getFilesByFileLockAssetId(context, projectConfig) {
|
|
737893
|
+
return {
|
|
737894
|
+
renderModule: Object.fromEntries(
|
|
737895
|
+
projectConfig.components.map((c) => [c.id, c.renderModuleFilePath])
|
|
737896
|
+
),
|
|
737897
|
+
cssRules: Object.fromEntries(
|
|
737898
|
+
projectConfig.components.map((c) => [c.id, c.cssFilePath])
|
|
737899
|
+
),
|
|
737900
|
+
icon: Object.fromEntries(
|
|
737901
|
+
projectConfig.icons.map((i) => [i.id, i.moduleFilePath])
|
|
737902
|
+
),
|
|
737903
|
+
image: Object.fromEntries(
|
|
737904
|
+
projectConfig.images.map((i) => [i.id, i.filePath])
|
|
737905
|
+
),
|
|
737906
|
+
projectCss: { [projectConfig.projectId]: projectConfig.cssFilePath },
|
|
737907
|
+
globalVariant: Object.fromEntries(
|
|
737908
|
+
context.config.globalVariants.variantGroups.filter((vg) => vg.projectId === projectConfig.projectId).map((vg) => [vg.id, vg.contextFilePath])
|
|
737909
|
+
),
|
|
737910
|
+
globalContext: {
|
|
737911
|
+
[projectConfig.projectId]: projectConfig.globalContextsFilePath
|
|
737912
|
+
}
|
|
737913
|
+
};
|
|
737914
|
+
}
|
|
737870
737915
|
function getChecksums(context, opts, projectId, componentIds) {
|
|
737871
737916
|
const projectConfig = context.config.projects.find(
|
|
737872
737917
|
(p) => p.projectId === projectId
|
|
@@ -737885,6 +737930,13 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
737885
737930
|
globalContextsChecksum: ""
|
|
737886
737931
|
};
|
|
737887
737932
|
}
|
|
737933
|
+
const fileLocations = getFilesByFileLockAssetId(context, projectConfig);
|
|
737934
|
+
const checkFile = (file) => {
|
|
737935
|
+
if (!file) {
|
|
737936
|
+
return false;
|
|
737937
|
+
}
|
|
737938
|
+
return fileExists(context, file);
|
|
737939
|
+
};
|
|
737888
737940
|
const fileLocks = projectLock.fileLocks;
|
|
737889
737941
|
const knownImages = new Set(projectConfig.images.map((i) => i.id));
|
|
737890
737942
|
const knownIcons = new Set(projectConfig.icons.map((i) => i.id));
|
|
@@ -737892,32 +737944,35 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
737892
737944
|
const knownGlobalVariants = new Set(
|
|
737893
737945
|
context.config.globalVariants.variantGroups.filter((vg) => vg.projectId === projectId).map((vg) => vg.id)
|
|
737894
737946
|
);
|
|
737895
|
-
const knownThemes = new Set(
|
|
737896
|
-
(projectConfig.jsBundleThemes || []).map((theme) => theme.bundleName)
|
|
737897
|
-
);
|
|
737898
737947
|
const toBeSyncedComponents = new Set(componentIds);
|
|
737899
737948
|
const imageChecksums = fileLocks.filter(
|
|
737900
737949
|
(fileLock) => fileLock.type === "image" && knownImages.has(fileLock.assetId)
|
|
737901
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737950
|
+
).filter((fileLock) => checkFile(fileLocations.image[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737902
737951
|
const iconChecksums = fileLocks.filter(
|
|
737903
737952
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "icon" && knownIcons.has(fileLock.assetId)
|
|
737904
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737953
|
+
).filter((fileLock) => checkFile(fileLocations.icon[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737905
737954
|
const renderModuleChecksums = fileLocks.filter(
|
|
737906
737955
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "renderModule" && toBeSyncedComponents.has(fileLock.assetId) && knownComponents.has(fileLock.assetId)
|
|
737956
|
+
).filter(
|
|
737957
|
+
(fileLock) => checkFile(fileLocations.renderModule[fileLock.assetId])
|
|
737907
737958
|
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737908
737959
|
const cssRulesChecksums = fileLocks.filter(
|
|
737909
737960
|
(fileLock) => fileLock.type === "cssRules" && toBeSyncedComponents.has(fileLock.assetId) && knownComponents.has(fileLock.assetId)
|
|
737910
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737961
|
+
).filter((fileLock) => checkFile(fileLocations.cssRules[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737911
737962
|
const globalVariantChecksums = fileLocks.filter(
|
|
737912
737963
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "globalVariant" && knownGlobalVariants.has(fileLock.assetId)
|
|
737964
|
+
).filter(
|
|
737965
|
+
(fileLock) => checkFile(fileLocations.globalVariant[fileLock.assetId])
|
|
737913
737966
|
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
737914
|
-
const projectCssChecksums = fileLocks.filter(
|
|
737915
|
-
(fileLock) => fileLock.
|
|
737967
|
+
const projectCssChecksums = fileLocks.filter((fileLock) => fileLock.type === "projectCss").filter(
|
|
737968
|
+
(fileLock) => checkFile(fileLocations.projectCss[fileLock.assetId])
|
|
737916
737969
|
);
|
|
737917
737970
|
assert(projectCssChecksums.length < 2);
|
|
737918
737971
|
const projectCssChecksum = projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
737919
737972
|
const globalContextsChecksums = fileLocks.filter(
|
|
737920
737973
|
(fileLock) => fileLock.type === "globalContexts" && fileLock.assetId === projectId
|
|
737974
|
+
).filter(
|
|
737975
|
+
(fileLock) => checkFile(fileLocations.globalContext[fileLock.assetId])
|
|
737921
737976
|
);
|
|
737922
737977
|
assert(globalContextsChecksums.length < 2);
|
|
737923
737978
|
const globalContextsChecksum = globalContextsChecksums.length > 0 ? globalContextsChecksums[0].checksum : "";
|
|
@@ -738799,6 +738854,9 @@ async function sync(opts, metadataDefaults) {
|
|
|
738799
738854
|
opts.baseDir = process.cwd();
|
|
738800
738855
|
const baseDir = opts.baseDir;
|
|
738801
738856
|
let context = await getContext(opts, { enableSkipAuth: true });
|
|
738857
|
+
if (opts.skipFormatting) {
|
|
738858
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
738859
|
+
}
|
|
738802
738860
|
const isFirstRun = context.config.projects.length === 0;
|
|
738803
738861
|
if (!opts.skipUpgradeCheck) {
|
|
738804
738862
|
await ensureRequiredPackages(context, opts.baseDir, opts.yes);
|
|
@@ -739555,16 +739613,28 @@ import_yargs.default.usage("Usage: $0 <command> [options]").option("auth", {
|
|
|
739555
739613
|
).command(
|
|
739556
739614
|
"fix-imports",
|
|
739557
739615
|
"Fixes import paths after you've moved around Plasmic blackbox files",
|
|
739558
|
-
(yags) =>
|
|
739616
|
+
(yags) => yags.option("skip-formatting", {
|
|
739617
|
+
type: "boolean",
|
|
739618
|
+
describe: "Skip formatting of modified code",
|
|
739619
|
+
default: false
|
|
739620
|
+
}),
|
|
739559
739621
|
(argv) => handleError(fixImports(argv))
|
|
739560
739622
|
).command(
|
|
739561
739623
|
"info",
|
|
739562
739624
|
"Fetches metadata for projects",
|
|
739563
|
-
(yags) => yags.option("
|
|
739625
|
+
(yags) => yags.option("host", {
|
|
739626
|
+
describe: "Plasmic host to use",
|
|
739627
|
+
type: "string",
|
|
739628
|
+
default: "https://studio.plasmic.app"
|
|
739629
|
+
}).option("projects", {
|
|
739564
739630
|
alias: "p",
|
|
739565
739631
|
describe: "ID of plasmic project to check",
|
|
739566
739632
|
type: "array",
|
|
739567
739633
|
default: []
|
|
739634
|
+
}).option("json", {
|
|
739635
|
+
describe: "Output full info, not just summary, in JSON format",
|
|
739636
|
+
type: "boolean",
|
|
739637
|
+
default: false
|
|
739568
739638
|
}),
|
|
739569
739639
|
(argv) => {
|
|
739570
739640
|
handleError(printProjectInfo(argv));
|
|
@@ -739701,6 +739771,10 @@ function configureSyncArgs(yags, includeQuietOption = true) {
|
|
|
739701
739771
|
describe: "Pass metadata through to the server. Use querystring format (e.g. command=sync&source=cli&cli_version=1.0.0",
|
|
739702
739772
|
default: "source=cli",
|
|
739703
739773
|
hidden: true
|
|
739774
|
+
}).option("skip-formatting", {
|
|
739775
|
+
type: "boolean",
|
|
739776
|
+
describe: "Disables formatting on generated code",
|
|
739777
|
+
default: false
|
|
739704
739778
|
}).option("all-files", {
|
|
739705
739779
|
type: "boolean",
|
|
739706
739780
|
describe: "Sync all files, including those that haven't changed since last sync",
|
package/dist/lib.js
CHANGED
|
@@ -730464,8 +730464,16 @@ async function fixComponentImagesReferences(context, fixImportContext, renderMod
|
|
|
730464
730464
|
return false;
|
|
730465
730465
|
}
|
|
730466
730466
|
|
|
730467
|
+
// src/globals.ts
|
|
730468
|
+
var GLOBAL_SETTINGS = {
|
|
730469
|
+
skipFormatting: false
|
|
730470
|
+
};
|
|
730471
|
+
|
|
730467
730472
|
// src/utils/code-utils.ts
|
|
730468
730473
|
var formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
|
|
730474
|
+
if (GLOBAL_SETTINGS.skipFormatting) {
|
|
730475
|
+
return content;
|
|
730476
|
+
}
|
|
730469
730477
|
const opts = { ...defaultOpts };
|
|
730470
730478
|
opts.filepath = filePath;
|
|
730471
730479
|
const res = Prettier.format(content, opts);
|
|
@@ -733028,7 +733036,10 @@ async function resolveMissingFilesInConfig(context, config) {
|
|
|
733028
733036
|
project.components = newComponents;
|
|
733029
733037
|
}
|
|
733030
733038
|
}
|
|
733031
|
-
async function getContext(args, {
|
|
733039
|
+
async function getContext(args, {
|
|
733040
|
+
enableSkipAuth = false,
|
|
733041
|
+
skipMissingFiles = false
|
|
733042
|
+
} = {}) {
|
|
733032
733043
|
if (!args.baseDir)
|
|
733033
733044
|
args.baseDir = process.cwd();
|
|
733034
733045
|
const auth2 = enableSkipAuth ? await getCurrentOrDefaultAuth(args) : await getOrInitAuth(args);
|
|
@@ -733072,8 +733083,10 @@ async function getContext(args, { enableSkipAuth = false } = {}) {
|
|
|
733072
733083
|
api: new PlasmicApi(auth2),
|
|
733073
733084
|
cliArgs: args
|
|
733074
733085
|
};
|
|
733075
|
-
|
|
733076
|
-
|
|
733086
|
+
if (!skipMissingFiles) {
|
|
733087
|
+
await resolveMissingFilesInConfig(context, config);
|
|
733088
|
+
removeMissingFilesFromLock(context, config, lock);
|
|
733089
|
+
}
|
|
733077
733090
|
return context;
|
|
733078
733091
|
}
|
|
733079
733092
|
async function getCurrentOrDefaultAuth(args) {
|
|
@@ -733139,6 +733152,9 @@ function setMetadataEnv(metadata) {
|
|
|
733139
733152
|
async function fixImports(opts) {
|
|
733140
733153
|
if (!opts.baseDir)
|
|
733141
733154
|
opts.baseDir = process.cwd();
|
|
733155
|
+
if (opts.skipFormatting) {
|
|
733156
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
733157
|
+
}
|
|
733142
733158
|
const context = await getContext(opts, { enableSkipAuth: true });
|
|
733143
733159
|
await updateConfig(context, context.config, opts.baseDir);
|
|
733144
733160
|
await fixAllImportStatements(context, opts.baseDir);
|
|
@@ -733169,6 +733185,29 @@ var import_lodash17 = __toESM(require_lodash());
|
|
|
733169
733185
|
var import_upath12 = __toESM(require_upath());
|
|
733170
733186
|
|
|
733171
733187
|
// src/utils/checksum.ts
|
|
733188
|
+
function getFilesByFileLockAssetId(context, projectConfig) {
|
|
733189
|
+
return {
|
|
733190
|
+
renderModule: Object.fromEntries(
|
|
733191
|
+
projectConfig.components.map((c) => [c.id, c.renderModuleFilePath])
|
|
733192
|
+
),
|
|
733193
|
+
cssRules: Object.fromEntries(
|
|
733194
|
+
projectConfig.components.map((c) => [c.id, c.cssFilePath])
|
|
733195
|
+
),
|
|
733196
|
+
icon: Object.fromEntries(
|
|
733197
|
+
projectConfig.icons.map((i) => [i.id, i.moduleFilePath])
|
|
733198
|
+
),
|
|
733199
|
+
image: Object.fromEntries(
|
|
733200
|
+
projectConfig.images.map((i) => [i.id, i.filePath])
|
|
733201
|
+
),
|
|
733202
|
+
projectCss: { [projectConfig.projectId]: projectConfig.cssFilePath },
|
|
733203
|
+
globalVariant: Object.fromEntries(
|
|
733204
|
+
context.config.globalVariants.variantGroups.filter((vg) => vg.projectId === projectConfig.projectId).map((vg) => [vg.id, vg.contextFilePath])
|
|
733205
|
+
),
|
|
733206
|
+
globalContext: {
|
|
733207
|
+
[projectConfig.projectId]: projectConfig.globalContextsFilePath
|
|
733208
|
+
}
|
|
733209
|
+
};
|
|
733210
|
+
}
|
|
733172
733211
|
function getChecksums(context, opts, projectId, componentIds) {
|
|
733173
733212
|
const projectConfig = context.config.projects.find(
|
|
733174
733213
|
(p) => p.projectId === projectId
|
|
@@ -733187,6 +733226,13 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
733187
733226
|
globalContextsChecksum: ""
|
|
733188
733227
|
};
|
|
733189
733228
|
}
|
|
733229
|
+
const fileLocations = getFilesByFileLockAssetId(context, projectConfig);
|
|
733230
|
+
const checkFile = (file) => {
|
|
733231
|
+
if (!file) {
|
|
733232
|
+
return false;
|
|
733233
|
+
}
|
|
733234
|
+
return fileExists(context, file);
|
|
733235
|
+
};
|
|
733190
733236
|
const fileLocks = projectLock.fileLocks;
|
|
733191
733237
|
const knownImages = new Set(projectConfig.images.map((i) => i.id));
|
|
733192
733238
|
const knownIcons = new Set(projectConfig.icons.map((i) => i.id));
|
|
@@ -733194,32 +733240,35 @@ function getChecksums(context, opts, projectId, componentIds) {
|
|
|
733194
733240
|
const knownGlobalVariants = new Set(
|
|
733195
733241
|
context.config.globalVariants.variantGroups.filter((vg) => vg.projectId === projectId).map((vg) => vg.id)
|
|
733196
733242
|
);
|
|
733197
|
-
const knownThemes = new Set(
|
|
733198
|
-
(projectConfig.jsBundleThemes || []).map((theme) => theme.bundleName)
|
|
733199
|
-
);
|
|
733200
733243
|
const toBeSyncedComponents = new Set(componentIds);
|
|
733201
733244
|
const imageChecksums = fileLocks.filter(
|
|
733202
733245
|
(fileLock) => fileLock.type === "image" && knownImages.has(fileLock.assetId)
|
|
733203
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733246
|
+
).filter((fileLock) => checkFile(fileLocations.image[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733204
733247
|
const iconChecksums = fileLocks.filter(
|
|
733205
733248
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "icon" && knownIcons.has(fileLock.assetId)
|
|
733206
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733249
|
+
).filter((fileLock) => checkFile(fileLocations.icon[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733207
733250
|
const renderModuleChecksums = fileLocks.filter(
|
|
733208
733251
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "renderModule" && toBeSyncedComponents.has(fileLock.assetId) && knownComponents.has(fileLock.assetId)
|
|
733252
|
+
).filter(
|
|
733253
|
+
(fileLock) => checkFile(fileLocations.renderModule[fileLock.assetId])
|
|
733209
733254
|
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733210
733255
|
const cssRulesChecksums = fileLocks.filter(
|
|
733211
733256
|
(fileLock) => fileLock.type === "cssRules" && toBeSyncedComponents.has(fileLock.assetId) && knownComponents.has(fileLock.assetId)
|
|
733212
|
-
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733257
|
+
).filter((fileLock) => checkFile(fileLocations.cssRules[fileLock.assetId])).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733213
733258
|
const globalVariantChecksums = fileLocks.filter(
|
|
733214
733259
|
(fileLock) => projectLock.lang === context.config.code.lang && fileLock.type === "globalVariant" && knownGlobalVariants.has(fileLock.assetId)
|
|
733260
|
+
).filter(
|
|
733261
|
+
(fileLock) => checkFile(fileLocations.globalVariant[fileLock.assetId])
|
|
733215
733262
|
).map((fileLock) => [fileLock.assetId, fileLock.checksum]);
|
|
733216
|
-
const projectCssChecksums = fileLocks.filter(
|
|
733217
|
-
(fileLock) => fileLock.
|
|
733263
|
+
const projectCssChecksums = fileLocks.filter((fileLock) => fileLock.type === "projectCss").filter(
|
|
733264
|
+
(fileLock) => checkFile(fileLocations.projectCss[fileLock.assetId])
|
|
733218
733265
|
);
|
|
733219
733266
|
assert(projectCssChecksums.length < 2);
|
|
733220
733267
|
const projectCssChecksum = projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
733221
733268
|
const globalContextsChecksums = fileLocks.filter(
|
|
733222
733269
|
(fileLock) => fileLock.type === "globalContexts" && fileLock.assetId === projectId
|
|
733270
|
+
).filter(
|
|
733271
|
+
(fileLock) => checkFile(fileLocations.globalContext[fileLock.assetId])
|
|
733223
733272
|
);
|
|
733224
733273
|
assert(globalContextsChecksums.length < 2);
|
|
733225
733274
|
const globalContextsChecksum = globalContextsChecksums.length > 0 ? globalContextsChecksums[0].checksum : "";
|
|
@@ -734101,6 +734150,9 @@ async function sync(opts, metadataDefaults) {
|
|
|
734101
734150
|
opts.baseDir = process.cwd();
|
|
734102
734151
|
const baseDir = opts.baseDir;
|
|
734103
734152
|
let context = await getContext(opts, { enableSkipAuth: true });
|
|
734153
|
+
if (opts.skipFormatting) {
|
|
734154
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
734155
|
+
}
|
|
734104
734156
|
const isFirstRun = context.config.projects.length === 0;
|
|
734105
734157
|
if (!opts.skipUpgradeCheck) {
|
|
734106
734158
|
await ensureRequiredPackages(context, opts.baseDir, opts.yes);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CommonArgs } from "../index";
|
|
2
2
|
import { PlasmicContext, PlasmicLock } from "./config-utils";
|
|
3
3
|
export declare function readLock(lockFile: string): PlasmicLock;
|
|
4
|
-
export declare function getContext(args: CommonArgs, { enableSkipAuth }?: {
|
|
4
|
+
export declare function getContext(args: CommonArgs, { enableSkipAuth, skipMissingFiles, }?: {
|
|
5
5
|
enableSkipAuth?: boolean;
|
|
6
|
+
skipMissingFiles?: boolean;
|
|
6
7
|
}): Promise<PlasmicContext>;
|
|
7
8
|
/**
|
|
8
9
|
* Table of where this metadata will be set
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.300",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"wrap-ansi": "^7.0.0",
|
|
79
79
|
"yargs": "^15.4.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "d77514328c5ed3df3af84ff5c9f35f351fc1c276"
|
|
82
82
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { CommonArgs } from "..";
|
|
2
|
+
import { GLOBAL_SETTINGS } from "../globals";
|
|
2
3
|
import { fixAllImportStatements } from "../utils/code-utils";
|
|
3
4
|
import { updateConfig } from "../utils/config-utils";
|
|
4
5
|
import { getContext } from "../utils/get-context";
|
|
5
6
|
|
|
6
|
-
export interface FixImportsArgs extends CommonArgs {
|
|
7
|
+
export interface FixImportsArgs extends CommonArgs {
|
|
8
|
+
skipFormatting?: boolean;
|
|
9
|
+
}
|
|
7
10
|
export async function fixImports(opts: FixImportsArgs) {
|
|
8
11
|
if (!opts.baseDir) opts.baseDir = process.cwd();
|
|
12
|
+
if (opts.skipFormatting) {
|
|
13
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
14
|
+
}
|
|
9
15
|
const context = await getContext(opts, { enableSkipAuth: true });
|
|
10
16
|
await updateConfig(context, context.config, opts.baseDir);
|
|
11
17
|
await fixAllImportStatements(context, opts.baseDir);
|
package/src/actions/info.ts
CHANGED
|
@@ -4,17 +4,25 @@ import { getContext } from "../utils/get-context";
|
|
|
4
4
|
|
|
5
5
|
export interface InfoArgs extends CommonArgs {
|
|
6
6
|
projects: readonly string[];
|
|
7
|
+
json?: boolean;
|
|
8
|
+
host?: string;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export async function printProjectInfo(opts: InfoArgs): Promise<void> {
|
|
10
|
-
let context = await getContext(opts);
|
|
12
|
+
let context = await getContext(opts, { skipMissingFiles: true });
|
|
11
13
|
const results = await Promise.all(
|
|
12
14
|
opts.projects.map(async (p) => await context.api.projectMeta(p))
|
|
13
15
|
);
|
|
14
|
-
|
|
15
|
-
logger.info(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (opts.json) {
|
|
17
|
+
logger.info(JSON.stringify(results, null, 2));
|
|
18
|
+
} else {
|
|
19
|
+
for (const meta of results) {
|
|
20
|
+
logger.info(`Id: ${meta.id}`);
|
|
21
|
+
logger.info(`Name: ${meta.name}`);
|
|
22
|
+
logger.info(`Host URL: ${meta.hostUrl ?? null}`);
|
|
23
|
+
logger.info(
|
|
24
|
+
`Last published version: ${meta.lastPublishedVersion ?? null}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
28
|
}
|
package/src/actions/sync.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
StyleConfigResponse,
|
|
13
13
|
} from "../api";
|
|
14
14
|
import { logger } from "../deps";
|
|
15
|
+
import { GLOBAL_SETTINGS } from "../globals";
|
|
15
16
|
import { getChecksums } from "../utils/checksum";
|
|
16
17
|
import {
|
|
17
18
|
ComponentUpdateSummary,
|
|
@@ -21,12 +22,12 @@ import {
|
|
|
21
22
|
} from "../utils/code-utils";
|
|
22
23
|
import {
|
|
23
24
|
CONFIG_FILE_NAME,
|
|
24
|
-
createProjectConfig,
|
|
25
|
-
getOrAddProjectConfig,
|
|
26
|
-
getOrAddProjectLock,
|
|
27
25
|
LOADER_CONFIG_FILE_NAME,
|
|
28
26
|
PlasmicContext,
|
|
29
27
|
PlasmicLoaderConfig,
|
|
28
|
+
createProjectConfig,
|
|
29
|
+
getOrAddProjectConfig,
|
|
30
|
+
getOrAddProjectLock,
|
|
30
31
|
updateConfig,
|
|
31
32
|
} from "../utils/config-utils";
|
|
32
33
|
import { HandledError } from "../utils/error";
|
|
@@ -41,7 +42,7 @@ import {
|
|
|
41
42
|
writeFileContent,
|
|
42
43
|
writeFileText,
|
|
43
44
|
} from "../utils/file-utils";
|
|
44
|
-
import { generateMetadata, getContext
|
|
45
|
+
import { Metadata, generateMetadata, getContext } from "../utils/get-context";
|
|
45
46
|
import { printFirstSyncInfo } from "../utils/help";
|
|
46
47
|
import { ensure, tuple } from "../utils/lang-utils";
|
|
47
48
|
import {
|
|
@@ -73,6 +74,7 @@ export interface SyncArgs extends CommonArgs {
|
|
|
73
74
|
metadata?: string;
|
|
74
75
|
allFiles?: boolean;
|
|
75
76
|
loaderConfig?: string;
|
|
77
|
+
skipFormatting?: boolean;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
async function ensureRequiredPackages(
|
|
@@ -198,6 +200,10 @@ export async function sync(
|
|
|
198
200
|
const baseDir = opts.baseDir;
|
|
199
201
|
let context = await getContext(opts, { enableSkipAuth: true });
|
|
200
202
|
|
|
203
|
+
if (opts.skipFormatting) {
|
|
204
|
+
GLOBAL_SETTINGS.skipFormatting = true;
|
|
205
|
+
}
|
|
206
|
+
|
|
201
207
|
const isFirstRun = context.config.projects.length === 0;
|
|
202
208
|
|
|
203
209
|
if (!opts.skipUpgradeCheck) {
|
package/src/globals.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -136,19 +136,35 @@ yargs
|
|
|
136
136
|
.command<FixImportsArgs>(
|
|
137
137
|
"fix-imports",
|
|
138
138
|
"Fixes import paths after you've moved around Plasmic blackbox files",
|
|
139
|
-
(yags) =>
|
|
139
|
+
(yags) =>
|
|
140
|
+
yags.option("skip-formatting", {
|
|
141
|
+
type: "boolean",
|
|
142
|
+
describe: "Skip formatting of modified code",
|
|
143
|
+
default: false,
|
|
144
|
+
}),
|
|
140
145
|
(argv) => handleError(fixImports(argv))
|
|
141
146
|
)
|
|
142
147
|
.command<InfoArgs>(
|
|
143
148
|
"info",
|
|
144
149
|
"Fetches metadata for projects",
|
|
145
150
|
(yags) =>
|
|
146
|
-
yags
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
yags
|
|
152
|
+
.option("host", {
|
|
153
|
+
describe: "Plasmic host to use",
|
|
154
|
+
type: "string",
|
|
155
|
+
default: "https://studio.plasmic.app",
|
|
156
|
+
})
|
|
157
|
+
.option("projects", {
|
|
158
|
+
alias: "p",
|
|
159
|
+
describe: "ID of plasmic project to check",
|
|
160
|
+
type: "array",
|
|
161
|
+
default: [],
|
|
162
|
+
})
|
|
163
|
+
.option("json", {
|
|
164
|
+
describe: "Output full info, not just summary, in JSON format",
|
|
165
|
+
type: "boolean",
|
|
166
|
+
default: false,
|
|
167
|
+
}),
|
|
152
168
|
(argv) => {
|
|
153
169
|
handleError(printProjectInfo(argv));
|
|
154
170
|
}
|
|
@@ -345,6 +361,11 @@ function configureSyncArgs(
|
|
|
345
361
|
default: "source=cli",
|
|
346
362
|
hidden: true,
|
|
347
363
|
})
|
|
364
|
+
.option("skip-formatting", {
|
|
365
|
+
type: "boolean",
|
|
366
|
+
describe: "Disables formatting on generated code",
|
|
367
|
+
default: false,
|
|
368
|
+
})
|
|
348
369
|
.option("all-files", {
|
|
349
370
|
type: "boolean",
|
|
350
371
|
describe:
|
package/src/utils/checksum.ts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { SyncArgs } from "../actions/sync";
|
|
2
2
|
import { ChecksumBundle } from "../api";
|
|
3
|
-
import { PlasmicContext } from "./config-utils";
|
|
3
|
+
import { PlasmicContext, ProjectConfig } from "./config-utils";
|
|
4
|
+
import { fileExists } from "./file-utils";
|
|
4
5
|
import { assert } from "./lang-utils";
|
|
5
6
|
|
|
7
|
+
function getFilesByFileLockAssetId(
|
|
8
|
+
context: PlasmicContext,
|
|
9
|
+
projectConfig: ProjectConfig
|
|
10
|
+
) {
|
|
11
|
+
return {
|
|
12
|
+
renderModule: Object.fromEntries(
|
|
13
|
+
projectConfig.components.map((c) => [c.id, c.renderModuleFilePath])
|
|
14
|
+
),
|
|
15
|
+
cssRules: Object.fromEntries(
|
|
16
|
+
projectConfig.components.map((c) => [c.id, c.cssFilePath])
|
|
17
|
+
),
|
|
18
|
+
icon: Object.fromEntries(
|
|
19
|
+
projectConfig.icons.map((i) => [i.id, i.moduleFilePath])
|
|
20
|
+
),
|
|
21
|
+
image: Object.fromEntries(
|
|
22
|
+
projectConfig.images.map((i) => [i.id, i.filePath])
|
|
23
|
+
),
|
|
24
|
+
projectCss: { [projectConfig.projectId]: projectConfig.cssFilePath },
|
|
25
|
+
globalVariant: Object.fromEntries(
|
|
26
|
+
context.config.globalVariants.variantGroups
|
|
27
|
+
.filter((vg) => vg.projectId === projectConfig.projectId)
|
|
28
|
+
.map((vg) => [vg.id, vg.contextFilePath])
|
|
29
|
+
),
|
|
30
|
+
globalContext: {
|
|
31
|
+
[projectConfig.projectId]: projectConfig.globalContextsFilePath,
|
|
32
|
+
},
|
|
33
|
+
} as const;
|
|
34
|
+
}
|
|
35
|
+
|
|
6
36
|
export function getChecksums(
|
|
7
37
|
context: PlasmicContext,
|
|
8
38
|
opts: SyncArgs,
|
|
@@ -29,6 +59,15 @@ export function getChecksums(
|
|
|
29
59
|
};
|
|
30
60
|
}
|
|
31
61
|
|
|
62
|
+
// We only use checksum for files that actually exist on disk
|
|
63
|
+
const fileLocations = getFilesByFileLockAssetId(context, projectConfig);
|
|
64
|
+
const checkFile = (file: string | undefined) => {
|
|
65
|
+
if (!file) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return fileExists(context, file);
|
|
69
|
+
};
|
|
70
|
+
|
|
32
71
|
const fileLocks = projectLock.fileLocks;
|
|
33
72
|
|
|
34
73
|
const knownImages = new Set(projectConfig.images.map((i) => i.id));
|
|
@@ -39,9 +78,6 @@ export function getChecksums(
|
|
|
39
78
|
.filter((vg) => vg.projectId === projectId)
|
|
40
79
|
.map((vg) => vg.id)
|
|
41
80
|
);
|
|
42
|
-
const knownThemes = new Set(
|
|
43
|
-
(projectConfig.jsBundleThemes || []).map((theme) => theme.bundleName)
|
|
44
|
-
);
|
|
45
81
|
|
|
46
82
|
const toBeSyncedComponents = new Set(componentIds);
|
|
47
83
|
|
|
@@ -50,6 +86,7 @@ export function getChecksums(
|
|
|
50
86
|
(fileLock) =>
|
|
51
87
|
fileLock.type === "image" && knownImages.has(fileLock.assetId)
|
|
52
88
|
)
|
|
89
|
+
.filter((fileLock) => checkFile(fileLocations.image[fileLock.assetId]))
|
|
53
90
|
.map((fileLock): [string, string] => [fileLock.assetId, fileLock.checksum]);
|
|
54
91
|
|
|
55
92
|
const iconChecksums = fileLocks
|
|
@@ -59,6 +96,7 @@ export function getChecksums(
|
|
|
59
96
|
fileLock.type === "icon" &&
|
|
60
97
|
knownIcons.has(fileLock.assetId)
|
|
61
98
|
)
|
|
99
|
+
.filter((fileLock) => checkFile(fileLocations.icon[fileLock.assetId]))
|
|
62
100
|
.map((fileLock): [string, string] => [fileLock.assetId, fileLock.checksum]);
|
|
63
101
|
|
|
64
102
|
const renderModuleChecksums = fileLocks
|
|
@@ -69,6 +107,9 @@ export function getChecksums(
|
|
|
69
107
|
toBeSyncedComponents.has(fileLock.assetId) &&
|
|
70
108
|
knownComponents.has(fileLock.assetId)
|
|
71
109
|
)
|
|
110
|
+
.filter((fileLock) =>
|
|
111
|
+
checkFile(fileLocations.renderModule[fileLock.assetId])
|
|
112
|
+
)
|
|
72
113
|
.map((fileLock): [string, string] => [fileLock.assetId, fileLock.checksum]);
|
|
73
114
|
|
|
74
115
|
const cssRulesChecksums = fileLocks
|
|
@@ -78,6 +119,7 @@ export function getChecksums(
|
|
|
78
119
|
toBeSyncedComponents.has(fileLock.assetId) &&
|
|
79
120
|
knownComponents.has(fileLock.assetId)
|
|
80
121
|
)
|
|
122
|
+
.filter((fileLock) => checkFile(fileLocations.cssRules[fileLock.assetId]))
|
|
81
123
|
.map((fileLock): [string, string] => [fileLock.assetId, fileLock.checksum]);
|
|
82
124
|
|
|
83
125
|
const globalVariantChecksums = fileLocks
|
|
@@ -87,19 +129,28 @@ export function getChecksums(
|
|
|
87
129
|
fileLock.type === "globalVariant" &&
|
|
88
130
|
knownGlobalVariants.has(fileLock.assetId)
|
|
89
131
|
)
|
|
132
|
+
.filter((fileLock) =>
|
|
133
|
+
checkFile(fileLocations.globalVariant[fileLock.assetId])
|
|
134
|
+
)
|
|
90
135
|
.map((fileLock): [string, string] => [fileLock.assetId, fileLock.checksum]);
|
|
91
136
|
|
|
92
|
-
const projectCssChecksums = fileLocks
|
|
93
|
-
(fileLock) => fileLock.type === "projectCss"
|
|
94
|
-
|
|
137
|
+
const projectCssChecksums = fileLocks
|
|
138
|
+
.filter((fileLock) => fileLock.type === "projectCss")
|
|
139
|
+
.filter((fileLock) =>
|
|
140
|
+
checkFile(fileLocations.projectCss[fileLock.assetId])
|
|
141
|
+
);
|
|
95
142
|
assert(projectCssChecksums.length < 2);
|
|
96
143
|
const projectCssChecksum =
|
|
97
144
|
projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
|
|
98
145
|
|
|
99
|
-
const globalContextsChecksums = fileLocks
|
|
100
|
-
(
|
|
101
|
-
fileLock
|
|
102
|
-
|
|
146
|
+
const globalContextsChecksums = fileLocks
|
|
147
|
+
.filter(
|
|
148
|
+
(fileLock) =>
|
|
149
|
+
fileLock.type === "globalContexts" && fileLock.assetId === projectId
|
|
150
|
+
)
|
|
151
|
+
.filter((fileLock) =>
|
|
152
|
+
checkFile(fileLocations.globalContext[fileLock.assetId])
|
|
153
|
+
);
|
|
103
154
|
assert(globalContextsChecksums.length < 2);
|
|
104
155
|
const globalContextsChecksum =
|
|
105
156
|
globalContextsChecksums.length > 0
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
writeFileContent,
|
|
35
35
|
} from "./file-utils";
|
|
36
36
|
import { assert, flatMap } from "./lang-utils";
|
|
37
|
+
import { GLOBAL_SETTINGS } from "../globals";
|
|
37
38
|
|
|
38
39
|
export const formatAsLocal = (
|
|
39
40
|
content: string,
|
|
@@ -41,6 +42,9 @@ export const formatAsLocal = (
|
|
|
41
42
|
baseDir: string,
|
|
42
43
|
defaultOpts: Options = {}
|
|
43
44
|
) => {
|
|
45
|
+
if (GLOBAL_SETTINGS.skipFormatting) {
|
|
46
|
+
return content;
|
|
47
|
+
}
|
|
44
48
|
// TODO: we used to use resolveConfig.sync() to try to use local prettier,
|
|
45
49
|
// but this ended up using unrelated prettier config higher up the stack,
|
|
46
50
|
// which dangerously may remove unused imports like
|
package/src/utils/get-context.ts
CHANGED
|
@@ -286,7 +286,10 @@ async function resolveMissingFilesInConfig(
|
|
|
286
286
|
|
|
287
287
|
export async function getContext(
|
|
288
288
|
args: CommonArgs,
|
|
289
|
-
{
|
|
289
|
+
{
|
|
290
|
+
enableSkipAuth = false,
|
|
291
|
+
skipMissingFiles = false,
|
|
292
|
+
}: { enableSkipAuth?: boolean; skipMissingFiles?: boolean } = {}
|
|
290
293
|
): Promise<PlasmicContext> {
|
|
291
294
|
if (!args.baseDir) args.baseDir = process.cwd();
|
|
292
295
|
const auth = enableSkipAuth
|
|
@@ -297,8 +300,7 @@ export async function getContext(
|
|
|
297
300
|
if (auth.host.startsWith(DEFAULT_HOST)) {
|
|
298
301
|
// Production usage of cli
|
|
299
302
|
Sentry.init({
|
|
300
|
-
dsn:
|
|
301
|
-
"https://3ed4eb43d28646e381bf3c50cff24bd6@o328029.ingest.sentry.io/5285892",
|
|
303
|
+
dsn: "https://3ed4eb43d28646e381bf3c50cff24bd6@o328029.ingest.sentry.io/5285892",
|
|
302
304
|
});
|
|
303
305
|
Sentry.configureScope((scope) => {
|
|
304
306
|
if (auth.user) {
|
|
@@ -348,8 +350,10 @@ export async function getContext(
|
|
|
348
350
|
cliArgs: args,
|
|
349
351
|
};
|
|
350
352
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
+
if (!skipMissingFiles) {
|
|
354
|
+
await resolveMissingFilesInConfig(context, config);
|
|
355
|
+
removeMissingFilesFromLock(context, config, lock);
|
|
356
|
+
}
|
|
353
357
|
|
|
354
358
|
return context;
|
|
355
359
|
}
|