@plasmicapp/cli 0.1.174 → 0.1.177
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/localization-strings.d.ts +8 -0
- package/dist/actions/localization-strings.js +56 -0
- package/dist/actions/sync.js +1 -0
- package/dist/api.d.ts +3 -0
- package/dist/api.js +28 -0
- package/dist/index.js +28 -0
- package/dist/plasmic.schema.json +6 -1
- package/dist/test-common/fixtures.js +1 -0
- package/dist/utils/code-utils.js +13 -3
- package/dist/utils/config-utils.d.ts +2 -0
- package/dist/utils/config-utils.js +1 -0
- package/package.json +1 -1
- package/src/actions/localization-strings.ts +57 -0
- package/src/actions/sync.ts +1 -0
- package/src/api.ts +36 -0
- package/src/index.ts +38 -0
- package/src/test-common/fixtures.ts +1 -0
- package/src/utils/code-utils.ts +18 -3
- package/src/utils/config-utils.ts +4 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface LocalizationStringsArgs {
|
|
2
|
+
host: string;
|
|
3
|
+
projects: readonly string[];
|
|
4
|
+
format: "po" | "json" | "lingui";
|
|
5
|
+
output: string;
|
|
6
|
+
forceOverwrite: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function localizationStrings(opts: LocalizationStringsArgs): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.localizationStrings = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const api_1 = require("../api");
|
|
18
|
+
const deps_1 = require("../deps");
|
|
19
|
+
const lib_1 = require("../lib");
|
|
20
|
+
const auth_utils_1 = require("../utils/auth-utils");
|
|
21
|
+
const config_utils_1 = require("../utils/config-utils");
|
|
22
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
23
|
+
const user_utils_1 = require("../utils/user-utils");
|
|
24
|
+
function localizationStrings(opts) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!opts.projects || opts.projects.length === 0) {
|
|
27
|
+
throw new lib_1.HandledError(`Missing projects.`);
|
|
28
|
+
}
|
|
29
|
+
const output = !opts.output
|
|
30
|
+
? opts.format === "po"
|
|
31
|
+
? "data.po"
|
|
32
|
+
: "data.json"
|
|
33
|
+
: opts.output;
|
|
34
|
+
const auth = yield auth_utils_1.getOrStartAuth({
|
|
35
|
+
baseDir: "",
|
|
36
|
+
host: opts.host || config_utils_1.DEFAULT_HOST,
|
|
37
|
+
});
|
|
38
|
+
if (auth) {
|
|
39
|
+
const api = new api_1.PlasmicApi(auth);
|
|
40
|
+
deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(opts.projects.join(", "))}...`);
|
|
41
|
+
const data = yield api.genLocalizationStrings(opts.projects, opts.format);
|
|
42
|
+
if (file_utils_1.existsBuffered(output)) {
|
|
43
|
+
const overwrite = yield user_utils_1.confirmWithUser(`File ${output} already exists. Do you want to overwrite?`, opts.forceOverwrite);
|
|
44
|
+
if (!overwrite) {
|
|
45
|
+
throw new lib_1.HandledError(`Cannot write to ${output}; file already exists.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
file_utils_1.writeFileText(output, data);
|
|
49
|
+
deps_1.logger.info(`Localization strings have been written to ${output}`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
deps_1.logger.error("Missing auth information");
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.localizationStrings = localizationStrings;
|
package/dist/actions/sync.js
CHANGED
|
@@ -353,6 +353,7 @@ function syncProject(context, opts, projectIdsAndTokens, projectId, componentIds
|
|
|
353
353
|
codeOpts: context.config.code,
|
|
354
354
|
metadata: get_context_1.generateMetadata(Object.assign(Object.assign({}, metadataDefaults), { platform: context.config.platform }), opts.metadata),
|
|
355
355
|
indirect,
|
|
356
|
+
wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
|
|
356
357
|
});
|
|
357
358
|
// Convert from TSX => JSX
|
|
358
359
|
if (context.config.code.lang === "js") {
|
package/dist/api.d.ts
CHANGED
|
@@ -184,15 +184,18 @@ export declare class PlasmicApi {
|
|
|
184
184
|
codeOpts: CodeConfig;
|
|
185
185
|
checksums: ChecksumBundle;
|
|
186
186
|
indirect: boolean;
|
|
187
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
187
188
|
metadata?: Metadata;
|
|
188
189
|
}): Promise<ProjectBundle>;
|
|
189
190
|
projectMeta(projectId: string): Promise<ProjectMetaInfo>;
|
|
191
|
+
genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui"): Promise<string>;
|
|
190
192
|
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>;
|
|
191
193
|
projectStyleTokens(projectId: string, versionRange?: string): Promise<StyleTokensMap>;
|
|
192
194
|
projectIcons(projectId: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
|
|
193
195
|
projectSyncMetadata(projectId: string, revision: number, rethrowAppError: boolean): Promise<ProjectSyncMetadataModel>;
|
|
194
196
|
connectSocket(): SocketIOClient.Socket;
|
|
195
197
|
private post;
|
|
198
|
+
private get;
|
|
196
199
|
private makeErrorMessage;
|
|
197
200
|
private makeHeaders;
|
|
198
201
|
private projectIdsAndTokens?;
|
package/dist/api.js
CHANGED
|
@@ -99,6 +99,14 @@ class PlasmicApi {
|
|
|
99
99
|
return result.data;
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
+
genLocalizationStrings(projects, format) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?format=${format}&preview=true&${projects
|
|
105
|
+
.map((p) => `projectId=${p}`)
|
|
106
|
+
.join("&")}`);
|
|
107
|
+
return result.data;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
102
110
|
uploadBundle(projectId, bundleName, bundleJs, css, metaJson, genModulePath, genCssPaths, pkgVersion, extraPropMetaJson, themeProviderWrapper, themeModule) {
|
|
103
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
112
|
const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/jsbundle/upload`, {
|
|
@@ -168,6 +176,26 @@ class PlasmicApi {
|
|
|
168
176
|
}
|
|
169
177
|
});
|
|
170
178
|
}
|
|
179
|
+
get(url, rethrowAppError) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
try {
|
|
182
|
+
return yield axios_1.default.get(url, {
|
|
183
|
+
headers: this.makeHeaders(),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
const error = e;
|
|
188
|
+
const errorMsg = this.makeErrorMessage(error);
|
|
189
|
+
if (rethrowAppError) {
|
|
190
|
+
throw new AppServerError(errorMsg);
|
|
191
|
+
}
|
|
192
|
+
if (!errorMsg) {
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
throw new error_1.HandledError(errorMsg);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
171
199
|
makeErrorMessage(error) {
|
|
172
200
|
var _a, _b;
|
|
173
201
|
const response = error.response;
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const auth = __importStar(require("./actions/auth"));
|
|
|
30
30
|
const fix_imports_1 = require("./actions/fix-imports");
|
|
31
31
|
const info_1 = require("./actions/info");
|
|
32
32
|
const init_1 = require("./actions/init");
|
|
33
|
+
const localization_strings_1 = require("./actions/localization-strings");
|
|
33
34
|
const projectToken = __importStar(require("./actions/project-token"));
|
|
34
35
|
const sync_1 = require("./actions/sync");
|
|
35
36
|
const upload_bundle_1 = require("./actions/upload-bundle");
|
|
@@ -186,6 +187,33 @@ yargs_1.default
|
|
|
186
187
|
type: "string",
|
|
187
188
|
default: "https://studio.plasmic.app",
|
|
188
189
|
}), (argv) => error_1.handleError(projectToken.projectToken(argv)))
|
|
190
|
+
.command("localization-strings", false, (yargs) => yargs
|
|
191
|
+
.option("projects", {
|
|
192
|
+
alias: "p",
|
|
193
|
+
describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
|
|
194
|
+
type: "array",
|
|
195
|
+
})
|
|
196
|
+
.option("host", {
|
|
197
|
+
describe: "Plasmic host to use",
|
|
198
|
+
type: "string",
|
|
199
|
+
default: "https://studio.plasmic.app",
|
|
200
|
+
})
|
|
201
|
+
.option("format", {
|
|
202
|
+
describe: 'Output format. Either "json", "po" or "lingui"',
|
|
203
|
+
type: "string",
|
|
204
|
+
choices: ["json", "po", "lingui"],
|
|
205
|
+
default: "json",
|
|
206
|
+
})
|
|
207
|
+
.option("output", {
|
|
208
|
+
alias: "o",
|
|
209
|
+
describe: "Output file",
|
|
210
|
+
type: "string",
|
|
211
|
+
})
|
|
212
|
+
.option("force-overwrite", {
|
|
213
|
+
type: "boolean",
|
|
214
|
+
describe: "Overwrite the output file.",
|
|
215
|
+
default: false,
|
|
216
|
+
}), (argv) => error_1.handleError(localization_strings_1.localizationStrings(argv)))
|
|
189
217
|
.demandCommand()
|
|
190
218
|
.strict()
|
|
191
219
|
.help("h")
|
package/dist/plasmic.schema.json
CHANGED
|
@@ -458,6 +458,10 @@
|
|
|
458
458
|
"tokens": {
|
|
459
459
|
"$ref": "#/definitions/TokensConfig",
|
|
460
460
|
"description": "Config for style tokens"
|
|
461
|
+
},
|
|
462
|
+
"wrapPagesWithGlobalContexts": {
|
|
463
|
+
"description": "Wether we should wrap the pages with the project global contexts or not",
|
|
464
|
+
"type": "boolean"
|
|
461
465
|
}
|
|
462
466
|
},
|
|
463
467
|
"required": [
|
|
@@ -469,7 +473,8 @@
|
|
|
469
473
|
"projects",
|
|
470
474
|
"srcDir",
|
|
471
475
|
"style",
|
|
472
|
-
"tokens"
|
|
476
|
+
"tokens",
|
|
477
|
+
"wrapPagesWithGlobalContexts"
|
|
473
478
|
],
|
|
474
479
|
"type": "object"
|
|
475
480
|
}
|
package/dist/utils/code-utils.js
CHANGED
|
@@ -125,7 +125,7 @@ function tryParsePlasmicImportSpec(node) {
|
|
|
125
125
|
if (!c) {
|
|
126
126
|
return undefined;
|
|
127
127
|
}
|
|
128
|
-
const m = c.value.match(/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent))?/);
|
|
128
|
+
const m = c.value.match(/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext))?/);
|
|
129
129
|
if (m) {
|
|
130
130
|
return { id: m[1], type: m[2] };
|
|
131
131
|
}
|
|
@@ -262,6 +262,14 @@ function replaceImports(context, code, fromPath, fixImportContext, removeImportD
|
|
|
262
262
|
stmt.source.value = meta.componentImportPath;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
+
else if (type === "globalContext") {
|
|
266
|
+
const projectConfig = fixImportContext.projects[uuid];
|
|
267
|
+
if (!projectConfig) {
|
|
268
|
+
throwMissingReference(context, "project", uuid, fromPath);
|
|
269
|
+
}
|
|
270
|
+
const realPath = makeImportPath(context, fromPath, projectConfig.globalContextsFilePath, true);
|
|
271
|
+
stmt.source.value = realPath;
|
|
272
|
+
}
|
|
265
273
|
});
|
|
266
274
|
if (!changed) {
|
|
267
275
|
return code;
|
|
@@ -297,8 +305,10 @@ function makeImportPath(context, fromPath, toPath, stripExt, forceRelative = fal
|
|
|
297
305
|
* a local file
|
|
298
306
|
*/
|
|
299
307
|
function isLocalModulePath(modulePath) {
|
|
300
|
-
// It is a local file reference if the importPath includes the file extension
|
|
301
|
-
|
|
308
|
+
// It is a local file reference if the importPath includes the file extension, and
|
|
309
|
+
// modulePath doesn't start with "@" (like an alias by convention, or scoped npm
|
|
310
|
+
// package). This is not a reliable way to detect scoped npm package, but :shrug:
|
|
311
|
+
return !!upath_1.default.extname(modulePath) && !modulePath.startsWith("@");
|
|
302
312
|
}
|
|
303
313
|
exports.isLocalModulePath = isLocalModulePath;
|
|
304
314
|
exports.mkFixImportContext = (config) => {
|
|
@@ -56,6 +56,8 @@ export interface PlasmicConfig {
|
|
|
56
56
|
globalVariants: GlobalVariantsConfig;
|
|
57
57
|
/** Metadata for each project that has been synced */
|
|
58
58
|
projects: ProjectConfig[];
|
|
59
|
+
/** Wether we should wrap the pages with the project global contexts or not */
|
|
60
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
59
61
|
/** The version of cli when this file was written */
|
|
60
62
|
cliVersion?: string;
|
|
61
63
|
/** Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files */
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { PlasmicApi } from "../api";
|
|
3
|
+
import { logger } from "../deps";
|
|
4
|
+
import { HandledError } from "../lib";
|
|
5
|
+
import { getOrStartAuth } from "../utils/auth-utils";
|
|
6
|
+
import { DEFAULT_HOST } from "../utils/config-utils";
|
|
7
|
+
import { existsBuffered, writeFileText } from "../utils/file-utils";
|
|
8
|
+
import { confirmWithUser } from "../utils/user-utils";
|
|
9
|
+
|
|
10
|
+
export interface LocalizationStringsArgs {
|
|
11
|
+
host: string;
|
|
12
|
+
projects: readonly string[];
|
|
13
|
+
format: "po" | "json" | "lingui";
|
|
14
|
+
output: string;
|
|
15
|
+
forceOverwrite: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function localizationStrings(
|
|
19
|
+
opts: LocalizationStringsArgs
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
if (!opts.projects || opts.projects.length === 0) {
|
|
22
|
+
throw new HandledError(`Missing projects.`);
|
|
23
|
+
}
|
|
24
|
+
const output = !opts.output
|
|
25
|
+
? opts.format === "po"
|
|
26
|
+
? "data.po"
|
|
27
|
+
: "data.json"
|
|
28
|
+
: opts.output;
|
|
29
|
+
const auth = await getOrStartAuth({
|
|
30
|
+
baseDir: "",
|
|
31
|
+
host: opts.host || DEFAULT_HOST,
|
|
32
|
+
});
|
|
33
|
+
if (auth) {
|
|
34
|
+
const api = new PlasmicApi(auth);
|
|
35
|
+
logger.info(
|
|
36
|
+
`Generating localization strings for ${chalk.bold(
|
|
37
|
+
opts.projects.join(", ")
|
|
38
|
+
)}...`
|
|
39
|
+
);
|
|
40
|
+
const data = await api.genLocalizationStrings(opts.projects, opts.format);
|
|
41
|
+
if (existsBuffered(output)) {
|
|
42
|
+
const overwrite = await confirmWithUser(
|
|
43
|
+
`File ${output} already exists. Do you want to overwrite?`,
|
|
44
|
+
opts.forceOverwrite
|
|
45
|
+
);
|
|
46
|
+
if (!overwrite) {
|
|
47
|
+
throw new HandledError(
|
|
48
|
+
`Cannot write to ${output}; file already exists.`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
writeFileText(output, data);
|
|
53
|
+
logger.info(`Localization strings have been written to ${output}`);
|
|
54
|
+
} else {
|
|
55
|
+
logger.error("Missing auth information");
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/actions/sync.ts
CHANGED
package/src/api.ts
CHANGED
|
@@ -266,6 +266,7 @@ export class PlasmicApi {
|
|
|
266
266
|
codeOpts: CodeConfig;
|
|
267
267
|
checksums: ChecksumBundle;
|
|
268
268
|
indirect: boolean;
|
|
269
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
269
270
|
metadata?: Metadata;
|
|
270
271
|
}
|
|
271
272
|
): Promise<ProjectBundle> {
|
|
@@ -285,6 +286,20 @@ export class PlasmicApi {
|
|
|
285
286
|
return result.data as ProjectMetaInfo;
|
|
286
287
|
}
|
|
287
288
|
|
|
289
|
+
async genLocalizationStrings(
|
|
290
|
+
projects: readonly string[],
|
|
291
|
+
format: "po" | "json" | "lingui"
|
|
292
|
+
) {
|
|
293
|
+
const result = await this.get(
|
|
294
|
+
`${
|
|
295
|
+
this.codegenHost
|
|
296
|
+
}/api/v1/localization/gen-texts?format=${format}&preview=true&${projects
|
|
297
|
+
.map((p) => `projectId=${p}`)
|
|
298
|
+
.join("&")}`
|
|
299
|
+
);
|
|
300
|
+
return result.data as string;
|
|
301
|
+
}
|
|
302
|
+
|
|
288
303
|
async uploadBundle(
|
|
289
304
|
projectId: string,
|
|
290
305
|
bundleName: string,
|
|
@@ -392,6 +407,27 @@ export class PlasmicApi {
|
|
|
392
407
|
}
|
|
393
408
|
}
|
|
394
409
|
|
|
410
|
+
private async get(url: string, rethrowAppError?: boolean) {
|
|
411
|
+
try {
|
|
412
|
+
return await axios.get(url, {
|
|
413
|
+
headers: this.makeHeaders(),
|
|
414
|
+
});
|
|
415
|
+
} catch (e) {
|
|
416
|
+
const error = e as AxiosError;
|
|
417
|
+
const errorMsg = this.makeErrorMessage(error);
|
|
418
|
+
|
|
419
|
+
if (rethrowAppError) {
|
|
420
|
+
throw new AppServerError(errorMsg);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (!errorMsg) {
|
|
424
|
+
throw e;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
throw new HandledError(errorMsg);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
395
431
|
private makeErrorMessage(error: AxiosError) {
|
|
396
432
|
const response = error.response;
|
|
397
433
|
if (!response) {
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,10 @@ import * as auth from "./actions/auth";
|
|
|
6
6
|
import { fixImports, FixImportsArgs } from "./actions/fix-imports";
|
|
7
7
|
import { InfoArgs, printProjectInfo } from "./actions/info";
|
|
8
8
|
import { getYargsOption, InitArgs, initPlasmic } from "./actions/init";
|
|
9
|
+
import {
|
|
10
|
+
localizationStrings,
|
|
11
|
+
LocalizationStringsArgs,
|
|
12
|
+
} from "./actions/localization-strings";
|
|
9
13
|
import * as projectToken from "./actions/project-token";
|
|
10
14
|
import { sync, SyncArgs } from "./actions/sync";
|
|
11
15
|
import { UploadBundleArgs, uploadJsBundle } from "./actions/upload-bundle";
|
|
@@ -226,6 +230,40 @@ yargs
|
|
|
226
230
|
}),
|
|
227
231
|
(argv) => handleError(projectToken.projectToken(argv))
|
|
228
232
|
)
|
|
233
|
+
.command<LocalizationStringsArgs>(
|
|
234
|
+
"localization-strings",
|
|
235
|
+
false,
|
|
236
|
+
(yargs) =>
|
|
237
|
+
yargs
|
|
238
|
+
.option("projects", {
|
|
239
|
+
alias: "p",
|
|
240
|
+
describe:
|
|
241
|
+
"One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
|
|
242
|
+
type: "array",
|
|
243
|
+
})
|
|
244
|
+
.option("host", {
|
|
245
|
+
describe: "Plasmic host to use",
|
|
246
|
+
type: "string",
|
|
247
|
+
default: "https://studio.plasmic.app",
|
|
248
|
+
})
|
|
249
|
+
.option("format", {
|
|
250
|
+
describe: 'Output format. Either "json", "po" or "lingui"',
|
|
251
|
+
type: "string",
|
|
252
|
+
choices: ["json", "po", "lingui"],
|
|
253
|
+
default: "json",
|
|
254
|
+
})
|
|
255
|
+
.option("output", {
|
|
256
|
+
alias: "o",
|
|
257
|
+
describe: "Output file",
|
|
258
|
+
type: "string",
|
|
259
|
+
})
|
|
260
|
+
.option("force-overwrite", {
|
|
261
|
+
type: "boolean",
|
|
262
|
+
describe: "Overwrite the output file.",
|
|
263
|
+
default: false,
|
|
264
|
+
}),
|
|
265
|
+
(argv) => handleError(localizationStrings(argv))
|
|
266
|
+
)
|
|
229
267
|
.demandCommand()
|
|
230
268
|
.strict()
|
|
231
269
|
.help("h")
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -156,6 +156,7 @@ type PlasmicImportType =
|
|
|
156
156
|
| "picture"
|
|
157
157
|
| "jsBundle"
|
|
158
158
|
| "codeComponent"
|
|
159
|
+
| "globalContext"
|
|
159
160
|
| undefined;
|
|
160
161
|
|
|
161
162
|
function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
@@ -164,7 +165,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
|
|
|
164
165
|
return undefined;
|
|
165
166
|
}
|
|
166
167
|
const m = c.value.match(
|
|
167
|
-
/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent))?/
|
|
168
|
+
/plasmic-import:\s+([\w-]+)(?:\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext))?/
|
|
168
169
|
);
|
|
169
170
|
if (m) {
|
|
170
171
|
return { id: m[1], type: m[2] as PlasmicImportType } as PlasmicImportSpec;
|
|
@@ -337,6 +338,18 @@ export function replaceImports(
|
|
|
337
338
|
// npm package
|
|
338
339
|
stmt.source.value = meta.componentImportPath;
|
|
339
340
|
}
|
|
341
|
+
} else if (type === "globalContext") {
|
|
342
|
+
const projectConfig = fixImportContext.projects[uuid];
|
|
343
|
+
if (!projectConfig) {
|
|
344
|
+
throwMissingReference(context, "project", uuid, fromPath);
|
|
345
|
+
}
|
|
346
|
+
const realPath = makeImportPath(
|
|
347
|
+
context,
|
|
348
|
+
fromPath,
|
|
349
|
+
projectConfig.globalContextsFilePath,
|
|
350
|
+
true
|
|
351
|
+
);
|
|
352
|
+
stmt.source.value = realPath;
|
|
340
353
|
}
|
|
341
354
|
});
|
|
342
355
|
|
|
@@ -392,8 +405,10 @@ function makeImportPath(
|
|
|
392
405
|
* a local file
|
|
393
406
|
*/
|
|
394
407
|
export function isLocalModulePath(modulePath: string) {
|
|
395
|
-
// It is a local file reference if the importPath includes the file extension
|
|
396
|
-
|
|
408
|
+
// It is a local file reference if the importPath includes the file extension, and
|
|
409
|
+
// modulePath doesn't start with "@" (like an alias by convention, or scoped npm
|
|
410
|
+
// package). This is not a reliable way to detect scoped npm package, but :shrug:
|
|
411
|
+
return !!path.extname(modulePath) && !modulePath.startsWith("@");
|
|
397
412
|
}
|
|
398
413
|
|
|
399
414
|
export interface ComponentUpdateSummary {
|
|
@@ -85,6 +85,9 @@ export interface PlasmicConfig {
|
|
|
85
85
|
/** Metadata for each project that has been synced */
|
|
86
86
|
projects: ProjectConfig[];
|
|
87
87
|
|
|
88
|
+
/** Wether we should wrap the pages with the project global contexts or not */
|
|
89
|
+
wrapPagesWithGlobalContexts: boolean;
|
|
90
|
+
|
|
88
91
|
/** The version of cli when this file was written */
|
|
89
92
|
cliVersion?: string;
|
|
90
93
|
|
|
@@ -411,6 +414,7 @@ export const DEFAULT_CONFIG: PlasmicConfig = {
|
|
|
411
414
|
globalVariants: {
|
|
412
415
|
variantGroups: [],
|
|
413
416
|
},
|
|
417
|
+
wrapPagesWithGlobalContexts: true,
|
|
414
418
|
};
|
|
415
419
|
|
|
416
420
|
export const DEFAULT_PUBLIC_FILES_CONFIG: ImagesConfig = {
|