@plasmicapp/cli 0.1.162
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/.eslintrc.js +61 -0
- package/.idea/cli.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +16 -0
- package/README.internal +46 -0
- package/README.md +17 -0
- package/build.sh +8 -0
- package/dist/__mocks__/api.d.ts +16 -0
- package/dist/__mocks__/api.js +297 -0
- package/dist/__tests__/code-utils-spec.d.ts +1 -0
- package/dist/__tests__/code-utils-spec.js +838 -0
- package/dist/__tests__/ftue-spec.d.ts +1 -0
- package/dist/__tests__/ftue-spec.js +39 -0
- package/dist/__tests__/project-api-token-spec.d.ts +1 -0
- package/dist/__tests__/project-api-token-spec.js +147 -0
- package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
- package/dist/__tests__/versioned-sync-spec.js +145 -0
- package/dist/actions/auth.d.ts +8 -0
- package/dist/actions/auth.js +47 -0
- package/dist/actions/fix-imports.d.ts +4 -0
- package/dist/actions/fix-imports.js +25 -0
- package/dist/actions/init.d.ts +62 -0
- package/dist/actions/init.js +460 -0
- package/dist/actions/project-token.d.ts +6 -0
- package/dist/actions/project-token.js +42 -0
- package/dist/actions/sync-components.d.ts +10 -0
- package/dist/actions/sync-components.js +242 -0
- package/dist/actions/sync-global-variants.d.ts +3 -0
- package/dist/actions/sync-global-variants.js +89 -0
- package/dist/actions/sync-icons.d.ts +7 -0
- package/dist/actions/sync-icons.js +92 -0
- package/dist/actions/sync-images.d.ts +6 -0
- package/dist/actions/sync-images.js +137 -0
- package/dist/actions/sync-styles.d.ts +3 -0
- package/dist/actions/sync-styles.js +58 -0
- package/dist/actions/sync.d.ts +25 -0
- package/dist/actions/sync.js +417 -0
- package/dist/actions/upload-bundle.d.ts +15 -0
- package/dist/actions/upload-bundle.js +28 -0
- package/dist/actions/watch.d.ts +14 -0
- package/dist/actions/watch.js +90 -0
- package/dist/api.d.ts +182 -0
- package/dist/api.js +202 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +247 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +23 -0
- package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
- package/dist/migrations/0.1.110-fileLocks.js +15 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
- package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
- package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
- package/dist/migrations/0.1.27-migrateInit.js +8 -0
- package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
- package/dist/migrations/0.1.28-tsToTsx.js +33 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
- package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
- package/dist/migrations/0.1.42-ensureVersion.js +12 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
- package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
- package/dist/migrations/0.1.64-imageFiles.js +17 -0
- package/dist/migrations/0.1.95-componentType.d.ts +2 -0
- package/dist/migrations/0.1.95-componentType.js +16 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +119 -0
- package/dist/plasmic.schema.json +463 -0
- package/dist/test-common/fixtures.d.ts +13 -0
- package/dist/test-common/fixtures.js +165 -0
- package/dist/tsconfig-transform.json +68 -0
- package/dist/utils/auth-utils.d.ts +31 -0
- package/dist/utils/auth-utils.js +236 -0
- package/dist/utils/checksum.d.ts +4 -0
- package/dist/utils/checksum.js +63 -0
- package/dist/utils/code-utils.d.ts +46 -0
- package/dist/utils/code-utils.js +457 -0
- package/dist/utils/config-utils.d.ts +271 -0
- package/dist/utils/config-utils.js +178 -0
- package/dist/utils/envdetect.d.ts +4 -0
- package/dist/utils/envdetect.js +42 -0
- package/dist/utils/error.d.ts +14 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/file-utils.d.ts +71 -0
- package/dist/utils/file-utils.js +433 -0
- package/dist/utils/get-context.d.ts +40 -0
- package/dist/utils/get-context.js +339 -0
- package/dist/utils/help.d.ts +2 -0
- package/dist/utils/help.js +56 -0
- package/dist/utils/lang-utils.d.ts +10 -0
- package/dist/utils/lang-utils.js +52 -0
- package/dist/utils/npm-utils.d.ts +28 -0
- package/dist/utils/npm-utils.js +215 -0
- package/dist/utils/prompts.d.ts +6 -0
- package/dist/utils/prompts.js +23 -0
- package/dist/utils/resolve-utils.d.ts +13 -0
- package/dist/utils/resolve-utils.js +198 -0
- package/dist/utils/semver.d.ts +34 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/test-utils.d.ts +22 -0
- package/dist/utils/test-utils.js +106 -0
- package/dist/utils/user-utils.d.ts +7 -0
- package/dist/utils/user-utils.js +48 -0
- package/jest.config.js +6 -0
- package/package.json +80 -0
- package/src/__mocks__/api.ts +394 -0
- package/src/__tests__/code-utils-spec.ts +881 -0
- package/src/__tests__/ftue-spec.ts +43 -0
- package/src/__tests__/project-api-token-spec.ts +208 -0
- package/src/__tests__/versioned-sync-spec.ts +176 -0
- package/src/actions/auth.ts +43 -0
- package/src/actions/fix-imports.ts +13 -0
- package/src/actions/init.ts +638 -0
- package/src/actions/project-token.ts +36 -0
- package/src/actions/sync-components.ts +405 -0
- package/src/actions/sync-global-variants.ts +129 -0
- package/src/actions/sync-icons.ts +135 -0
- package/src/actions/sync-images.ts +191 -0
- package/src/actions/sync-styles.ts +71 -0
- package/src/actions/sync.ts +747 -0
- package/src/actions/upload-bundle.ts +38 -0
- package/src/actions/watch.ts +95 -0
- package/src/api.ts +407 -0
- package/src/deps.ts +18 -0
- package/src/index.ts +300 -0
- package/src/lib.ts +10 -0
- package/src/migrations/0.1.110-fileLocks.ts +16 -0
- package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
- package/src/migrations/0.1.27-migrateInit.ts +4 -0
- package/src/migrations/0.1.28-tsToTsx.ts +37 -0
- package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
- package/src/migrations/0.1.42-ensureVersion.ts +10 -0
- package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
- package/src/migrations/0.1.64-imageFiles.ts +15 -0
- package/src/migrations/0.1.95-componentType.ts +14 -0
- package/src/migrations/migrations.ts +147 -0
- package/src/test-common/fixtures.ts +178 -0
- package/src/utils/auth-utils.ts +276 -0
- package/src/utils/checksum.ts +106 -0
- package/src/utils/code-utils.ts +656 -0
- package/src/utils/config-utils.ts +551 -0
- package/src/utils/envdetect.ts +39 -0
- package/src/utils/error.ts +36 -0
- package/src/utils/file-utils.ts +526 -0
- package/src/utils/get-context.ts +451 -0
- package/src/utils/help.ts +75 -0
- package/src/utils/lang-utils.ts +52 -0
- package/src/utils/npm-utils.ts +223 -0
- package/src/utils/prompts.ts +22 -0
- package/src/utils/resolve-utils.ts +245 -0
- package/src/utils/semver.ts +67 -0
- package/src/utils/test-utils.ts +116 -0
- package/src/utils/user-utils.ts +37 -0
- package/testData/fixImports_plasmic.json +66 -0
- package/tsconfig-transform.json +68 -0
- package/tsconfig.json +67 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import L from "lodash";
|
|
2
|
+
import path from "upath";
|
|
3
|
+
import { ChecksumBundle, ImageBundle } from "../api";
|
|
4
|
+
import { logger } from "../deps";
|
|
5
|
+
import { FixImportContext } from "../utils/code-utils";
|
|
6
|
+
import {
|
|
7
|
+
getOrAddProjectConfig,
|
|
8
|
+
getOrAddProjectLock,
|
|
9
|
+
PlasmicContext,
|
|
10
|
+
} from "../utils/config-utils";
|
|
11
|
+
import {
|
|
12
|
+
defaultPublicResourcePath,
|
|
13
|
+
defaultResourcePath,
|
|
14
|
+
deleteFile,
|
|
15
|
+
fileExists,
|
|
16
|
+
readFileContent,
|
|
17
|
+
renameFile,
|
|
18
|
+
writeFileContent,
|
|
19
|
+
} from "../utils/file-utils";
|
|
20
|
+
import { ensure } from "../utils/lang-utils";
|
|
21
|
+
|
|
22
|
+
export async function syncProjectImageAssets(
|
|
23
|
+
context: PlasmicContext,
|
|
24
|
+
projectId: string,
|
|
25
|
+
version: string,
|
|
26
|
+
imageBundles: ImageBundle[],
|
|
27
|
+
checksums: ChecksumBundle
|
|
28
|
+
) {
|
|
29
|
+
const project = getOrAddProjectConfig(context, projectId);
|
|
30
|
+
const projectLock = getOrAddProjectLock(context, projectId);
|
|
31
|
+
const knownImageConfigs = L.keyBy(project.images, (i) => i.id);
|
|
32
|
+
const imageBundleIds = L.keyBy(imageBundles, (i) => i.id);
|
|
33
|
+
const imageFileLocks = L.keyBy(
|
|
34
|
+
projectLock.fileLocks.filter((fileLock) => fileLock.type === "image"),
|
|
35
|
+
(fl) => fl.assetId
|
|
36
|
+
);
|
|
37
|
+
const id2ImageChecksum = new Map(checksums.imageChecksums);
|
|
38
|
+
|
|
39
|
+
const deletedImages = L.filter(
|
|
40
|
+
knownImageConfigs,
|
|
41
|
+
(i) => !imageBundleIds[i.id] && !id2ImageChecksum.has(i.id)
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
for (const bundle of imageBundles) {
|
|
45
|
+
if (context.cliArgs.quiet !== true) {
|
|
46
|
+
logger.info(
|
|
47
|
+
`Syncing image: ${bundle.name}@${version}\t['${project.projectName}' ${project.projectId}/${bundle.id} ${project.version}]`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
let imageConfig = knownImageConfigs[bundle.id];
|
|
51
|
+
const isNew = !imageConfig;
|
|
52
|
+
const defaultFilePath =
|
|
53
|
+
context.config.images.scheme === "public-files"
|
|
54
|
+
? defaultPublicResourcePath(context, project, "images", bundle.fileName)
|
|
55
|
+
: defaultResourcePath(context, project, "images", bundle.fileName);
|
|
56
|
+
if (isNew) {
|
|
57
|
+
imageConfig = {
|
|
58
|
+
id: bundle.id,
|
|
59
|
+
name: bundle.name,
|
|
60
|
+
filePath: defaultFilePath,
|
|
61
|
+
};
|
|
62
|
+
project.images.push(imageConfig);
|
|
63
|
+
} else {
|
|
64
|
+
const filePath = path.join(
|
|
65
|
+
path.dirname(imageConfig.filePath),
|
|
66
|
+
path.basename(defaultFilePath)
|
|
67
|
+
);
|
|
68
|
+
if (
|
|
69
|
+
imageConfig.filePath !== filePath &&
|
|
70
|
+
fileExists(context, imageConfig.filePath)
|
|
71
|
+
) {
|
|
72
|
+
if (context.cliArgs.quiet !== true) {
|
|
73
|
+
logger.info(
|
|
74
|
+
`Renaming image: ${imageConfig.name}@${version}\t['${project.projectName}' ${project.projectId}/${bundle.id} ${project.version}]`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
renameFile(context, imageConfig.filePath, filePath);
|
|
78
|
+
imageConfig.filePath = filePath;
|
|
79
|
+
}
|
|
80
|
+
imageConfig.name = bundle.name;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Update FileLocks
|
|
84
|
+
if (imageFileLocks[bundle.id]) {
|
|
85
|
+
imageFileLocks[bundle.id].checksum = ensure(
|
|
86
|
+
id2ImageChecksum.get(bundle.id)
|
|
87
|
+
);
|
|
88
|
+
} else {
|
|
89
|
+
projectLock.fileLocks.push({
|
|
90
|
+
type: "image",
|
|
91
|
+
assetId: bundle.id,
|
|
92
|
+
checksum: ensure(id2ImageChecksum.get(bundle.id)),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await writeFileContent(
|
|
97
|
+
context,
|
|
98
|
+
imageConfig.filePath,
|
|
99
|
+
Buffer.from(bundle.blob, "base64"),
|
|
100
|
+
{
|
|
101
|
+
force: !isNew,
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const deletedImageFiles = new Set<string>();
|
|
107
|
+
for (const deletedImage of deletedImages) {
|
|
108
|
+
const imageConfig = knownImageConfigs[deletedImage.id];
|
|
109
|
+
if (fileExists(context, imageConfig.filePath)) {
|
|
110
|
+
logger.info(
|
|
111
|
+
`Deleting image: ${imageConfig.name}@${version}\t['${project.projectName}' ${project.projectId}/${deletedImage.id} ${project.version}]`
|
|
112
|
+
);
|
|
113
|
+
deleteFile(context, imageConfig.filePath);
|
|
114
|
+
deletedImageFiles.add(deletedImage.id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
project.images = project.images.filter((i) => !deletedImageFiles.has(i.id));
|
|
118
|
+
|
|
119
|
+
const deletedImageIds = new Set(deletedImages.map((i) => i.id));
|
|
120
|
+
projectLock.fileLocks = projectLock.fileLocks.filter(
|
|
121
|
+
(fileLock) =>
|
|
122
|
+
fileLock.type !== "image" || !deletedImageIds.has(fileLock.assetId)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const RE_ASSETCSSREF_ALL = /var\(--image-([^\)]+)\)/g;
|
|
127
|
+
export async function fixComponentCssReferences(
|
|
128
|
+
context: PlasmicContext,
|
|
129
|
+
fixImportContext: FixImportContext,
|
|
130
|
+
cssFilePath: string
|
|
131
|
+
) {
|
|
132
|
+
if (!fileExists(context, cssFilePath)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const prevContent = readFileContent(context, cssFilePath);
|
|
137
|
+
const newContent = prevContent.replace(RE_ASSETCSSREF_ALL, (sub, assetId) => {
|
|
138
|
+
const asset = fixImportContext.images[assetId];
|
|
139
|
+
if (asset) {
|
|
140
|
+
return context.config.images.scheme === "public-files"
|
|
141
|
+
? `url("${path.join(
|
|
142
|
+
"/",
|
|
143
|
+
ensure(context.config.images.publicUrlPrefix),
|
|
144
|
+
path.relative(
|
|
145
|
+
ensure(context.config.images.publicDir),
|
|
146
|
+
asset.filePath
|
|
147
|
+
)
|
|
148
|
+
)}")`
|
|
149
|
+
: `url("./${path.relative(
|
|
150
|
+
path.dirname(cssFilePath),
|
|
151
|
+
asset.filePath
|
|
152
|
+
)}")`;
|
|
153
|
+
} else {
|
|
154
|
+
return sub;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (prevContent !== newContent) {
|
|
159
|
+
await writeFileContent(context, cssFilePath, newContent, { force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const RE_ASSETTSXREF_ALL = /Plasmic_Image_([^\)\s]+)__Ref/g;
|
|
164
|
+
export async function fixComponentImagesReferences(
|
|
165
|
+
context: PlasmicContext,
|
|
166
|
+
fixImportContext: FixImportContext,
|
|
167
|
+
renderModuleFilePath: string
|
|
168
|
+
) {
|
|
169
|
+
const prevContent = readFileContent(context, renderModuleFilePath);
|
|
170
|
+
const newContent = prevContent.replace(RE_ASSETTSXREF_ALL, (sub, assetId) => {
|
|
171
|
+
const asset = fixImportContext.images[assetId];
|
|
172
|
+
if (asset) {
|
|
173
|
+
return path.join(
|
|
174
|
+
"/",
|
|
175
|
+
ensure(context.config.images.publicUrlPrefix),
|
|
176
|
+
path.relative(ensure(context.config.images.publicDir), asset.filePath)
|
|
177
|
+
);
|
|
178
|
+
} else {
|
|
179
|
+
return sub;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
if (prevContent !== newContent) {
|
|
184
|
+
await writeFileContent(context, renderModuleFilePath, newContent, {
|
|
185
|
+
force: true,
|
|
186
|
+
});
|
|
187
|
+
// Returns true if the content changed
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { StyleTokensMap } from "../api";
|
|
2
|
+
import { PlasmicContext } from "../utils/config-utils";
|
|
3
|
+
import { HandledError } from "../utils/error";
|
|
4
|
+
import {
|
|
5
|
+
fileExists,
|
|
6
|
+
readFileContent,
|
|
7
|
+
writeFileContent,
|
|
8
|
+
} from "../utils/file-utils";
|
|
9
|
+
|
|
10
|
+
export async function upsertStyleTokens(
|
|
11
|
+
context: PlasmicContext,
|
|
12
|
+
newStyleMap: StyleTokensMap
|
|
13
|
+
) {
|
|
14
|
+
const curStyleMap = await readCurStyleMap(context);
|
|
15
|
+
for (const prop of newStyleMap.props) {
|
|
16
|
+
const index = curStyleMap.props.findIndex(
|
|
17
|
+
(p) => p.meta.id === prop.meta.id
|
|
18
|
+
);
|
|
19
|
+
if (index >= 0) {
|
|
20
|
+
curStyleMap.props[index] = prop;
|
|
21
|
+
} else {
|
|
22
|
+
curStyleMap.props.push(prop);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
curStyleMap.props.sort((prop1, prop2) =>
|
|
26
|
+
prop1.name === prop2.name ? 0 : prop1.name < prop2.name ? -1 : 1
|
|
27
|
+
);
|
|
28
|
+
await writeFileContent(
|
|
29
|
+
context,
|
|
30
|
+
context.config.tokens.tokensFilePath,
|
|
31
|
+
|
|
32
|
+
JSON.stringify(curStyleMap, undefined, 2),
|
|
33
|
+
|
|
34
|
+
{ force: true }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function readCurStyleMap(
|
|
39
|
+
context: PlasmicContext
|
|
40
|
+
): Promise<StyleTokensMap> {
|
|
41
|
+
const filePath = context.config.tokens.tokensFilePath;
|
|
42
|
+
if (fileExists(context, filePath)) {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(
|
|
45
|
+
readFileContent(context, context.config.tokens.tokensFilePath)
|
|
46
|
+
);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new HandledError(
|
|
49
|
+
`Error encountered reading ${context.config.tokens.tokensFilePath}: ${e}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const defaultMap = {
|
|
54
|
+
props: [],
|
|
55
|
+
global: {
|
|
56
|
+
meta: {
|
|
57
|
+
source: "plasmic.app",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
} as StyleTokensMap;
|
|
61
|
+
await writeFileContent(
|
|
62
|
+
context,
|
|
63
|
+
context.config.tokens.tokensFilePath,
|
|
64
|
+
JSON.stringify(defaultMap, undefined, 2),
|
|
65
|
+
{
|
|
66
|
+
force: false,
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
return defaultMap;
|
|
70
|
+
}
|
|
71
|
+
}
|