@plasmicapp/cli 0.1.292 → 0.1.294
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 +1 -0
- package/dist/actions/localization-strings.js +30 -22
- package/dist/api.d.ts +1 -1
- package/dist/api.js +10 -4
- package/dist/index.js +6 -1
- package/dist/plasmic.schema.json +3 -2
- package/dist/utils/config-utils.d.ts +3 -3
- package/package.json +2 -2
- package/src/actions/localization-strings.ts +37 -22
- package/src/api.ts +13 -6
- package/src/index.ts +7 -1
- package/src/utils/config-utils.ts +3 -3
|
@@ -8,5 +8,6 @@ export interface LocalizationStringsArgs extends CommonArgs {
|
|
|
8
8
|
forceOverwrite: boolean;
|
|
9
9
|
keyScheme: "content" | "hash" | "path" | undefined;
|
|
10
10
|
tagPrefix: string | undefined;
|
|
11
|
+
excludeDeps: boolean | undefined;
|
|
11
12
|
}
|
|
12
13
|
export declare function localizationStrings(opts: LocalizationStringsArgs): Promise<void>;
|
|
@@ -26,12 +26,36 @@ const user_utils_1 = require("../utils/user-utils");
|
|
|
26
26
|
function localizationStrings(opts) {
|
|
27
27
|
var _a, _b, _c;
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
if (!opts.
|
|
29
|
+
if (!opts.baseDir) {
|
|
30
|
+
opts.baseDir = process.cwd();
|
|
31
|
+
}
|
|
32
|
+
const maybeConfigFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: true });
|
|
33
|
+
let projectSpecs = opts.projects;
|
|
34
|
+
let keyScheme = opts.keyScheme;
|
|
35
|
+
let tagPrefix = opts.tagPrefix;
|
|
36
|
+
const projectTokensFromConfig = [];
|
|
37
|
+
if (maybeConfigFile) {
|
|
38
|
+
// if plasmic.json exists, then we can derive some settings from
|
|
39
|
+
// there instead.
|
|
40
|
+
deps_1.logger.info(`Using settings from ${maybeConfigFile}...`);
|
|
41
|
+
const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
|
|
42
|
+
context.config.projects.forEach((p) => {
|
|
43
|
+
projectTokensFromConfig.push(lodash_1.pick(p, "projectId", "projectApiToken"));
|
|
44
|
+
});
|
|
45
|
+
if (!projectSpecs || projectSpecs.length === 0) {
|
|
46
|
+
projectSpecs = context.config.projects.map((p) => p.projectId + (p.version === "latest" ? "" : `@${p.version}`));
|
|
47
|
+
}
|
|
48
|
+
if (!keyScheme) {
|
|
49
|
+
keyScheme = (_a = context.config.i18n) === null || _a === void 0 ? void 0 : _a.keyScheme;
|
|
50
|
+
}
|
|
51
|
+
if (!tagPrefix) {
|
|
52
|
+
tagPrefix = (_b = context.config.i18n) === null || _b === void 0 ? void 0 : _b.tagPrefix;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!projectSpecs || projectSpecs.length === 0) {
|
|
30
56
|
throw new lib_1.HandledError(`Missing projects.`);
|
|
31
57
|
}
|
|
32
|
-
|
|
33
|
-
opts.baseDir = process.cwd();
|
|
34
|
-
const parsedProjectTokens = ((_a = opts.projectTokens) !== null && _a !== void 0 ? _a : []).map((val) => {
|
|
58
|
+
const parsedProjectTokens = ((_c = opts.projectTokens) !== null && _c !== void 0 ? _c : []).map((val) => {
|
|
35
59
|
const [projectId, projectApiToken] = val.split(":");
|
|
36
60
|
if (!projectId || !projectApiToken) {
|
|
37
61
|
throw new Error(`Invalid value passed to '--project-tokens': ${val}\nPlease provide the API tokens with the format PROJECT_ID:PROJECT_API_TOKEN`);
|
|
@@ -46,23 +70,7 @@ function localizationStrings(opts) {
|
|
|
46
70
|
? "data.po"
|
|
47
71
|
: "data.json"
|
|
48
72
|
: opts.output;
|
|
49
|
-
let keyScheme = opts.keyScheme;
|
|
50
|
-
let tagPrefix = opts.tagPrefix;
|
|
51
|
-
const projectTokensFromConfig = [];
|
|
52
73
|
const auth = yield auth_utils_1.getCurrentAuth(opts.auth);
|
|
53
|
-
const maybeConfigFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: true });
|
|
54
|
-
if (maybeConfigFile) {
|
|
55
|
-
const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
|
|
56
|
-
context.config.projects.forEach((p) => {
|
|
57
|
-
projectTokensFromConfig.push(lodash_1.pick(p, "projectId", "projectApiToken"));
|
|
58
|
-
});
|
|
59
|
-
if (!keyScheme) {
|
|
60
|
-
keyScheme = (_b = context.config.i18n) === null || _b === void 0 ? void 0 : _b.keyScheme;
|
|
61
|
-
}
|
|
62
|
-
if (!tagPrefix) {
|
|
63
|
-
tagPrefix = (_c = context.config.i18n) === null || _c === void 0 ? void 0 : _c.tagPrefix;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
74
|
const projectIdsAndTokens = [
|
|
67
75
|
...parsedProjectTokens,
|
|
68
76
|
...projectTokensFromConfig,
|
|
@@ -73,8 +81,8 @@ function localizationStrings(opts) {
|
|
|
73
81
|
user: "",
|
|
74
82
|
token: "",
|
|
75
83
|
});
|
|
76
|
-
deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(
|
|
77
|
-
const data = yield api.genLocalizationStrings(
|
|
84
|
+
deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(projectSpecs.join(", "))}...`);
|
|
85
|
+
const data = yield api.genLocalizationStrings(projectSpecs, opts.format, keyScheme !== null && keyScheme !== void 0 ? keyScheme : "content", tagPrefix, projectIdsAndTokens, opts.excludeDeps);
|
|
78
86
|
if (file_utils_1.existsBuffered(output)) {
|
|
79
87
|
const overwrite = yield user_utils_1.confirmWithUser(`File ${output} already exists. Do you want to overwrite?`, opts.forceOverwrite);
|
|
80
88
|
if (!overwrite) {
|
package/dist/api.d.ts
CHANGED
|
@@ -200,7 +200,7 @@ export declare class PlasmicApi {
|
|
|
200
200
|
metadata?: Metadata;
|
|
201
201
|
}): Promise<ProjectBundle>;
|
|
202
202
|
projectMeta(projectId: string): Promise<ProjectMetaInfo>;
|
|
203
|
-
genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", keyScheme: "content" | "hash" | "path", tagPrefix: string | undefined, projectIdsAndTokens: ProjectIdAndToken[]): Promise<string>;
|
|
203
|
+
genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", keyScheme: "content" | "hash" | "path", tagPrefix: string | undefined, projectIdsAndTokens: ProjectIdAndToken[], excludeDeps: boolean | undefined): Promise<string>;
|
|
204
204
|
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>;
|
|
205
205
|
projectStyleTokens(projectId: string, branchName: string, versionRange?: string): Promise<StyleTokensMap>;
|
|
206
206
|
projectIcons(projectId: string, branchName: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
|
package/dist/api.js
CHANGED
|
@@ -99,11 +99,17 @@ class PlasmicApi {
|
|
|
99
99
|
return result.data;
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
genLocalizationStrings(projects, format, keyScheme, tagPrefix, projectIdsAndTokens) {
|
|
102
|
+
genLocalizationStrings(projects, format, keyScheme, tagPrefix, projectIdsAndTokens, excludeDeps) {
|
|
103
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const params = new URLSearchParams([
|
|
105
|
+
["format", format],
|
|
106
|
+
["keyScheme", keyScheme],
|
|
107
|
+
["preview", "true"],
|
|
108
|
+
...projects.map((p) => ["projectId", p]),
|
|
109
|
+
tagPrefix ? ["tagPrefix", tagPrefix] : undefined,
|
|
110
|
+
excludeDeps ? ["excludeDeps", "true"] : undefined,
|
|
111
|
+
].filter((x) => !!x));
|
|
112
|
+
const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?${params.toString()}`, undefined, {
|
|
107
113
|
"x-plasmic-api-project-tokens": projectIdsAndTokens
|
|
108
114
|
.map(({ projectId, projectApiToken }) => `${projectId}:${projectApiToken}`)
|
|
109
115
|
.join(","),
|
package/dist/index.js
CHANGED
|
@@ -190,7 +190,7 @@ yargs_1.default
|
|
|
190
190
|
.command("localization-strings", false, (yargs) => yargs
|
|
191
191
|
.option("projects", {
|
|
192
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",
|
|
193
|
+
describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version. If not specified, will be derived from plasmic.json if you are using codegen.",
|
|
194
194
|
type: "array",
|
|
195
195
|
})
|
|
196
196
|
.option("host", {
|
|
@@ -212,6 +212,11 @@ yargs_1.default
|
|
|
212
212
|
.option("tag-prefix", {
|
|
213
213
|
describe: "By default, rich text with markup tags look like '<0>hello</0>'. If your localization framework requires num-numeric tags, then specify a prefix; for example a prefix of 'n' turns it into '<n0>hello</n0>'.",
|
|
214
214
|
type: "string",
|
|
215
|
+
})
|
|
216
|
+
.option("exclude-deps", {
|
|
217
|
+
type: "boolean",
|
|
218
|
+
describe: "By default, strings from imported dependencies are also included. Specify --exclude-deps to only include strings from projects you explicitly specify.",
|
|
219
|
+
default: false,
|
|
215
220
|
})
|
|
216
221
|
.option("output", {
|
|
217
222
|
alias: "o",
|
package/dist/plasmic.schema.json
CHANGED
|
@@ -182,10 +182,11 @@
|
|
|
182
182
|
"I18NConfig": {
|
|
183
183
|
"properties": {
|
|
184
184
|
"keyScheme": {
|
|
185
|
-
"description": "For localization, whether the extracted strings are keyed by its content
|
|
185
|
+
"description": "For localization, whether the extracted strings are keyed by its content,\nor by a hash of its content, or by where the string is found (\"path\")",
|
|
186
186
|
"enum": [
|
|
187
187
|
"content",
|
|
188
|
-
"hash"
|
|
188
|
+
"hash",
|
|
189
|
+
"path"
|
|
189
190
|
],
|
|
190
191
|
"type": "string"
|
|
191
192
|
},
|
|
@@ -250,10 +250,10 @@ export interface ProjectLock {
|
|
|
250
250
|
}
|
|
251
251
|
export interface I18NConfig {
|
|
252
252
|
/**
|
|
253
|
-
* For localization, whether the extracted strings are keyed by its content
|
|
254
|
-
* or by a hash of its content
|
|
253
|
+
* For localization, whether the extracted strings are keyed by its content,
|
|
254
|
+
* or by a hash of its content, or by where the string is found ("path")
|
|
255
255
|
*/
|
|
256
|
-
keyScheme: "content" | "hash";
|
|
256
|
+
keyScheme: "content" | "hash" | "path";
|
|
257
257
|
/**
|
|
258
258
|
* For localization, rich text with embedded tags are exported as
|
|
259
259
|
* "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.294",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"wrap-ansi": "^7.0.0",
|
|
81
81
|
"yargs": "^15.4.1"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "ff42d1b747943bedcc21cb39f8ffb92d38347292"
|
|
84
84
|
}
|
|
@@ -19,15 +19,46 @@ export interface LocalizationStringsArgs extends CommonArgs {
|
|
|
19
19
|
forceOverwrite: boolean;
|
|
20
20
|
keyScheme: "content" | "hash" | "path" | undefined;
|
|
21
21
|
tagPrefix: string | undefined;
|
|
22
|
+
excludeDeps: boolean | undefined;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export async function localizationStrings(
|
|
25
26
|
opts: LocalizationStringsArgs
|
|
26
27
|
): Promise<void> {
|
|
27
|
-
if (!opts.
|
|
28
|
+
if (!opts.baseDir) {
|
|
29
|
+
opts.baseDir = process.cwd();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const maybeConfigFile =
|
|
33
|
+
opts.config || findConfigFile(opts.baseDir, { traverseParents: true });
|
|
34
|
+
|
|
35
|
+
let projectSpecs = opts.projects;
|
|
36
|
+
let keyScheme = opts.keyScheme;
|
|
37
|
+
let tagPrefix = opts.tagPrefix;
|
|
38
|
+
const projectTokensFromConfig: ProjectIdAndToken[] = [];
|
|
39
|
+
if (maybeConfigFile) {
|
|
40
|
+
// if plasmic.json exists, then we can derive some settings from
|
|
41
|
+
// there instead.
|
|
42
|
+
logger.info(`Using settings from ${maybeConfigFile}...`);
|
|
43
|
+
const context = await getContext(opts, { enableSkipAuth: true });
|
|
44
|
+
context.config.projects.forEach((p) => {
|
|
45
|
+
projectTokensFromConfig.push(pick(p, "projectId", "projectApiToken"));
|
|
46
|
+
});
|
|
47
|
+
if (!projectSpecs || projectSpecs.length === 0) {
|
|
48
|
+
projectSpecs = context.config.projects.map(
|
|
49
|
+
(p) => p.projectId + (p.version === "latest" ? "" : `@${p.version}`)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (!keyScheme) {
|
|
53
|
+
keyScheme = context.config.i18n?.keyScheme;
|
|
54
|
+
}
|
|
55
|
+
if (!tagPrefix) {
|
|
56
|
+
tagPrefix = context.config.i18n?.tagPrefix;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!projectSpecs || projectSpecs.length === 0) {
|
|
28
60
|
throw new HandledError(`Missing projects.`);
|
|
29
61
|
}
|
|
30
|
-
if (!opts.baseDir) opts.baseDir = process.cwd();
|
|
31
62
|
const parsedProjectTokens: ProjectIdAndToken[] = (
|
|
32
63
|
opts.projectTokens ?? []
|
|
33
64
|
).map((val) => {
|
|
@@ -47,24 +78,7 @@ export async function localizationStrings(
|
|
|
47
78
|
? "data.po"
|
|
48
79
|
: "data.json"
|
|
49
80
|
: opts.output;
|
|
50
|
-
let keyScheme = opts.keyScheme;
|
|
51
|
-
let tagPrefix = opts.tagPrefix;
|
|
52
|
-
const projectTokensFromConfig: ProjectIdAndToken[] = [];
|
|
53
81
|
const auth = await getCurrentAuth(opts.auth);
|
|
54
|
-
const maybeConfigFile =
|
|
55
|
-
opts.config || findConfigFile(opts.baseDir, { traverseParents: true });
|
|
56
|
-
if (maybeConfigFile) {
|
|
57
|
-
const context = await getContext(opts, { enableSkipAuth: true });
|
|
58
|
-
context.config.projects.forEach((p) => {
|
|
59
|
-
projectTokensFromConfig.push(pick(p, "projectId", "projectApiToken"));
|
|
60
|
-
});
|
|
61
|
-
if (!keyScheme) {
|
|
62
|
-
keyScheme = context.config.i18n?.keyScheme;
|
|
63
|
-
}
|
|
64
|
-
if (!tagPrefix) {
|
|
65
|
-
tagPrefix = context.config.i18n?.tagPrefix;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
82
|
|
|
69
83
|
const projectIdsAndTokens = [
|
|
70
84
|
...parsedProjectTokens,
|
|
@@ -81,15 +95,16 @@ export async function localizationStrings(
|
|
|
81
95
|
);
|
|
82
96
|
logger.info(
|
|
83
97
|
`Generating localization strings for ${chalk.bold(
|
|
84
|
-
|
|
98
|
+
projectSpecs.join(", ")
|
|
85
99
|
)}...`
|
|
86
100
|
);
|
|
87
101
|
const data = await api.genLocalizationStrings(
|
|
88
|
-
|
|
102
|
+
projectSpecs,
|
|
89
103
|
opts.format,
|
|
90
104
|
keyScheme ?? "content",
|
|
91
105
|
tagPrefix,
|
|
92
|
-
projectIdsAndTokens
|
|
106
|
+
projectIdsAndTokens,
|
|
107
|
+
opts.excludeDeps
|
|
93
108
|
);
|
|
94
109
|
if (existsBuffered(output)) {
|
|
95
110
|
const overwrite = await confirmWithUser(
|
package/src/api.ts
CHANGED
|
@@ -304,14 +304,21 @@ export class PlasmicApi {
|
|
|
304
304
|
format: "po" | "json" | "lingui",
|
|
305
305
|
keyScheme: "content" | "hash" | "path",
|
|
306
306
|
tagPrefix: string | undefined,
|
|
307
|
-
projectIdsAndTokens: ProjectIdAndToken[]
|
|
307
|
+
projectIdsAndTokens: ProjectIdAndToken[],
|
|
308
|
+
excludeDeps: boolean | undefined
|
|
308
309
|
) {
|
|
310
|
+
const params = new URLSearchParams(
|
|
311
|
+
[
|
|
312
|
+
["format", format],
|
|
313
|
+
["keyScheme", keyScheme],
|
|
314
|
+
["preview", "true"],
|
|
315
|
+
...projects.map((p) => ["projectId", p]),
|
|
316
|
+
tagPrefix ? ["tagPrefix", tagPrefix] : undefined,
|
|
317
|
+
excludeDeps ? ["excludeDeps", "true"] : undefined,
|
|
318
|
+
].filter((x): x is [string, string] => !!x)
|
|
319
|
+
);
|
|
309
320
|
const result = await this.get(
|
|
310
|
-
`${
|
|
311
|
-
this.codegenHost
|
|
312
|
-
}/api/v1/localization/gen-texts?format=${format}&keyScheme=${keyScheme}&tagPrefix=${tagPrefix}&preview=true&${projects
|
|
313
|
-
.map((p) => `projectId=${p}`)
|
|
314
|
-
.join("&")}`,
|
|
321
|
+
`${this.codegenHost}/api/v1/localization/gen-texts?${params.toString()}`,
|
|
315
322
|
undefined,
|
|
316
323
|
{
|
|
317
324
|
"x-plasmic-api-project-tokens": projectIdsAndTokens
|
package/src/index.ts
CHANGED
|
@@ -238,7 +238,7 @@ yargs
|
|
|
238
238
|
.option("projects", {
|
|
239
239
|
alias: "p",
|
|
240
240
|
describe:
|
|
241
|
-
"One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
|
|
241
|
+
"One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version. If not specified, will be derived from plasmic.json if you are using codegen.",
|
|
242
242
|
type: "array",
|
|
243
243
|
})
|
|
244
244
|
.option("host", {
|
|
@@ -263,6 +263,12 @@ yargs
|
|
|
263
263
|
"By default, rich text with markup tags look like '<0>hello</0>'. If your localization framework requires num-numeric tags, then specify a prefix; for example a prefix of 'n' turns it into '<n0>hello</n0>'.",
|
|
264
264
|
type: "string",
|
|
265
265
|
})
|
|
266
|
+
.option("exclude-deps", {
|
|
267
|
+
type: "boolean",
|
|
268
|
+
describe:
|
|
269
|
+
"By default, strings from imported dependencies are also included. Specify --exclude-deps to only include strings from projects you explicitly specify.",
|
|
270
|
+
default: false,
|
|
271
|
+
})
|
|
266
272
|
.option("output", {
|
|
267
273
|
alias: "o",
|
|
268
274
|
describe: "Output file",
|
|
@@ -351,10 +351,10 @@ export interface ProjectLock {
|
|
|
351
351
|
|
|
352
352
|
export interface I18NConfig {
|
|
353
353
|
/**
|
|
354
|
-
* For localization, whether the extracted strings are keyed by its content
|
|
355
|
-
* or by a hash of its content
|
|
354
|
+
* For localization, whether the extracted strings are keyed by its content,
|
|
355
|
+
* or by a hash of its content, or by where the string is found ("path")
|
|
356
356
|
*/
|
|
357
|
-
keyScheme: "content" | "hash";
|
|
357
|
+
keyScheme: "content" | "hash" | "path";
|
|
358
358
|
/**
|
|
359
359
|
* For localization, rich text with embedded tags are exported as
|
|
360
360
|
* "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
|