@plasmicapp/cli 0.1.170 → 0.1.174
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.js +2 -2
- package/dist/actions/info.d.ts +5 -0
- package/dist/actions/info.js +28 -0
- package/dist/actions/sync.js +16 -6
- package/dist/api.d.ts +8 -0
- package/dist/api.js +6 -0
- package/dist/index.js +9 -0
- package/dist/plasmic.schema.json +3 -0
- package/dist/utils/code-utils.js +2 -1
- package/dist/utils/config-utils.d.ts +1 -0
- package/dist/utils/file-utils.d.ts +0 -5
- package/dist/utils/file-utils.js +1 -32
- package/dist/utils/get-context.js +14 -3
- package/package.json +2 -2
- package/src/actions/fix-imports.ts +2 -3
- package/src/actions/info.ts +20 -0
- package/src/actions/sync.ts +20 -6
- package/src/api.ts +15 -0
- package/src/index.ts +15 -0
- package/src/utils/code-utils.ts +1 -0
- package/src/utils/config-utils.ts +2 -0
- package/src/utils/file-utils.ts +0 -41
- package/src/utils/get-context.ts +15 -3
|
@@ -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,28 @@
|
|
|
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
|
+
var _a, _b;
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
let context = yield get_context_1.getContext(opts);
|
|
19
|
+
const results = yield Promise.all(opts.projects.map((p) => __awaiter(this, void 0, void 0, function* () { return yield context.api.projectMeta(p); })));
|
|
20
|
+
for (const meta of results) {
|
|
21
|
+
deps_1.logger.info(`Id: ${meta.id}`);
|
|
22
|
+
deps_1.logger.info(`Name: ${meta.name}`);
|
|
23
|
+
deps_1.logger.info(`Host URL: ${(_a = meta.hostUrl) !== null && _a !== void 0 ? _a : null}`);
|
|
24
|
+
deps_1.logger.info(`Last published version: ${(_b = meta.lastPublishedVersion) !== null && _b !== void 0 ? _b : null}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.printProjectInfo = printProjectInfo;
|
package/dist/actions/sync.js
CHANGED
|
@@ -50,11 +50,11 @@ const resolve_utils_1 = require("../utils/resolve-utils");
|
|
|
50
50
|
const semver = __importStar(require("../utils/semver"));
|
|
51
51
|
const user_utils_1 = require("../utils/user-utils");
|
|
52
52
|
const sync_components_1 = require("./sync-components");
|
|
53
|
+
const sync_global_contexts_1 = require("./sync-global-contexts");
|
|
53
54
|
const sync_global_variants_1 = require("./sync-global-variants");
|
|
54
55
|
const sync_icons_1 = require("./sync-icons");
|
|
55
56
|
const sync_images_1 = require("./sync-images");
|
|
56
57
|
const sync_styles_1 = require("./sync-styles");
|
|
57
|
-
const sync_global_contexts_1 = require("./sync-global-contexts");
|
|
58
58
|
function ensureRequiredPackages(context, baseDir, yes) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
60
|
const requireds = yield context.api.requiredPackages();
|
|
@@ -302,23 +302,33 @@ function checkExternalPkgs(context, baseDir, opts, pkgs) {
|
|
|
302
302
|
}
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
|
-
function maybeRenamePathExt(context, path, ext) {
|
|
305
|
+
function maybeRenamePathExt(context, path, ext, opts) {
|
|
306
306
|
if (!path) {
|
|
307
307
|
return path;
|
|
308
308
|
}
|
|
309
309
|
const correctPath = `${file_utils_1.stripExtension(path, true)}${ext}`;
|
|
310
310
|
if (path !== correctPath) {
|
|
311
|
-
|
|
311
|
+
try {
|
|
312
|
+
file_utils_1.renameFile(context, path, correctPath);
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.continueOnFailure)) {
|
|
316
|
+
throw e;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
deps_1.logger.warn(e);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
312
322
|
}
|
|
313
323
|
return correctPath;
|
|
314
324
|
}
|
|
315
325
|
function fixFileExtension(context) {
|
|
316
326
|
const cssExt = context.config.style.scheme === "css-modules" ? ".module.css" : ".css";
|
|
317
|
-
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(context, context.config.style.defaultStyleCssFilePath, cssExt);
|
|
327
|
+
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(context, context.config.style.defaultStyleCssFilePath, cssExt, { continueOnFailure: true });
|
|
318
328
|
context.config.projects.forEach((project) => {
|
|
319
|
-
project.cssFilePath = maybeRenamePathExt(context, project.cssFilePath, cssExt);
|
|
329
|
+
project.cssFilePath = maybeRenamePathExt(context, project.cssFilePath, cssExt, { continueOnFailure: true });
|
|
320
330
|
project.components.forEach((component) => {
|
|
321
|
-
component.cssFilePath = maybeRenamePathExt(context, component.cssFilePath, cssExt);
|
|
331
|
+
component.cssFilePath = maybeRenamePathExt(context, component.cssFilePath, cssExt, { continueOnFailure: true });
|
|
322
332
|
});
|
|
323
333
|
});
|
|
324
334
|
}
|
package/dist/api.d.ts
CHANGED
|
@@ -76,6 +76,13 @@ export interface RequiredPackages {
|
|
|
76
76
|
"@plasmicapp/react-web": string;
|
|
77
77
|
"@plasmicapp/react-web-runtime": string;
|
|
78
78
|
}
|
|
79
|
+
export interface ProjectMetaInfo {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
workspaceId?: string;
|
|
83
|
+
hostUrl?: string;
|
|
84
|
+
lastPublishedVersion?: string;
|
|
85
|
+
}
|
|
79
86
|
export interface ProjectBundle {
|
|
80
87
|
components: ComponentBundle[];
|
|
81
88
|
codeComponentMetas: CodeComponentMeta[];
|
|
@@ -179,6 +186,7 @@ export declare class PlasmicApi {
|
|
|
179
186
|
indirect: boolean;
|
|
180
187
|
metadata?: Metadata;
|
|
181
188
|
}): Promise<ProjectBundle>;
|
|
189
|
+
projectMeta(projectId: string): Promise<ProjectMetaInfo>;
|
|
182
190
|
uploadBundle(projectId: string, bundleName: string, bundleJs: string, css: string[], metaJson: string, genModulePath: string | undefined, genCssPaths: string[], pkgVersion: string | undefined, extraPropMetaJson: string | undefined, themeProviderWrapper: string | undefined, themeModule: string | undefined): Promise<StyleTokensMap>;
|
|
183
191
|
projectStyleTokens(projectId: string, versionRange?: string): Promise<StyleTokensMap>;
|
|
184
192
|
projectIcons(projectId: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
|
package/dist/api.js
CHANGED
|
@@ -93,6 +93,12 @@ class PlasmicApi {
|
|
|
93
93
|
return result.data;
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
projectMeta(projectId) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/meta`);
|
|
99
|
+
return result.data;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
96
102
|
uploadBundle(projectId, bundleName, bundleJs, css, metaJson, genModulePath, genCssPaths, pkgVersion, extraPropMetaJson, themeProviderWrapper, themeModule) {
|
|
97
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
104
|
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/jsbundle/upload`, {
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const update_notifier_1 = __importDefault(require("update-notifier"));
|
|
|
28
28
|
const yargs_1 = __importDefault(require("yargs"));
|
|
29
29
|
const auth = __importStar(require("./actions/auth"));
|
|
30
30
|
const fix_imports_1 = require("./actions/fix-imports");
|
|
31
|
+
const info_1 = require("./actions/info");
|
|
31
32
|
const init_1 = require("./actions/init");
|
|
32
33
|
const projectToken = __importStar(require("./actions/project-token"));
|
|
33
34
|
const sync_1 = require("./actions/sync");
|
|
@@ -118,6 +119,14 @@ yargs_1.default
|
|
|
118
119
|
}));
|
|
119
120
|
})
|
|
120
121
|
.command("fix-imports", "Fixes import paths after you've moved around Plasmic blackbox files", (yags) => 0, (argv) => error_1.handleError(fix_imports_1.fixImports(argv)))
|
|
122
|
+
.command("info", "Fetches metadata for projects", (yags) => yags.option("projects", {
|
|
123
|
+
alias: "p",
|
|
124
|
+
describe: "ID of plasmic project to check",
|
|
125
|
+
type: "array",
|
|
126
|
+
default: [],
|
|
127
|
+
}), (argv) => {
|
|
128
|
+
error_1.handleError(info_1.printProjectInfo(argv));
|
|
129
|
+
})
|
|
121
130
|
.command("upload-bundle", false, (yargs) => yargs
|
|
122
131
|
.option("project", {
|
|
123
132
|
alias: "p",
|
package/dist/plasmic.schema.json
CHANGED
package/dist/utils/code-utils.js
CHANGED
|
@@ -350,7 +350,8 @@ exports.fixAllImportStatements = fixAllImportStatements;
|
|
|
350
350
|
function fixComponentImportStatements(context, compConfig, fixImportContext, fixSkeletonModule, baseDir) {
|
|
351
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
352
352
|
// If ComponentConfig.importPath is still a local file, we best-effort also fix up the import statements there.
|
|
353
|
-
if (
|
|
353
|
+
if (compConfig.type !== "mapped" &&
|
|
354
|
+
isLocalModulePath(compConfig.importSpec.modulePath) &&
|
|
354
355
|
fixSkeletonModule) {
|
|
355
356
|
yield fixFileImportStatements(context, compConfig.importSpec.modulePath, fixImportContext, true, baseDir);
|
|
356
357
|
}
|
|
@@ -73,6 +73,7 @@ export interface StyleConfig {
|
|
|
73
73
|
scheme: "css" | "css-modules";
|
|
74
74
|
/** File location for global css styles shared by all components. Relative to srcDir */
|
|
75
75
|
defaultStyleCssFilePath: string;
|
|
76
|
+
skipGlobalCssImport?: boolean;
|
|
76
77
|
}
|
|
77
78
|
export interface ImagesConfig {
|
|
78
79
|
/**
|
|
@@ -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"));
|
|
@@ -219,37 +219,6 @@ function getAllPaths(context) {
|
|
|
219
219
|
}
|
|
220
220
|
return pairs;
|
|
221
221
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
224
|
-
* movement on disk.
|
|
225
|
-
*/
|
|
226
|
-
function fixAllFilePaths(context, baseDir) {
|
|
227
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
const baseNameToFiles = buildBaseNameToFiles(context);
|
|
229
|
-
let changed = false;
|
|
230
|
-
const paths = getAllPaths(context);
|
|
231
|
-
for (const { bundle, key } of paths) {
|
|
232
|
-
const known = bundle[key];
|
|
233
|
-
// Check null and undefined
|
|
234
|
-
if (known == null) {
|
|
235
|
-
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}"`);
|
|
236
|
-
}
|
|
237
|
-
// Check falsey values (e.g. "")
|
|
238
|
-
if (!known) {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
const found = findSrcDirPath(context.absoluteSrcDir, known, baseNameToFiles);
|
|
242
|
-
if (known !== found) {
|
|
243
|
-
bundle[key] = found;
|
|
244
|
-
changed = true;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (changed) {
|
|
248
|
-
yield config_utils_1.updateConfig(context, context.config, baseDir);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
exports.fixAllFilePaths = fixAllFilePaths;
|
|
253
222
|
/**
|
|
254
223
|
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
255
224
|
* directory (i.e., the directory containing plasmic.json).
|
|
@@ -104,6 +104,14 @@ function removeMissingFilesFromLock(context, config, lock) {
|
|
|
104
104
|
return project;
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @param context
|
|
110
|
+
* @param expectedPath
|
|
111
|
+
* @param baseNameToFiles
|
|
112
|
+
* @returns The path if we are able to find the file, undefined if we need to recreate it
|
|
113
|
+
* @throws if the user interrupts flow
|
|
114
|
+
*/
|
|
107
115
|
function attemptToRestoreFilePath(context, expectedPath, baseNameToFiles) {
|
|
108
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
117
|
// If the path is not set, always recreate.
|
|
@@ -163,16 +171,19 @@ function resolveMissingFilesInConfig(context, config) {
|
|
|
163
171
|
});
|
|
164
172
|
}
|
|
165
173
|
context.config.globalVariants.variantGroups = yield filterFiles(context.config.globalVariants.variantGroups, "contextFilePath");
|
|
174
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
166
175
|
context.config.style.defaultStyleCssFilePath =
|
|
167
|
-
(yield attemptToRestoreFilePath(context, context.config.style.defaultStyleCssFilePath, baseNameToFiles)) ||
|
|
176
|
+
(yield attemptToRestoreFilePath(context, context.config.style.defaultStyleCssFilePath, baseNameToFiles)) || context.config.style.defaultStyleCssFilePath;
|
|
177
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
168
178
|
for (const project of config.projects) {
|
|
169
179
|
project.cssFilePath =
|
|
170
|
-
(yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) ||
|
|
180
|
+
(yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) || project.cssFilePath;
|
|
171
181
|
if (!project.globalContextsFilePath) {
|
|
172
182
|
project.globalContextsFilePath = "";
|
|
173
183
|
}
|
|
184
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
174
185
|
project.globalContextsFilePath =
|
|
175
|
-
(yield attemptToRestoreFilePath(context, project.globalContextsFilePath, baseNameToFiles)) ||
|
|
186
|
+
(yield attemptToRestoreFilePath(context, project.globalContextsFilePath, baseNameToFiles)) || project.globalContextsFilePath;
|
|
176
187
|
project.images = yield filterFiles(project.images, "filePath");
|
|
177
188
|
project.icons = yield filterFiles(project.icons, "moduleFilePath");
|
|
178
189
|
project.jsBundleThemes = yield filterFiles(project.jsBundleThemes || [], "themeFilePath");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.174",
|
|
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",
|
|
@@ -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,20 @@
|
|
|
1
|
+
import { CommonArgs } from "..";
|
|
2
|
+
import { logger } from "../deps";
|
|
3
|
+
import { getContext } from "../utils/get-context";
|
|
4
|
+
|
|
5
|
+
export interface InfoArgs extends CommonArgs {
|
|
6
|
+
projects: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function printProjectInfo(opts: InfoArgs): Promise<void> {
|
|
10
|
+
let context = await getContext(opts);
|
|
11
|
+
const results = await Promise.all(
|
|
12
|
+
opts.projects.map(async (p) => await context.api.projectMeta(p))
|
|
13
|
+
);
|
|
14
|
+
for (const meta of results) {
|
|
15
|
+
logger.info(`Id: ${meta.id}`);
|
|
16
|
+
logger.info(`Name: ${meta.name}`);
|
|
17
|
+
logger.info(`Host URL: ${meta.hostUrl ?? null}`);
|
|
18
|
+
logger.info(`Last published version: ${meta.lastPublishedVersion ?? null}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/actions/sync.ts
CHANGED
|
@@ -60,11 +60,11 @@ import {
|
|
|
60
60
|
ComponentPendingMerge,
|
|
61
61
|
syncProjectComponents,
|
|
62
62
|
} from "./sync-components";
|
|
63
|
+
import { syncGlobalContexts } from "./sync-global-contexts";
|
|
63
64
|
import { syncGlobalVariants } from "./sync-global-variants";
|
|
64
65
|
import { syncProjectIconAssets } from "./sync-icons";
|
|
65
66
|
import { syncProjectImageAssets } from "./sync-images";
|
|
66
67
|
import { upsertStyleTokens } from "./sync-styles";
|
|
67
|
-
import { syncGlobalContexts } from "./sync-global-contexts";
|
|
68
68
|
|
|
69
69
|
export interface SyncArgs extends CommonArgs {
|
|
70
70
|
projects: readonly string[];
|
|
@@ -488,14 +488,25 @@ async function checkExternalPkgs(
|
|
|
488
488
|
function maybeRenamePathExt(
|
|
489
489
|
context: PlasmicContext,
|
|
490
490
|
path: string,
|
|
491
|
-
ext: string
|
|
491
|
+
ext: string,
|
|
492
|
+
opts?: {
|
|
493
|
+
continueOnFailure?: boolean;
|
|
494
|
+
}
|
|
492
495
|
) {
|
|
493
496
|
if (!path) {
|
|
494
497
|
return path;
|
|
495
498
|
}
|
|
496
499
|
const correctPath = `${stripExtension(path, true)}${ext}`;
|
|
497
500
|
if (path !== correctPath) {
|
|
498
|
-
|
|
501
|
+
try {
|
|
502
|
+
renameFile(context, path, correctPath);
|
|
503
|
+
} catch (e) {
|
|
504
|
+
if (!opts?.continueOnFailure) {
|
|
505
|
+
throw e;
|
|
506
|
+
} else {
|
|
507
|
+
logger.warn(e);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
499
510
|
}
|
|
500
511
|
return correctPath;
|
|
501
512
|
}
|
|
@@ -506,19 +517,22 @@ function fixFileExtension(context: PlasmicContext) {
|
|
|
506
517
|
context.config.style.defaultStyleCssFilePath = maybeRenamePathExt(
|
|
507
518
|
context,
|
|
508
519
|
context.config.style.defaultStyleCssFilePath,
|
|
509
|
-
cssExt
|
|
520
|
+
cssExt,
|
|
521
|
+
{ continueOnFailure: true }
|
|
510
522
|
);
|
|
511
523
|
context.config.projects.forEach((project) => {
|
|
512
524
|
project.cssFilePath = maybeRenamePathExt(
|
|
513
525
|
context,
|
|
514
526
|
project.cssFilePath,
|
|
515
|
-
cssExt
|
|
527
|
+
cssExt,
|
|
528
|
+
{ continueOnFailure: true }
|
|
516
529
|
);
|
|
517
530
|
project.components.forEach((component) => {
|
|
518
531
|
component.cssFilePath = maybeRenamePathExt(
|
|
519
532
|
context,
|
|
520
533
|
component.cssFilePath,
|
|
521
|
-
cssExt
|
|
534
|
+
cssExt,
|
|
535
|
+
{ continueOnFailure: true }
|
|
522
536
|
);
|
|
523
537
|
});
|
|
524
538
|
});
|
package/src/api.ts
CHANGED
|
@@ -98,6 +98,14 @@ export interface RequiredPackages {
|
|
|
98
98
|
"@plasmicapp/react-web-runtime": string;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export interface ProjectMetaInfo {
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
workspaceId?: string;
|
|
105
|
+
hostUrl?: string;
|
|
106
|
+
lastPublishedVersion?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
export interface ProjectBundle {
|
|
102
110
|
components: ComponentBundle[];
|
|
103
111
|
codeComponentMetas: CodeComponentMeta[];
|
|
@@ -270,6 +278,13 @@ export class PlasmicApi {
|
|
|
270
278
|
return result.data as ProjectBundle;
|
|
271
279
|
}
|
|
272
280
|
|
|
281
|
+
async projectMeta(projectId: string) {
|
|
282
|
+
const result = await this.post(
|
|
283
|
+
`${this.codegenHost}/api/v1/projects/${projectId}/code/meta`
|
|
284
|
+
);
|
|
285
|
+
return result.data as ProjectMetaInfo;
|
|
286
|
+
}
|
|
287
|
+
|
|
273
288
|
async uploadBundle(
|
|
274
289
|
projectId: string,
|
|
275
290
|
bundleName: string,
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import updateNotifier from "update-notifier";
|
|
|
4
4
|
import yargs from "yargs";
|
|
5
5
|
import * as auth from "./actions/auth";
|
|
6
6
|
import { fixImports, FixImportsArgs } from "./actions/fix-imports";
|
|
7
|
+
import { InfoArgs, printProjectInfo } from "./actions/info";
|
|
7
8
|
import { getYargsOption, InitArgs, initPlasmic } from "./actions/init";
|
|
8
9
|
import * as projectToken from "./actions/project-token";
|
|
9
10
|
import { sync, SyncArgs } from "./actions/sync";
|
|
@@ -134,6 +135,20 @@ yargs
|
|
|
134
135
|
(yags) => 0,
|
|
135
136
|
(argv) => handleError(fixImports(argv))
|
|
136
137
|
)
|
|
138
|
+
.command<InfoArgs>(
|
|
139
|
+
"info",
|
|
140
|
+
"Fetches metadata for projects",
|
|
141
|
+
(yags) =>
|
|
142
|
+
yags.option("projects", {
|
|
143
|
+
alias: "p",
|
|
144
|
+
describe: "ID of plasmic project to check",
|
|
145
|
+
type: "array",
|
|
146
|
+
default: [],
|
|
147
|
+
}),
|
|
148
|
+
(argv) => {
|
|
149
|
+
handleError(printProjectInfo(argv));
|
|
150
|
+
}
|
|
151
|
+
)
|
|
137
152
|
.command<UploadBundleArgs>(
|
|
138
153
|
"upload-bundle",
|
|
139
154
|
false,
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -487,6 +487,7 @@ async function fixComponentImportStatements(
|
|
|
487
487
|
) {
|
|
488
488
|
// If ComponentConfig.importPath is still a local file, we best-effort also fix up the import statements there.
|
|
489
489
|
if (
|
|
490
|
+
compConfig.type !== "mapped" &&
|
|
490
491
|
isLocalModulePath(compConfig.importSpec.modulePath) &&
|
|
491
492
|
fixSkeletonModule
|
|
492
493
|
) {
|
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";
|
|
@@ -279,46 +278,6 @@ function getAllPaths(context: PlasmicContext): BundleKeyPair[] {
|
|
|
279
278
|
return pairs;
|
|
280
279
|
}
|
|
281
280
|
|
|
282
|
-
/**
|
|
283
|
-
* Fixes all src-relative file paths in PlasmicConfig by detecting file
|
|
284
|
-
* movement on disk.
|
|
285
|
-
*/
|
|
286
|
-
export async function fixAllFilePaths(
|
|
287
|
-
context: PlasmicContext,
|
|
288
|
-
baseDir: string
|
|
289
|
-
) {
|
|
290
|
-
const baseNameToFiles = buildBaseNameToFiles(context);
|
|
291
|
-
let changed = false;
|
|
292
|
-
|
|
293
|
-
const paths = getAllPaths(context);
|
|
294
|
-
for (const { bundle, key } of paths) {
|
|
295
|
-
const known = bundle[key];
|
|
296
|
-
// Check null and undefined
|
|
297
|
-
if (known == null) {
|
|
298
|
-
throw new HandledError(
|
|
299
|
-
`"${key} is required, but missing in ${CONFIG_FILE_NAME}. Please restore the file or delete from ${CONFIG_FILE_NAME} and run plasmic sync: ${bundle}"`
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
// Check falsey values (e.g. "")
|
|
303
|
-
if (!known) {
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
const found = findSrcDirPath(
|
|
307
|
-
context.absoluteSrcDir,
|
|
308
|
-
known,
|
|
309
|
-
baseNameToFiles
|
|
310
|
-
);
|
|
311
|
-
if (known !== found) {
|
|
312
|
-
bundle[key] = found;
|
|
313
|
-
changed = true;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (changed) {
|
|
318
|
-
await updateConfig(context, context.config, baseDir);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
281
|
/**
|
|
323
282
|
* Throws an error if some file in PlasmicConfig is not inside the root
|
|
324
283
|
* directory (i.e., the directory containing plasmic.json).
|
package/src/utils/get-context.ts
CHANGED
|
@@ -106,6 +106,14 @@ function removeMissingFilesFromLock(
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param context
|
|
112
|
+
* @param expectedPath
|
|
113
|
+
* @param baseNameToFiles
|
|
114
|
+
* @returns The path if we are able to find the file, undefined if we need to recreate it
|
|
115
|
+
* @throws if the user interrupts flow
|
|
116
|
+
*/
|
|
109
117
|
async function attemptToRestoreFilePath(
|
|
110
118
|
context: PlasmicContext,
|
|
111
119
|
expectedPath: string,
|
|
@@ -193,30 +201,34 @@ async function resolveMissingFilesInConfig(
|
|
|
193
201
|
"contextFilePath"
|
|
194
202
|
);
|
|
195
203
|
|
|
204
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
196
205
|
context.config.style.defaultStyleCssFilePath =
|
|
197
206
|
(await attemptToRestoreFilePath(
|
|
198
207
|
context,
|
|
199
208
|
context.config.style.defaultStyleCssFilePath,
|
|
200
209
|
baseNameToFiles
|
|
201
|
-
)) ||
|
|
210
|
+
)) || context.config.style.defaultStyleCssFilePath;
|
|
202
211
|
|
|
212
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
203
213
|
for (const project of config.projects) {
|
|
204
214
|
project.cssFilePath =
|
|
205
215
|
(await attemptToRestoreFilePath(
|
|
206
216
|
context,
|
|
207
217
|
project.cssFilePath,
|
|
208
218
|
baseNameToFiles
|
|
209
|
-
)) ||
|
|
219
|
+
)) || project.cssFilePath;
|
|
210
220
|
|
|
211
221
|
if (!project.globalContextsFilePath) {
|
|
212
222
|
project.globalContextsFilePath = "";
|
|
213
223
|
}
|
|
224
|
+
|
|
225
|
+
// Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
|
|
214
226
|
project.globalContextsFilePath =
|
|
215
227
|
(await attemptToRestoreFilePath(
|
|
216
228
|
context,
|
|
217
229
|
project.globalContextsFilePath,
|
|
218
230
|
baseNameToFiles
|
|
219
|
-
)) ||
|
|
231
|
+
)) || project.globalContextsFilePath;
|
|
220
232
|
|
|
221
233
|
project.images = await filterFiles(project.images, "filePath");
|
|
222
234
|
project.icons = await filterFiles(project.icons, "moduleFilePath");
|