@dittowords/cli 4.2.0 → 4.2.3
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/bin/ditto.js +10 -3
- package/bin/ditto.js.map +1 -1
- package/bin/generate-suggestions.js +6 -3
- package/bin/generate-suggestions.js.map +1 -1
- package/bin/http/fetchComponents.js +3 -3
- package/bin/http/fetchComponents.js.map +1 -1
- package/bin/pull.js +3 -3
- package/bin/pull.js.map +1 -1
- package/bin/utils/cleanFileName.js +8 -3
- package/bin/utils/cleanFileName.js.map +1 -1
- package/bin/utils/cleanFileName.test.js +15 -0
- package/bin/utils/cleanFileName.test.js.map +1 -0
- package/lib/ditto.ts +14 -4
- package/lib/generate-suggestions.ts +14 -7
- package/lib/http/fetchComponents.ts +1 -1
- package/lib/pull.ts +4 -1
- package/lib/utils/cleanFileName.test.ts +11 -0
- package/lib/utils/cleanFileName.ts +6 -4
- package/package.json +2 -2
package/bin/ditto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ff164041-941a-57a6-b654-0be6a12eef74")}catch(e){}}();
|
|
4
4
|
|
|
5
5
|
var __create = Object.create;
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
@@ -83,6 +83,13 @@ function getVersion() {
|
|
|
83
83
|
return packageJson.version;
|
|
84
84
|
}
|
|
85
85
|
const VERSION = getVersion();
|
|
86
|
+
const CONFIG_FILE_RELIANT_COMMANDS = [
|
|
87
|
+
"pull",
|
|
88
|
+
"none",
|
|
89
|
+
"project",
|
|
90
|
+
"project add",
|
|
91
|
+
"project remove"
|
|
92
|
+
];
|
|
86
93
|
const COMMANDS = [
|
|
87
94
|
{
|
|
88
95
|
name: "pull",
|
|
@@ -199,7 +206,7 @@ const setupOptions = () => {
|
|
|
199
206
|
import_commander.program.version(VERSION, "-v, --version", "Output the current version");
|
|
200
207
|
};
|
|
201
208
|
const executeCommand = (command, options) => __async(exports, null, function* () {
|
|
202
|
-
const needsInitialization = (0, import_init.needsTokenOrSource)();
|
|
209
|
+
const needsInitialization = CONFIG_FILE_RELIANT_COMMANDS.includes(command) && (0, import_init.needsTokenOrSource)();
|
|
203
210
|
if (needsInitialization) {
|
|
204
211
|
try {
|
|
205
212
|
yield (0, import_init.init)();
|
|
@@ -272,4 +279,4 @@ const main = () => __async(exports, null, function* () {
|
|
|
272
279
|
main();
|
|
273
280
|
//# sourceMappingURL=ditto.js.map
|
|
274
281
|
|
|
275
|
-
//# debugId=
|
|
282
|
+
//# debugId=ff164041-941a-57a6-b654-0be6a12eef74
|
package/bin/ditto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/ditto.ts"],"sourcesContent":["#!/usr/bin/env node\n// This is the main entry point for the ditto-cli command.\nimport { program } from \"commander\";\n// to use V8's code cache to speed up instantiation time\nimport \"v8-compile-cache\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport * as Sentry from \"@sentry/node\";\nimport { version as release } from \"../package.json\";\n\nimport { init, needsTokenOrSource } from \"./init/init\";\nimport { pull } from \"./pull\";\nimport { quit } from \"./utils/quit\";\nimport addProject from \"./add-project\";\nimport removeProject from \"./remove-project\";\nimport { replace } from \"./replace\";\nimport { generateSuggestions } from \"./generate-suggestions\";\n\nimport processMetaOption from \"./utils/processMetaOption\";\nimport { importComponents } from \"./importComponents\";\nimport { showComponentFolders } from \"./component-folders\";\n\nconst environment = process.env.ENV || \"development\";\nSentry.init({ dsn: process.env.SENTRY_DSN, environment, release });\n\nfunction getVersion(): string {\n const packageJsonPath = path.join(__dirname, \"..\", \"package.json\");\n const packageJsonContent = fs.readFileSync(packageJsonPath, \"utf8\");\n const packageJson = JSON.parse(packageJsonContent) as { version: string };\n return packageJson.version;\n}\n\nconst VERSION = getVersion();\n\ntype Command =\n | \"pull\"\n | \"project\"\n | \"project add\"\n | \"project remove\"\n | \"component-folders\"\n | \"generate-suggestions\"\n | \"replace\"\n | \"import-components\";\n\ninterface CommandConfig<T extends Command | \"add\" | \"remove\"> {\n name: T;\n description: string;\n commands?: CommandConfig<\"add\" | \"remove\">[];\n flags?: {\n [flag: string]: { description: string; processor?: (value: string) => any };\n };\n}\n\nconst COMMANDS: CommandConfig<Command>[] = [\n {\n name: \"pull\",\n description: \"Sync copy from Ditto into the current working directory\",\n },\n {\n name: \"project\",\n description: \"Add a Ditto project to sync copy from\",\n commands: [\n {\n name: \"add\",\n description: \"Add a Ditto project to sync copy from\",\n },\n {\n name: \"remove\",\n description: \"Stop syncing copy from a Ditto project\",\n },\n ],\n },\n {\n name: \"component-folders\",\n description:\n \"List component folders in your workspace. More information about component folders can be found here: https://www.dittowords.com/docs/component-folders.\",\n flags: {\n \"-s, --sample-data\": {\n description: \"Includes the sample components folder in the output\",\n },\n },\n },\n {\n name: \"generate-suggestions\",\n description: \"Find text that can be potentially replaced with Ditto text\",\n flags: {\n \"-d, --directory [value]\": {\n description: \"Directory to search for text\",\n },\n \"-f, --files [value]\": {\n description: \"Files to search for text (will override -d)\",\n processor: (value: string) => value.split(\",\"),\n },\n \"-cf, --component-folder [value]\": {\n description: \"Component folder to search for matches\",\n },\n },\n },\n {\n name: \"replace\",\n description: \"Find and replace Ditto text with code\",\n flags: {\n \"-ln, --line-numbers [value]\": {\n description: \"Only replace text on a specific line number\",\n processor: (value: string) => value.split(\",\").map(Number),\n },\n },\n },\n {\n name: \"import-components\",\n description:\n \"Import components via a file. For more information please see: https://www.dittowords.com/docs/importing-string-files.\",\n flags: {\n \"-t, --text [value]\": {\n description: \"Text column index (.csv format only)\",\n },\n \"-n, --component-name [value]\": {\n description: \"Name column indexes (comma separated) (.csv format only)\",\n },\n \"-no, --notes [value]\": {\n description: \"Notes column index (.csv format only)\",\n },\n \"-t, --tags [value]\": {\n description: \"Tags column index (.csv format only)\",\n },\n \"-s, --status [value]\": {\n description: \"Status column index (.csv format only)\",\n },\n \"-c, --component-id [value]\": {\n description: \"Component ID column index (.csv format only)\",\n },\n },\n },\n];\n\nconst setupCommands = () => {\n program.name(\"ditto-cli\");\n\n COMMANDS.forEach((commandConfig) => {\n const cmd = program\n .command(commandConfig.name)\n .description(commandConfig.description)\n .action((options) => {\n return executeCommand(commandConfig.name, options);\n });\n\n if (commandConfig.flags) {\n Object.entries(commandConfig.flags).forEach(\n ([flags, { description, processor }]) => {\n if (processor) {\n cmd.option(flags, description, processor);\n } else {\n cmd.option(flags, description);\n }\n }\n );\n }\n\n if (\"commands\" in commandConfig && commandConfig.commands) {\n commandConfig.commands.forEach((nestedCommand) => {\n cmd\n .command(nestedCommand.name)\n .description(nestedCommand.description)\n .action((str, options) => {\n if (commandConfig.name === \"project\") {\n const command =\n `${commandConfig.name} ${nestedCommand.name}` as Command;\n\n return executeCommand(command, options);\n }\n });\n });\n }\n });\n};\n\nconst setupOptions = () => {\n program.option(\n \"-m, --meta <data...>\",\n \"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual\"\n );\n program.version(VERSION, \"-v, --version\", \"Output the current version\");\n};\n\nconst executeCommand = async (\n command: Command | \"none\",\n options: any\n): Promise<void> => {\n const needsInitialization = needsTokenOrSource();\n if (needsInitialization) {\n try {\n await init();\n } catch (error) {\n quit(\"Exiting Ditto CLI...\");\n return;\n }\n }\n\n const { meta } = program.opts();\n switch (command) {\n case \"none\":\n case \"pull\": {\n return pull({ meta: processMetaOption(meta) });\n }\n case \"project\":\n case \"project add\": {\n // initialization already includes the selection of a source,\n // so if `project add` is called during initialization, don't\n // prompt the user to select a source again\n if (needsInitialization) return;\n\n return addProject();\n }\n case \"project remove\": {\n return removeProject();\n }\n case \"component-folders\": {\n return showComponentFolders({\n showSampleData: options.sampleData,\n });\n }\n case \"generate-suggestions\": {\n return generateSuggestions({\n directory: options.directory,\n files: options.files,\n componentFolder: options.componentFolder,\n });\n }\n case \"replace\": {\n return replace(options.args, {\n ...(options?.lineNumbers ? { lineNumbers: options.lineNumbers } : {}),\n });\n }\n case \"import-components\": {\n if (options.args.length === 0) {\n console.info(\"Please provide a file path.\");\n return;\n }\n return importComponents(options.args[0], {\n csvColumnMapping: {\n name: options.componentName,\n text: options.text,\n notes: options.notes,\n tags: options.tags,\n status: options.status,\n componentId: options.componentId,\n },\n });\n }\n default: {\n quit(\"Exiting Ditto CLI...\");\n return;\n }\n }\n};\n\nconst main = async () => {\n setupCommands();\n setupOptions();\n\n if (process.argv.length <= 2 && process.argv[1].includes(\"ditto-cli\")) {\n await executeCommand(\"none\", []);\n return;\n }\n\n program.parse(process.argv);\n};\n\nmain();\n"],"names":["release","path","fs","processMetaOption","addProject","removeProject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uBAAwB;AAExB,8BAAO;AACP,gBAAe;AACf,kBAAiB;AACjB,aAAwB;AACxB,qBAAmC;AAEnC,kBAAyC;AACzC,kBAAqB;AACrB,kBAAqB;AACrB,yBAAuB;AACvB,4BAA0B;AAC1B,qBAAwB;AACxB,kCAAoC;AAEpC,+BAA8B;AAC9B,8BAAiC;AACjC,+BAAqC;AAErC,MAAM,cAAc;AACpB,OAAO,KAAK,EAAE,KAAK,sFAAwB,aAAa,wBAAAA,QAAQ,CAAC;AAEjE,SAAS,aAAqB;AAC5B,QAAM,kBAAkB,YAAAC,QAAK,KAAK,WAAW,MAAM,cAAc;AACjE,QAAM,qBAAqB,UAAAC,QAAG,aAAa,iBAAiB,MAAM;AAClE,QAAM,cAAc,KAAK,MAAM,kBAAkB;AACjD,SA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eAAa;AAEb,MAAI,QAAQ,KAAK,UAAU,KAAK,QAAQ,KAAK,CAAC,EAAE,SAAS,WAAW,GAAG;AACrE,UAAM,eAAe,QAAQ,CAAC,CAAC;AAC/B;AAAA,EACF;AAEA,2BAAQ,MAAM,QAAQ,IAAI;AAC5B;AAEA,KAAK","debug_id":"298d9939-0eee-50da-a0d9-6a4b31b1fd34"}
|
|
1
|
+
{"version":3,"sources":["../lib/ditto.ts"],"sourcesContent":["#!/usr/bin/env node\n// This is the main entry point for the ditto-cli command.\nimport { program } from \"commander\";\n// to use V8's code cache to speed up instantiation time\nimport \"v8-compile-cache\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport * as Sentry from \"@sentry/node\";\nimport { version as release } from \"../package.json\";\n\nimport { init, needsTokenOrSource } from \"./init/init\";\nimport { pull } from \"./pull\";\nimport { quit } from \"./utils/quit\";\nimport addProject from \"./add-project\";\nimport removeProject from \"./remove-project\";\nimport { replace } from \"./replace\";\nimport { generateSuggestions } from \"./generate-suggestions\";\n\nimport processMetaOption from \"./utils/processMetaOption\";\nimport { importComponents } from \"./importComponents\";\nimport { showComponentFolders } from \"./component-folders\";\n\nconst environment = process.env.ENV || \"development\";\nSentry.init({ dsn: process.env.SENTRY_DSN, environment, release });\n\nfunction getVersion(): string {\n const packageJsonPath = path.join(__dirname, \"..\", \"package.json\");\n const packageJsonContent = fs.readFileSync(packageJsonPath, \"utf8\");\n const packageJson = JSON.parse(packageJsonContent) as { version: string };\n return packageJson.version;\n}\n\nconst VERSION = getVersion();\n\nconst CONFIG_FILE_RELIANT_COMMANDS = [\n \"pull\",\n \"none\",\n \"project\",\n \"project add\",\n \"project remove\",\n];\n\ntype Command =\n | \"pull\"\n | \"project\"\n | \"project add\"\n | \"project remove\"\n | \"component-folders\"\n | \"generate-suggestions\"\n | \"replace\"\n | \"import-components\";\n\ninterface CommandConfig<T extends Command | \"add\" | \"remove\"> {\n name: T;\n description: string;\n commands?: CommandConfig<\"add\" | \"remove\">[];\n flags?: {\n [flag: string]: { description: string; processor?: (value: string) => any };\n };\n}\n\nconst COMMANDS: CommandConfig<Command>[] = [\n {\n name: \"pull\",\n description: \"Sync copy from Ditto into the current working directory\",\n },\n {\n name: \"project\",\n description: \"Add a Ditto project to sync copy from\",\n commands: [\n {\n name: \"add\",\n description: \"Add a Ditto project to sync copy from\",\n },\n {\n name: \"remove\",\n description: \"Stop syncing copy from a Ditto project\",\n },\n ],\n },\n {\n name: \"component-folders\",\n description:\n \"List component folders in your workspace. More information about component folders can be found here: https://www.dittowords.com/docs/component-folders.\",\n flags: {\n \"-s, --sample-data\": {\n description: \"Includes the sample components folder in the output\",\n },\n },\n },\n {\n name: \"generate-suggestions\",\n description: \"Find text that can be potentially replaced with Ditto text\",\n flags: {\n \"-d, --directory [value]\": {\n description: \"Directory to search for text\",\n },\n \"-f, --files [value]\": {\n description: \"Files to search for text (will override -d)\",\n processor: (value: string) => value.split(\",\"),\n },\n \"-cf, --component-folder [value]\": {\n description: \"Component folder to search for matches\",\n },\n },\n },\n {\n name: \"replace\",\n description: \"Find and replace Ditto text with code\",\n flags: {\n \"-ln, --line-numbers [value]\": {\n description: \"Only replace text on a specific line number\",\n processor: (value: string) => value.split(\",\").map(Number),\n },\n },\n },\n {\n name: \"import-components\",\n description:\n \"Import components via a file. For more information please see: https://www.dittowords.com/docs/importing-string-files.\",\n flags: {\n \"-t, --text [value]\": {\n description: \"Text column index (.csv format only)\",\n },\n \"-n, --component-name [value]\": {\n description: \"Name column indexes (comma separated) (.csv format only)\",\n },\n \"-no, --notes [value]\": {\n description: \"Notes column index (.csv format only)\",\n },\n \"-t, --tags [value]\": {\n description: \"Tags column index (.csv format only)\",\n },\n \"-s, --status [value]\": {\n description: \"Status column index (.csv format only)\",\n },\n \"-c, --component-id [value]\": {\n description: \"Component ID column index (.csv format only)\",\n },\n },\n },\n];\n\nconst setupCommands = () => {\n program.name(\"ditto-cli\");\n\n COMMANDS.forEach((commandConfig) => {\n const cmd = program\n .command(commandConfig.name)\n .description(commandConfig.description)\n .action((options) => {\n return executeCommand(commandConfig.name, options);\n });\n\n if (commandConfig.flags) {\n Object.entries(commandConfig.flags).forEach(\n ([flags, { description, processor }]) => {\n if (processor) {\n cmd.option(flags, description, processor);\n } else {\n cmd.option(flags, description);\n }\n },\n );\n }\n\n if (\"commands\" in commandConfig && commandConfig.commands) {\n commandConfig.commands.forEach((nestedCommand) => {\n cmd\n .command(nestedCommand.name)\n .description(nestedCommand.description)\n .action((str, options) => {\n if (commandConfig.name === \"project\") {\n const command =\n `${commandConfig.name} ${nestedCommand.name}` as Command;\n\n return executeCommand(command, options);\n }\n });\n });\n }\n });\n};\n\nconst setupOptions = () => {\n program.option(\n \"-m, --meta <data...>\",\n \"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual\",\n );\n program.version(VERSION, \"-v, --version\", \"Output the current version\");\n};\n\nconst executeCommand = async (\n command: Command | \"none\",\n options: any,\n): Promise<void> => {\n const needsInitialization =\n CONFIG_FILE_RELIANT_COMMANDS.includes(command) && needsTokenOrSource();\n\n if (needsInitialization) {\n try {\n await init();\n } catch (error) {\n quit(\"Exiting Ditto CLI...\");\n return;\n }\n }\n\n const { meta } = program.opts();\n switch (command) {\n case \"none\":\n case \"pull\": {\n return pull({ meta: processMetaOption(meta) });\n }\n case \"project\":\n case \"project add\": {\n // initialization already includes the selection of a source,\n // so if `project add` is called during initialization, don't\n // prompt the user to select a source again\n if (needsInitialization) return;\n\n return addProject();\n }\n case \"project remove\": {\n return removeProject();\n }\n case \"component-folders\": {\n return showComponentFolders({\n showSampleData: options.sampleData,\n });\n }\n case \"generate-suggestions\": {\n return generateSuggestions({\n directory: options.directory,\n files: options.files,\n componentFolder: options.componentFolder,\n });\n }\n case \"replace\": {\n return replace(options.args, {\n ...(options?.lineNumbers ? { lineNumbers: options.lineNumbers } : {}),\n });\n }\n case \"import-components\": {\n if (options.args.length === 0) {\n console.info(\"Please provide a file path.\");\n return;\n }\n return importComponents(options.args[0], {\n csvColumnMapping: {\n name: options.componentName,\n text: options.text,\n notes: options.notes,\n tags: options.tags,\n status: options.status,\n componentId: options.componentId,\n },\n });\n }\n default: {\n quit(\"Exiting Ditto CLI...\");\n return;\n }\n }\n};\n\nconst main = async () => {\n setupCommands();\n setupOptions();\n\n if (process.argv.length <= 2 && process.argv[1].includes(\"ditto-cli\")) {\n await executeCommand(\"none\", []);\n return;\n }\n\n program.parse(process.argv);\n};\n\nmain();\n"],"names":["release","path","fs","processMetaOption","addProject","removeProject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uBAAwB;AAExB,8BAAO;AACP,gBAAe;AACf,kBAAiB;AACjB,aAAwB;AACxB,qBAAmC;AAEnC,kBAAyC;AACzC,kBAAqB;AACrB,kBAAqB;AACrB,yBAAuB;AACvB,4BAA0B;AAC1B,qBAAwB;AACxB,kCAAoC;AAEpC,+BAA8B;AAC9B,8BAAiC;AACjC,+BAAqC;AAErC,MAAM,cAAc;AACpB,OAAO,KAAK,EAAE,KAAK,sFAAwB,aAAa,wBAAAA,QAAQ,CAAC;AAEjE,SAAS,aAAqB;AAC5B,QAAM,kBAAkB,YAAAC,QAAK,KAAK,WAAW,MAAM,cAAc;AACjE,QAAM,qBAAqB,UAAAC,QAAG,aAAa,iBAAiB,MAAM;AAClE,QAAM,cAAc,KAAK,MAAM,kBAAkB;AACjD,SAAO,YAAY;AACrB;AAEA,MAAM,UAAU,WAAW;AAE3B,MAAM,+BAA+B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAqBA,MAAM,WAAqC;AAAA,EACzC;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,EACf;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,MACR;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,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}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f22b8e5d-ede9-5c90-a7aa-258036e348df")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -114,7 +114,10 @@ function findComponentsInJSXFiles(params) {
|
|
|
114
114
|
occurrences: {}
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
if (
|
|
117
|
+
if (
|
|
118
|
+
// Skip white space lines
|
|
119
|
+
!/^\s*$/.test(path.node.value) && !/^\s*$/.test(component.text) && path.node.value.includes(component.text)
|
|
120
|
+
) {
|
|
118
121
|
const escapedText = component.text.replace(
|
|
119
122
|
/[.*+?^${}()|[\]\\]/g,
|
|
120
123
|
"\\$&"
|
|
@@ -167,4 +170,4 @@ function replaceAt(str, index, searchString, replacement) {
|
|
|
167
170
|
});
|
|
168
171
|
//# sourceMappingURL=generate-suggestions.js.map
|
|
169
172
|
|
|
170
|
-
//# debugId=
|
|
173
|
+
//# debugId=f22b8e5d-ede9-5c90-a7aa-258036e348df
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/generate-suggestions.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport glob from \"glob\";\nimport { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\n\nimport {\n FetchComponentResponse,\n FetchComponentResponseComponent,\n fetchComponents,\n} from \"./http/fetchComponents\";\n\ninterface Occurrence {\n lineNumber: number;\n preview: string;\n}\n\ninterface Result extends FetchComponentResponseComponent {\n apiId: string;\n occurrences: {\n [file: string]: Occurrence[];\n };\n}\n\nasync function generateSuggestions(flags: {\n directory?: string;\n files?: string[];\n componentFolder?: string;\n}) {\n const components = await fetchComponents({\n
|
|
1
|
+
{"version":3,"sources":["../lib/generate-suggestions.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport glob from \"glob\";\nimport { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\n\nimport {\n FetchComponentResponse,\n FetchComponentResponseComponent,\n fetchComponents,\n} from \"./http/fetchComponents\";\n\ninterface Occurrence {\n lineNumber: number;\n preview: string;\n}\n\ninterface Result extends FetchComponentResponseComponent {\n apiId: string;\n occurrences: {\n [file: string]: Occurrence[];\n };\n}\n\nasync function generateSuggestions(flags: {\n directory?: string;\n files?: string[];\n componentFolder?: string;\n}) {\n const components = await fetchComponents({\n ...(flags.componentFolder\n ? { componentFolder: flags.componentFolder }\n : {}),\n });\n const directory = flags.directory || \".\";\n\n const results: { [apiId: string]: Result } = await findComponentsInJSXFiles({\n directory,\n files: flags.files,\n components,\n });\n\n // Display results to user\n console.log(JSON.stringify(results, null, 2));\n}\n\nasync function findComponentsInJSXFiles(params: {\n directory: string;\n files?: string[];\n components: FetchComponentResponse;\n}): Promise<{ [apiId: string]: Result }> {\n const result: { [apiId: string]: Result } = {};\n const files =\n params.files ||\n glob.sync(`${params.directory}/**/*.+(jsx|tsx)`, {\n ignore: \"**/node_modules/**\",\n });\n\n const promises: Promise<any>[] = [];\n\n for (const file of files) {\n promises.push(\n fs.readFile(file, \"utf-8\").then((code) => {\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"],\n });\n\n traverse(ast, {\n JSXText(path) {\n for (const [compApiId, component] of Object.entries(\n params.components,\n )) {\n // If we haven't seen this component before, add it to the result\n if (!result[compApiId]) {\n result[compApiId] = {\n apiId: compApiId,\n ...component,\n occurrences: {},\n };\n }\n\n if (\n // Skip white space lines\n !/^\\s*$/.test(path.node.value) &&\n !/^\\s*$/.test(component.text) &&\n path.node.value.includes(component.text)\n ) {\n // Escape all special characters from the text so we can use it in a regex\n const escapedText = component.text.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\",\n );\n const regex = new RegExp(escapedText, \"g\");\n let match;\n while ((match = regex.exec(path.node.value)) !== null) {\n const lines = path.node.value\n .slice(0, match.index)\n .split(\"\\n\");\n\n if (!path.node.loc) {\n continue;\n }\n\n const lineNumber =\n path.node.loc.start.line + lines.length - 1;\n\n const codeLines = code.split(\"\\n\");\n const line = codeLines[lineNumber - 1];\n const preview = replaceAt(\n line,\n match.index,\n component.text,\n `${component.text}`,\n );\n\n // Initialize the occurrences array if it doesn't exist\n if (!result[compApiId][\"occurrences\"][file]) {\n result[compApiId][\"occurrences\"][file] = [];\n }\n\n result[compApiId][\"occurrences\"][file].push({\n lineNumber,\n preview,\n });\n }\n }\n\n // Remove from result if no occurrences were found\n if (Object.keys(result[compApiId][\"occurrences\"]).length === 0) {\n delete result[compApiId];\n }\n }\n },\n });\n }),\n );\n }\n\n await Promise.all(promises);\n\n return result;\n}\n\nfunction replaceAt(\n str: string,\n index: number,\n searchString: string,\n replacement: string,\n) {\n return (\n str.substring(0, index) +\n str.substring(index, str.length).replace(searchString, replacement)\n );\n}\n\nexport { findComponentsInJSXFiles, generateSuggestions };\n"],"names":["glob","fs","traverse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAe;AACf,kBAAiB;AACjB,oBAAsB;AACtB,sBAAqB;AAErB,6BAIO;AAcP,SAAe,oBAAoB,OAIhC;AAAA;AACD,UAAM,aAAa,UAAM,wCAAgB,mBACnC,MAAM,kBACN,EAAE,iBAAiB,MAAM,gBAAgB,IACzC,CAAC,EACN;AACD,UAAM,YAAY,MAAM,aAAa;AAErC,UAAM,UAAuC,MAAM,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,MAAM,KAAK,EACpB,MAAM,IAAI;AAEb,wBAAI,CAAC,KAAK,KAAK,KAAK;AAClB;AAAA,oBACF;AAEA,0BAAM,aACJ,KAAK,KAAK,IAAI,MAAM,OAAO,MAAM,SAAS;AAE5C,0BAAM,YAAY,KAAK,MAAM,IAAI;AACjC,0BAAM,OAAO,UAAU,aAAa,CAAC;AACrC,0BAAM,UAAU;AAAA,sBACd;AAAA,sBACA,MAAM;AAAA,sBACN,UAAU;AAAA,sBACV,GAAG,UAAU,IAAI;AAAA,oBACnB;AAGA,wBAAI,CAAC,OAAO,SAAS,EAAE,aAAa,EAAE,IAAI,GAAG;AAC3C,6BAAO,SAAS,EAAE,aAAa,EAAE,IAAI,IAAI,CAAC;AAAA,oBAC5C;AAEA,2BAAO,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK;AAAA,sBAC1C;AAAA,sBACA;AAAA,oBACF,CAAC;AAAA,kBACH;AAAA,gBACF;AAGA,oBAAI,OAAO,KAAK,OAAO,SAAS,EAAE,aAAa,CAAC,EAAE,WAAW,GAAG;AAC9D,yBAAO,OAAO,SAAS;AAAA,gBACzB;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,QAAQ,IAAI,QAAQ;AAE1B,WAAO;AAAA,EACT;AAAA;AAEA,SAAS,UACP,KACA,OACA,cACA,aACA;AACA,SACE,IAAI,UAAU,GAAG,KAAK,IACtB,IAAI,UAAU,OAAO,IAAI,MAAM,EAAE,QAAQ,cAAc,WAAW;AAEtE","debug_id":"f22b8e5d-ede9-5c90-a7aa-258036e348df"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="18334cda-4915-5b0f-9ca7-67da352f382b")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -62,7 +62,7 @@ function fetchComponents(options) {
|
|
|
62
62
|
}
|
|
63
63
|
} else {
|
|
64
64
|
const { data } = yield api.get(
|
|
65
|
-
"/v1/components",
|
|
65
|
+
"/v1/components?format=structured",
|
|
66
66
|
{}
|
|
67
67
|
);
|
|
68
68
|
return data;
|
|
@@ -75,4 +75,4 @@ function fetchComponents(options) {
|
|
|
75
75
|
});
|
|
76
76
|
//# sourceMappingURL=fetchComponents.js.map
|
|
77
77
|
|
|
78
|
-
//# debugId=
|
|
78
|
+
//# debugId=18334cda-4915-5b0f-9ca7-67da352f382b
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/http/fetchComponents.ts"],"sourcesContent":["import { createApiClient } from \"../api\";\n\nexport interface FetchComponentResponseComponent {\n name: string;\n text: string;\n status: \"NONE\" | \"WIP\" | \"REVIEW\" | \"FINAL\";\n folder: \"string\" | null;\n}\n\nexport interface FetchComponentResponse {\n [compApiId: string]: FetchComponentResponseComponent;\n}\n\nexport async function fetchComponents(options: {\n componentFolder?: string;\n}): Promise<FetchComponentResponse> {\n const api = createApiClient();\n\n if (options.componentFolder) {\n try {\n const { data } = await api.get<FetchComponentResponse>(\n `/v1/component-folders/${options.componentFolder}/components`,\n {}\n );\n\n return data;\n } catch (e) {\n console.log(\n `Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`\n );\n return {};\n }\n } else {\n const { data } = await api.get<FetchComponentResponse>(\n \"/v1/components\",\n {}\n );\n\n return data;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgC;AAahC,SAAsB,gBAAgB,SAEF;AAAA;AAClC,UAAM,UAAM,4BAAgB;AAE5B,QAAI,QAAQ,iBAAiB;AAC3B,UAAI;AACF,cAAM,EAAE,KAAK,IAAI,MAAM,IAAI;AAAA,UACzB,yBAAyB,QAAQ,eAAe;AAAA,UAChD,CAAC;AAAA,QACH;AAEA,eAAO;AAAA,MACT,SAAS,GAAG;AACV,gBAAQ;AAAA,UACN,gCAAgC,QAAQ,eAAe;AAAA,QACzD;AACA,eAAO,CAAC;AAAA,MACV;AAAA,IACF,OAAO;AACL,YAAM,EAAE,KAAK,IAAI,MAAM,IAAI;AAAA,QACzB;AAAA,QACA,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAAA","debug_id":"
|
|
1
|
+
{"version":3,"sources":["../../lib/http/fetchComponents.ts"],"sourcesContent":["import { createApiClient } from \"../api\";\n\nexport interface FetchComponentResponseComponent {\n name: string;\n text: string;\n status: \"NONE\" | \"WIP\" | \"REVIEW\" | \"FINAL\";\n folder: \"string\" | null;\n}\n\nexport interface FetchComponentResponse {\n [compApiId: string]: FetchComponentResponseComponent;\n}\n\nexport async function fetchComponents(options: {\n componentFolder?: string;\n}): Promise<FetchComponentResponse> {\n const api = createApiClient();\n\n if (options.componentFolder) {\n try {\n const { data } = await api.get<FetchComponentResponse>(\n `/v1/component-folders/${options.componentFolder}/components`,\n {}\n );\n\n return data;\n } catch (e) {\n console.log(\n `Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`\n );\n return {};\n }\n } else {\n const { data } = await api.get<FetchComponentResponse>(\n \"/v1/components?format=structured\",\n {}\n );\n\n return data;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgC;AAahC,SAAsB,gBAAgB,SAEF;AAAA;AAClC,UAAM,UAAM,4BAAgB;AAE5B,QAAI,QAAQ,iBAAiB;AAC3B,UAAI;AACF,cAAM,EAAE,KAAK,IAAI,MAAM,IAAI;AAAA,UACzB,yBAAyB,QAAQ,eAAe;AAAA,UAChD,CAAC;AAAA,QACH;AAEA,eAAO;AAAA,MACT,SAAS,GAAG;AACV,gBAAQ;AAAA,UACN,gCAAgC,QAAQ,eAAe;AAAA,QACzD;AACA,eAAO,CAAC;AAAA,MACV;AAAA,IACF,OAAO;AACL,YAAM,EAAE,KAAK,IAAI,MAAM,IAAI;AAAA,QACzB;AAAA,QACA,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAAA","debug_id":"18334cda-4915-5b0f-9ca7-67da352f382b"}
|
package/bin/pull.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="130de1f8-09ed-546e-b0a2-30a311da1206")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -378,7 +378,7 @@ Fetching the latest text from ${(0, import_sourcesToText.default)(
|
|
|
378
378
|
});
|
|
379
379
|
const nameExt = getFormatExtension(format);
|
|
380
380
|
const nameBase = "components";
|
|
381
|
-
const nameFolder = `__${componentFolder.name}`;
|
|
381
|
+
const nameFolder = `__${(0, import_cleanFileName.cleanFileName)(componentFolder.name)}`;
|
|
382
382
|
const namePostfix = `__${variantApiId || "base"}`;
|
|
383
383
|
const fileName = (0, import_cleanFileName.cleanFileName)(
|
|
384
384
|
`${nameBase}${nameFolder}${namePostfix}${nameExt}`
|
|
@@ -544,4 +544,4 @@ var pull_default = {
|
|
|
544
544
|
});
|
|
545
545
|
//# sourceMappingURL=pull.js.map
|
|
546
546
|
|
|
547
|
-
//# debugId=
|
|
547
|
+
//# debugId=130de1f8-09ed-546e-b0a2-30a311da1206
|
package/bin/pull.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/pull.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport ora from \"ora\";\nimport * as Sentry from \"@sentry/node\";\n\nimport { createApiClient } from \"./api\";\nimport config from \"./config\";\nimport consts from \"./consts\";\nimport output from \"./output\";\nimport { collectAndSaveToken } from \"./init/token\";\nimport sourcesToText from \"./utils/sourcesToText\";\nimport { generateJsDriver } from \"./utils/generateJsDriver\";\nimport { cleanFileName } from \"./utils/cleanFileName\";\nimport {\n SourceInformation,\n Token,\n Project,\n SupportedFormat,\n ComponentFolder,\n ComponentSource,\n Source,\n} from \"./types\";\nimport { fetchVariants } from \"./http/fetchVariants\";\nimport { quit } from \"./utils/quit\";\nimport { AxiosError } from \"axios\";\nimport { fetchComponentFolders } from \"./http/fetchComponentFolders\";\nimport { generateSwiftDriver } from \"./utils/generateSwiftDriver\";\nimport { generateIOSBundles } from \"./utils/generateIOSBundles\";\n\ninterface IRequestOptions {\n projects: Project[];\n format: SupportedFormat;\n status: string | undefined;\n richText?: boolean | undefined;\n token?: Token;\n options?: PullOptions;\n}\n\ninterface IRequestOptionsWithVariants extends IRequestOptions {\n variants: { apiID: string }[];\n}\n\nconst ensureEndsWithNewLine = (str: string) =>\n str + (/[\\r\\n]$/.test(str) ? \"\" : \"\\n\");\n\nexport const writeFile = (path: string, data: string) =>\n new Promise((r) => fs.writeFile(path, ensureEndsWithNewLine(data), r));\n\nconst SUPPORTED_FORMATS: SupportedFormat[] = [\n \"flat\",\n \"structured\",\n \"android\",\n \"ios-strings\",\n \"ios-stringsdict\",\n \"icu\",\n];\n\nexport type JSONFormat = \"flat\" | \"nested\" | \"structured\" | \"icu\";\n\nconst IOS_FORMATS: SupportedFormat[] = [\"ios-strings\", \"ios-stringsdict\"];\nconst JSON_FORMATS: JSONFormat[] = [\"flat\", \"structured\", \"icu\"];\n\nconst getJsonFormat = (formats: string[]): JSONFormat => {\n // edge case: multiple json formats specified\n // we should grab the last one\n const jsonFormats = formats.filter((f) =>\n JSON_FORMATS.includes(f as JSONFormat)\n ) as JSONFormat[];\n\n return jsonFormats[jsonFormats.length - 1] || \"flat\";\n};\n\nconst FORMAT_EXTENSIONS = {\n flat: \".json\",\n structured: \".json\",\n android: \".xml\",\n \"ios-strings\": \".strings\",\n \"ios-stringsdict\": \".stringsdict\",\n icu: \".json\",\n};\n\nconst getJsonFormatIsValid = (data: string) => {\n try {\n return Object.keys(JSON.parse(data)).some(\n (k) => !k.startsWith(\"__variant\")\n );\n } catch {\n return false;\n }\n};\n\n// exported for test usage only\nexport const getFormatDataIsValid = {\n flat: getJsonFormatIsValid,\n structured: getJsonFormatIsValid,\n icu: getJsonFormatIsValid,\n android: (data: string) => data.includes(\"<string\"),\n \"ios-strings\": (data: string) => data.includes(`\" = \"`),\n \"ios-stringsdict\": (data: string) => data.includes(\"<key>\"),\n};\n\nconst getFormat = (\n formatFromSource: string | string[] | undefined\n): SupportedFormat[] => {\n const formats = (\n Array.isArray(formatFromSource) ? formatFromSource : [formatFromSource]\n ).filter((format) =>\n SUPPORTED_FORMATS.includes(format as SupportedFormat)\n ) as SupportedFormat[];\n\n if (formats.length) {\n return formats;\n }\n\n return [\"flat\"];\n};\n\nconst getFormatExtension = (format: SupportedFormat) => {\n return FORMAT_EXTENSIONS[format];\n};\n\nconst DEFAULT_FORMAT_KEYS = [\"projects\", \"exported_at\"];\nconst hasVariantData = (data: any) => {\n const hasTopLevelKeys =\n Object.keys(data).filter((key) => !DEFAULT_FORMAT_KEYS.includes(key))\n .length > 0;\n\n const hasProjectKeys = data.projects && Object.keys(data.projects).length > 0;\n\n return hasTopLevelKeys || hasProjectKeys;\n};\n\nasync function askForAnotherToken() {\n config.deleteToken(consts.CONFIG_FILE, consts.API_HOST);\n const message =\n \"Looks like the API key you have saved no longer works. Please enter another one.\";\n await collectAndSaveToken(message);\n}\n\n/**\n * For a given variant:\n * - if format is unspecified, fetch data for all projects from `/projects` and\n * save in `{variantApiId}.json`\n * - if format is `flat` or `structured`, fetch data for each project from `/project/:project_id` and\n * save in `{projectName}-${variantApiId}.json`\n */\nasync function downloadAndSaveVariant(\n variantApiId: string | null,\n requestOptions: IRequestOptions\n) {\n const { projects, format, status, richText, token } = requestOptions;\n const api = createApiClient();\n const params: Record<string, string | null> = { variant: variantApiId };\n if (format) params.format = format;\n if (richText) params.includeRichText = richText.toString();\n\n // Root-level status gets set as the default if specified\n if (status) params.status = status;\n\n const savedMessages = await Promise.all(\n projects.map(async (project) => {\n const projectParams = { ...params };\n // If project-level status is specified, overrides root-level status\n if (project.status) projectParams.status = project.status;\n if (project.exclude_components)\n projectParams.exclude_components = String(project.exclude_components);\n\n const { data } = await api.get(`/v1/projects/${project.id}`, {\n params: projectParams,\n headers: { Authorization: `token ${token}` },\n });\n\n if (!hasVariantData(data)) {\n return \"\";\n }\n\n const extension = getFormatExtension(format);\n\n const filename = cleanFileName(\n project.fileName + (\"__\" + (variantApiId || \"base\")) + extension\n );\n const filepath = path.join(consts.TEXT_DIR, filename);\n\n let dataString = data;\n if (extension === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filepath, dataString);\n return getSavedMessage(filename);\n })\n );\n\n return savedMessages.join(\"\");\n}\n\nasync function downloadAndSaveVariants(\n requestOptions: IRequestOptionsWithVariants\n) {\n const messages = await Promise.all([\n downloadAndSaveVariant(null, requestOptions),\n ...requestOptions.variants.map(({ apiID }: { apiID: string }) =>\n downloadAndSaveVariant(apiID, requestOptions)\n ),\n ]);\n\n return messages.join(\"\");\n}\n\nasync function downloadAndSaveBase(requestOptions: IRequestOptions) {\n const { projects, format, status, richText, token, options } = requestOptions;\n\n const api = createApiClient();\n const params = { ...options?.meta };\n if (format) params.format = format;\n if (richText) params.includeRichText = richText.toString();\n\n // Root-level status gets set as the default if specified\n if (status) params.status = status;\n\n const savedMessages = await Promise.all(\n projects.map(async (project) => {\n const projectParams = { ...params };\n // If project-level status is specified, overrides root-level status\n if (project.status) projectParams.status = project.status;\n if (project.exclude_components)\n projectParams.exclude_components = String(project.exclude_components);\n\n const { data } = await api.get(`/v1/projects/${project.id}`, {\n params: projectParams,\n headers: { Authorization: `token ${token}` },\n });\n\n const extension = getFormatExtension(format);\n const filename = cleanFileName(`${project.fileName}__base${extension}`);\n const filepath = path.join(consts.TEXT_DIR, filename);\n\n let dataString = data;\n if (extension === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filepath, dataString);\n return getSavedMessage(filename);\n })\n );\n\n return savedMessages.join(\"\");\n}\n\nfunction getSavedMessage(file: string) {\n return `Successfully saved to ${output.info(file)}\\n`;\n}\n\nfunction cleanOutputFiles() {\n if (!fs.existsSync(consts.TEXT_DIR)) {\n fs.mkdirSync(consts.TEXT_DIR);\n }\n\n const directoryContents = fs.readdirSync(consts.TEXT_DIR, {\n withFileTypes: true,\n });\n\n directoryContents.forEach((item) => {\n if (item.isDirectory() && /\\.lproj$/.test(item.name)) {\n return fs.rmSync(path.resolve(consts.TEXT_DIR, item.name), {\n recursive: true,\n force: true,\n });\n }\n\n if (\n item.isFile() &&\n /\\.js(on)?|\\.xml|\\.strings(dict)?$|\\.swift$/.test(item.name)\n ) {\n return fs.unlinkSync(path.resolve(consts.TEXT_DIR, item.name));\n }\n });\n\n return \"Cleaning old output files..\\n\";\n}\n\nasync function downloadAndSave(\n source: SourceInformation,\n token?: Token,\n options?: PullOptions\n) {\n const api = createApiClient();\n const {\n validProjects,\n format: formatFromSource,\n shouldFetchComponentLibrary,\n status,\n richText,\n componentFolders: specifiedComponentFolders,\n componentRoot,\n localeByVariantApiId,\n } = source;\n\n const formats = getFormat(formatFromSource);\n\n const hasJSONFormat = formats.some((f) =>\n JSON_FORMATS.includes(f as JSONFormat)\n );\n const hasIOSFormat = formats.some((f) => IOS_FORMATS.includes(f));\n const shouldGenerateIOSBundles = hasIOSFormat && localeByVariantApiId;\n\n const shouldLogOutputFiles = !shouldGenerateIOSBundles;\n\n let msg = \"\";\n const spinner = ora(msg);\n spinner.start();\n\n const [variants, allComponentFoldersResponse] = await Promise.all([\n fetchVariants(source),\n fetchComponentFolders({}),\n ]);\n\n const allComponentFolders = Object.entries(\n allComponentFoldersResponse\n ).reduce(\n (acc, [id, name]) => acc.concat([{ id, name }]),\n [] as ComponentFolder[]\n );\n\n try {\n msg += cleanOutputFiles();\n msg += `\\nFetching the latest text from ${sourcesToText(\n validProjects,\n shouldFetchComponentLibrary\n )}\\n`;\n\n const meta = options ? options.meta : {};\n\n const rootRequest = {\n id: \"__root__\",\n name: \"Root\",\n // componentRoot can be a boolean or an object\n status:\n typeof source.componentRoot === \"object\"\n ? source.componentRoot.status\n : undefined,\n };\n\n let componentFolderRequests: ComponentFolder[] = [];\n\n // there's a lot of complex logic here, and it's tempting to want to\n // simplify it. however, it's difficult to get rid of the complexity\n // without sacrificing specificity and expressiveness.\n //\n // if folders specified..\n if (specifiedComponentFolders) {\n switch (componentRoot) {\n // .. and no root specified, you only get components in the specified folders\n case undefined:\n case false:\n componentFolderRequests.push(...specifiedComponentFolders);\n break;\n // .. and root specified, you get components in folders and the root\n default:\n componentFolderRequests.push(...specifiedComponentFolders);\n componentFolderRequests.push(rootRequest);\n break;\n }\n }\n // if no folders specified..\n else {\n switch (componentRoot) {\n // .. and no root specified, you get all components including those in folders\n case undefined:\n componentFolderRequests.push(...allComponentFolders);\n componentFolderRequests.push(rootRequest);\n break;\n // .. and root specified as false, you only get components in folders\n case false:\n componentFolderRequests.push(...allComponentFolders);\n break;\n // .. and root specified as true or config object, you only get components in the root\n default:\n componentFolderRequests.push(rootRequest);\n break;\n }\n }\n\n // this array is populated while fetching from the component library and is used when\n // generating the index.js driver file\n const componentSources: ComponentSource[] = [];\n\n async function fetchComponentLibrary(format: SupportedFormat) {\n // Always include a variant with an apiID of undefined to ensure that we\n // fetch the base text for the component library.\n const componentVariants = [{ apiID: undefined }, ...(variants || [])];\n\n const params = new URLSearchParams();\n if (options?.meta)\n Object.entries(options.meta).forEach(([k, v]) => params.append(k, v));\n if (format) params.append(\"format\", format);\n if (richText) params.append(\"includeRichText\", richText.toString());\n\n // Root-level status gets set as the default if specified\n if (status) params.append(\"status\", status);\n\n const messagePromises: Promise<string>[] = [];\n\n componentVariants.forEach(({ apiID: variantApiId }) => {\n messagePromises.push(\n ...componentFolderRequests.map(async (componentFolder) => {\n const componentFolderParams = new URLSearchParams(params);\n\n if (variantApiId)\n componentFolderParams.append(\"variant\", variantApiId);\n\n // If folder-level status is specified, overrides root-level status\n if (componentFolder.status)\n componentFolderParams.append(\"status\", componentFolder.status);\n\n const url =\n componentFolder.id === \"__root__\"\n ? \"/v1/components?root_only=true\"\n : `/v1/component-folders/${componentFolder.id}/components`;\n\n const { data } = await api.get(url, {\n params: componentFolderParams,\n });\n\n const nameExt = getFormatExtension(format);\n const nameBase = \"components\";\n const nameFolder = `__${componentFolder.name}`;\n const namePostfix = `__${variantApiId || \"base\"}`;\n\n const fileName = cleanFileName(\n `${nameBase}${nameFolder}${namePostfix}${nameExt}`\n );\n const filePath = path.join(consts.TEXT_DIR, fileName);\n\n let dataString = data;\n if (nameExt === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filePath, dataString);\n\n componentSources.push({\n type: \"components\",\n id: \"ditto_component_library\",\n name: \"ditto_component_library\",\n fileName,\n variant: variantApiId || \"base\",\n });\n\n return getSavedMessage(fileName);\n })\n );\n });\n\n const messages = await Promise.all(messagePromises);\n if (shouldLogOutputFiles) {\n msg += messages.join(\"\");\n }\n }\n\n if (shouldFetchComponentLibrary) {\n for (const format of formats) {\n await fetchComponentLibrary(format);\n }\n }\n\n async function fetchProjects(format: SupportedFormat) {\n let result = \"\";\n if (variants) {\n result = await downloadAndSaveVariants({\n variants,\n projects: validProjects,\n format,\n status,\n richText,\n token,\n });\n } else {\n result = await downloadAndSaveBase({\n projects: validProjects,\n format,\n status,\n richText,\n token,\n options: {\n meta,\n },\n });\n }\n\n if (shouldLogOutputFiles) {\n msg += result;\n }\n }\n\n if (validProjects.length) {\n for (const format of formats) {\n await fetchProjects(format);\n }\n }\n\n const sources: Source[] = [...validProjects, ...componentSources];\n\n if (hasJSONFormat) msg += generateJsDriver(sources, getJsonFormat(formats));\n\n if (shouldGenerateIOSBundles) {\n msg += \"iOS locale information detected, generating bundles..\\n\\n\";\n msg += await generateIOSBundles(localeByVariantApiId);\n msg += await generateSwiftDriver(source);\n }\n\n msg += `\\n\\n${output.success(\"Done\")}!`;\n\n spinner.stop();\n return console.log(msg);\n } catch (e: any) {\n console.error(e);\n\n spinner.stop();\n let error = e.message;\n if (e.response && e.response.status === 404) {\n await askForAnotherToken();\n pull();\n return;\n }\n if (e.response && e.response.status === 401) {\n error = \"You don't have access to the selected projects\";\n msg = `${output.errorText(error)}.\\nChoose others using the ${output.info(\n \"project\"\n )} command, or update your API key.`;\n return console.log(msg);\n }\n if (e.response && e.response.status === 403) {\n error =\n \"One or more of the requested projects don't have Developer Mode enabled\";\n msg = `${output.errorText(\n error\n )}.\\nPlease choose different projects using the ${output.info(\n \"project\"\n )} command, or turn on Developer Mode for all selected projects. Learn more here: ${output.subtle(\n \"https://www.dittowords.com/docs/ditto-developer-mode\"\n )}.`;\n return console.log(msg);\n }\n if (e.response && e.response.status === 400) {\n error = \"projects not found\";\n }\n msg = `We hit an error fetching text from the projects: ${output.errorText(\n error\n )}.\\nChoose others using the ${output.info(\"project\")} command.`;\n return console.log(msg);\n }\n}\n\nexport interface PullOptions {\n meta?: Record<string, string>;\n}\n\nexport const pull = async (options?: PullOptions) => {\n const meta = options ? options.meta : {};\n const token = config.getToken(consts.CONFIG_FILE, consts.API_HOST);\n const sourceInformation = config.parseSourceInformation();\n\n try {\n return await downloadAndSave(sourceInformation, token, { meta });\n } catch (e) {\n const eventId = Sentry.captureException(e);\n const eventStr = `\\n\\nError ID: ${output.info(eventId)}`;\n if (e instanceof AxiosError) {\n return quit(\n output.errorText(\n \"Something went wrong connecting to Ditto servers. Please contact support or try again later.\"\n ) + eventStr\n );\n }\n\n return quit(\n output.errorText(\n \"Something went wrong. Please contact support or try again later.\"\n ) + eventStr\n );\n }\n};\n\nexport default {\n pull,\n _testing: {\n cleanOutputFiles,\n downloadAndSaveVariant,\n downloadAndSaveVariants,\n downloadAndSaveBase,\n },\n};\n"],"names":["path","fs","config","consts","output","ora","sourcesToText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAEjB,iBAAgB;AAChB,aAAwB;AAExB,iBAAgC;AAChC,oBAAmB;AACnB,oBAAmB;AACnB,oBAAmB;AACnB,mBAAoC;AACpC,2BAA0B;AAC1B,8BAAiC;AACjC,2BAA8B;AAU9B,2BAA8B;AAC9B,kBAAqB;AACrB,mBAA2B;AAC3B,mCAAsC;AACtC,iCAAoC;AACpC,gCAAmC;AAenC,MAAM,wBAAwB,CAAC,QAC7B,OAAO,UAAU,KAAK,GAAG,IAAI,KAAK;AAE7B,MAAM,YAAY,CAACA,OAAc,SACtC,IAAI,QAAQ,CAAC,MAAM,UAAAC,QAAG,UAAUD,OAAM,sBAAsB,IAAI,GAAG,CAAC,CAAC;AAEvE,MAAM,oBAA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UACvD;AAAA,QACF,CAAC,mFAAmF,cAAAA,QAAO;AAAA,UACzF;AAAA,QACF,CAAC;AACD,eAAO,QAAQ,IAAI,GAAG;AAAA,MACxB;AACA,UAAI,EAAE,YAAY,EAAE,SAAS,WAAW,KAAK;AAC3C,gBAAQ;AAAA,MACV;AACA,YAAM,oDAAoD,cAAAA,QAAO;AAAA,QAC/D;AAAA,MACF,CAAC;AAAA,0BAA8B,cAAAA,QAAO,KAAK,SAAS,CAAC;AACrD,aAAO,QAAQ,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA;AAMO,MAAM,OAAO,CAAO,YAA0B;AACnD,QAAM,OAAO,UAAU,QAAQ,OAAO,CAAC;AACvC,QAAM,QAAQ,cAAAF,QAAO,SAAS,cAAAC,QAAO,aAAa,cAAAA,QAAO,QAAQ;AACjE,QAAM,oBAAoB,cAAAD,QAAO,uBAAuB;AAExD,MAAI;AACF,WAAO,MAAM,gBAAgB,mBAAmB,OAAO,EAAE,KAAK,CAAC;AAAA,EACjE,SAAS,GAAG;AACV,UAAM,UAAU,OAAO,iBAAiB,CAAC;AACzC,UAAM,WAAW;AAAA;AAAA,YAAiB,cAAAE,QAAO,KAAK,OAAO,CAAC;AACtD,QAAI,aAAa,yBAAY;AAC3B,iBAAO;AAAA,QACL,cAAAA,QAAO;AAAA,UACL;AAAA,QACF,IAAI;AAAA,MACN;AAAA,IACF;AAEA,eAAO;AAAA,MACL,cAAAA,QAAO;AAAA,QACL;AAAA,MACF,IAAI;AAAA,IACN;AAAA,EACF;AACF;AAEA,IAAO,eAAQ;AAAA,EACb;AAAA,EACA,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","debug_id":"c8688159-ec02-55a6-900a-28847c915aa3"}
|
|
1
|
+
{"version":3,"sources":["../lib/pull.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport ora from \"ora\";\nimport * as Sentry from \"@sentry/node\";\n\nimport { createApiClient } from \"./api\";\nimport config from \"./config\";\nimport consts from \"./consts\";\nimport output from \"./output\";\nimport { collectAndSaveToken } from \"./init/token\";\nimport sourcesToText from \"./utils/sourcesToText\";\nimport { generateJsDriver } from \"./utils/generateJsDriver\";\nimport { cleanFileName } from \"./utils/cleanFileName\";\nimport {\n SourceInformation,\n Token,\n Project,\n SupportedFormat,\n ComponentFolder,\n ComponentSource,\n Source,\n} from \"./types\";\nimport { fetchVariants } from \"./http/fetchVariants\";\nimport { quit } from \"./utils/quit\";\nimport { AxiosError } from \"axios\";\nimport { fetchComponentFolders } from \"./http/fetchComponentFolders\";\nimport { generateSwiftDriver } from \"./utils/generateSwiftDriver\";\nimport { generateIOSBundles } from \"./utils/generateIOSBundles\";\n\ninterface IRequestOptions {\n projects: Project[];\n format: SupportedFormat;\n status: string | undefined;\n richText?: boolean | undefined;\n token?: Token;\n options?: PullOptions;\n}\n\ninterface IRequestOptionsWithVariants extends IRequestOptions {\n variants: { apiID: string }[];\n}\n\nconst ensureEndsWithNewLine = (str: string) =>\n str + (/[\\r\\n]$/.test(str) ? \"\" : \"\\n\");\n\nexport const writeFile = (path: string, data: string) =>\n new Promise((r) => fs.writeFile(path, ensureEndsWithNewLine(data), r));\n\nconst SUPPORTED_FORMATS: SupportedFormat[] = [\n \"flat\",\n \"structured\",\n \"android\",\n \"ios-strings\",\n \"ios-stringsdict\",\n \"icu\",\n];\n\nexport type JSONFormat = \"flat\" | \"nested\" | \"structured\" | \"icu\";\n\nconst IOS_FORMATS: SupportedFormat[] = [\"ios-strings\", \"ios-stringsdict\"];\nconst JSON_FORMATS: JSONFormat[] = [\"flat\", \"structured\", \"icu\"];\n\nconst getJsonFormat = (formats: string[]): JSONFormat => {\n // edge case: multiple json formats specified\n // we should grab the last one\n const jsonFormats = formats.filter((f) =>\n JSON_FORMATS.includes(f as JSONFormat)\n ) as JSONFormat[];\n\n return jsonFormats[jsonFormats.length - 1] || \"flat\";\n};\n\nconst FORMAT_EXTENSIONS = {\n flat: \".json\",\n structured: \".json\",\n android: \".xml\",\n \"ios-strings\": \".strings\",\n \"ios-stringsdict\": \".stringsdict\",\n icu: \".json\",\n};\n\nconst getJsonFormatIsValid = (data: string) => {\n try {\n return Object.keys(JSON.parse(data)).some(\n (k) => !k.startsWith(\"__variant\")\n );\n } catch {\n return false;\n }\n};\n\n// exported for test usage only\nexport const getFormatDataIsValid = {\n flat: getJsonFormatIsValid,\n structured: getJsonFormatIsValid,\n icu: getJsonFormatIsValid,\n android: (data: string) => data.includes(\"<string\"),\n \"ios-strings\": (data: string) => data.includes(`\" = \"`),\n \"ios-stringsdict\": (data: string) => data.includes(\"<key>\"),\n};\n\nconst getFormat = (\n formatFromSource: string | string[] | undefined\n): SupportedFormat[] => {\n const formats = (\n Array.isArray(formatFromSource) ? formatFromSource : [formatFromSource]\n ).filter((format) =>\n SUPPORTED_FORMATS.includes(format as SupportedFormat)\n ) as SupportedFormat[];\n\n if (formats.length) {\n return formats;\n }\n\n return [\"flat\"];\n};\n\nconst getFormatExtension = (format: SupportedFormat) => {\n return FORMAT_EXTENSIONS[format];\n};\n\nconst DEFAULT_FORMAT_KEYS = [\"projects\", \"exported_at\"];\nconst hasVariantData = (data: any) => {\n const hasTopLevelKeys =\n Object.keys(data).filter((key) => !DEFAULT_FORMAT_KEYS.includes(key))\n .length > 0;\n\n const hasProjectKeys = data.projects && Object.keys(data.projects).length > 0;\n\n return hasTopLevelKeys || hasProjectKeys;\n};\n\nasync function askForAnotherToken() {\n config.deleteToken(consts.CONFIG_FILE, consts.API_HOST);\n const message =\n \"Looks like the API key you have saved no longer works. Please enter another one.\";\n await collectAndSaveToken(message);\n}\n\n/**\n * For a given variant:\n * - if format is unspecified, fetch data for all projects from `/projects` and\n * save in `{variantApiId}.json`\n * - if format is `flat` or `structured`, fetch data for each project from `/project/:project_id` and\n * save in `{projectName}-${variantApiId}.json`\n */\nasync function downloadAndSaveVariant(\n variantApiId: string | null,\n requestOptions: IRequestOptions\n) {\n const { projects, format, status, richText, token } = requestOptions;\n const api = createApiClient();\n const params: Record<string, string | null> = { variant: variantApiId };\n if (format) params.format = format;\n if (richText) params.includeRichText = richText.toString();\n\n // Root-level status gets set as the default if specified\n if (status) params.status = status;\n\n const savedMessages = await Promise.all(\n projects.map(async (project) => {\n const projectParams = { ...params };\n // If project-level status is specified, overrides root-level status\n if (project.status) projectParams.status = project.status;\n if (project.exclude_components)\n projectParams.exclude_components = String(project.exclude_components);\n\n const { data } = await api.get(`/v1/projects/${project.id}`, {\n params: projectParams,\n headers: { Authorization: `token ${token}` },\n });\n\n if (!hasVariantData(data)) {\n return \"\";\n }\n\n const extension = getFormatExtension(format);\n\n const filename = cleanFileName(\n project.fileName + (\"__\" + (variantApiId || \"base\")) + extension\n );\n const filepath = path.join(consts.TEXT_DIR, filename);\n\n let dataString = data;\n if (extension === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filepath, dataString);\n return getSavedMessage(filename);\n })\n );\n\n return savedMessages.join(\"\");\n}\n\nasync function downloadAndSaveVariants(\n requestOptions: IRequestOptionsWithVariants\n) {\n const messages = await Promise.all([\n downloadAndSaveVariant(null, requestOptions),\n ...requestOptions.variants.map(({ apiID }: { apiID: string }) =>\n downloadAndSaveVariant(apiID, requestOptions)\n ),\n ]);\n\n return messages.join(\"\");\n}\n\nasync function downloadAndSaveBase(requestOptions: IRequestOptions) {\n const { projects, format, status, richText, token, options } = requestOptions;\n\n const api = createApiClient();\n const params = { ...options?.meta };\n if (format) params.format = format;\n if (richText) params.includeRichText = richText.toString();\n\n // Root-level status gets set as the default if specified\n if (status) params.status = status;\n\n const savedMessages = await Promise.all(\n projects.map(async (project) => {\n const projectParams = { ...params };\n // If project-level status is specified, overrides root-level status\n if (project.status) projectParams.status = project.status;\n if (project.exclude_components)\n projectParams.exclude_components = String(project.exclude_components);\n\n const { data } = await api.get(`/v1/projects/${project.id}`, {\n params: projectParams,\n headers: { Authorization: `token ${token}` },\n });\n\n const extension = getFormatExtension(format);\n const filename = cleanFileName(`${project.fileName}__base${extension}`);\n const filepath = path.join(consts.TEXT_DIR, filename);\n\n let dataString = data;\n if (extension === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filepath, dataString);\n return getSavedMessage(filename);\n })\n );\n\n return savedMessages.join(\"\");\n}\n\nfunction getSavedMessage(file: string) {\n return `Successfully saved to ${output.info(file)}\\n`;\n}\n\nfunction cleanOutputFiles() {\n if (!fs.existsSync(consts.TEXT_DIR)) {\n fs.mkdirSync(consts.TEXT_DIR);\n }\n\n const directoryContents = fs.readdirSync(consts.TEXT_DIR, {\n withFileTypes: true,\n });\n\n directoryContents.forEach((item) => {\n if (item.isDirectory() && /\\.lproj$/.test(item.name)) {\n return fs.rmSync(path.resolve(consts.TEXT_DIR, item.name), {\n recursive: true,\n force: true,\n });\n }\n\n if (\n item.isFile() &&\n /\\.js(on)?|\\.xml|\\.strings(dict)?$|\\.swift$/.test(item.name)\n ) {\n return fs.unlinkSync(path.resolve(consts.TEXT_DIR, item.name));\n }\n });\n\n return \"Cleaning old output files..\\n\";\n}\n\nasync function downloadAndSave(\n source: SourceInformation,\n token?: Token,\n options?: PullOptions\n) {\n const api = createApiClient();\n const {\n validProjects,\n format: formatFromSource,\n shouldFetchComponentLibrary,\n status,\n richText,\n componentFolders: specifiedComponentFolders,\n componentRoot,\n localeByVariantApiId,\n } = source;\n\n const formats = getFormat(formatFromSource);\n\n const hasJSONFormat = formats.some((f) =>\n JSON_FORMATS.includes(f as JSONFormat)\n );\n const hasIOSFormat = formats.some((f) => IOS_FORMATS.includes(f));\n const shouldGenerateIOSBundles = hasIOSFormat && localeByVariantApiId;\n\n const shouldLogOutputFiles = !shouldGenerateIOSBundles;\n\n let msg = \"\";\n const spinner = ora(msg);\n spinner.start();\n\n const [variants, allComponentFoldersResponse] = await Promise.all([\n fetchVariants(source),\n fetchComponentFolders({}),\n ]);\n\n const allComponentFolders = Object.entries(\n allComponentFoldersResponse\n ).reduce(\n (acc, [id, name]) => acc.concat([{ id, name }]),\n [] as ComponentFolder[]\n );\n\n try {\n msg += cleanOutputFiles();\n msg += `\\nFetching the latest text from ${sourcesToText(\n validProjects,\n shouldFetchComponentLibrary\n )}\\n`;\n\n const meta = options ? options.meta : {};\n\n const rootRequest = {\n id: \"__root__\",\n name: \"Root\",\n // componentRoot can be a boolean or an object\n status:\n typeof source.componentRoot === \"object\"\n ? source.componentRoot.status\n : undefined,\n };\n\n let componentFolderRequests: ComponentFolder[] = [];\n\n // there's a lot of complex logic here, and it's tempting to want to\n // simplify it. however, it's difficult to get rid of the complexity\n // without sacrificing specificity and expressiveness.\n //\n // if folders specified..\n if (specifiedComponentFolders) {\n switch (componentRoot) {\n // .. and no root specified, you only get components in the specified folders\n case undefined:\n case false:\n componentFolderRequests.push(...specifiedComponentFolders);\n break;\n // .. and root specified, you get components in folders and the root\n default:\n componentFolderRequests.push(...specifiedComponentFolders);\n componentFolderRequests.push(rootRequest);\n break;\n }\n }\n // if no folders specified..\n else {\n switch (componentRoot) {\n // .. and no root specified, you get all components including those in folders\n case undefined:\n componentFolderRequests.push(...allComponentFolders);\n componentFolderRequests.push(rootRequest);\n break;\n // .. and root specified as false, you only get components in folders\n case false:\n componentFolderRequests.push(...allComponentFolders);\n break;\n // .. and root specified as true or config object, you only get components in the root\n default:\n componentFolderRequests.push(rootRequest);\n break;\n }\n }\n\n // this array is populated while fetching from the component library and is used when\n // generating the index.js driver file\n const componentSources: ComponentSource[] = [];\n\n async function fetchComponentLibrary(format: SupportedFormat) {\n // Always include a variant with an apiID of undefined to ensure that we\n // fetch the base text for the component library.\n const componentVariants = [{ apiID: undefined }, ...(variants || [])];\n\n const params = new URLSearchParams();\n if (options?.meta)\n Object.entries(options.meta).forEach(([k, v]) => params.append(k, v));\n if (format) params.append(\"format\", format);\n if (richText) params.append(\"includeRichText\", richText.toString());\n\n // Root-level status gets set as the default if specified\n if (status) params.append(\"status\", status);\n\n const messagePromises: Promise<string>[] = [];\n\n componentVariants.forEach(({ apiID: variantApiId }) => {\n messagePromises.push(\n ...componentFolderRequests.map(async (componentFolder) => {\n const componentFolderParams = new URLSearchParams(params);\n\n if (variantApiId)\n componentFolderParams.append(\"variant\", variantApiId);\n\n // If folder-level status is specified, overrides root-level status\n if (componentFolder.status)\n componentFolderParams.append(\"status\", componentFolder.status);\n\n const url =\n componentFolder.id === \"__root__\"\n ? \"/v1/components?root_only=true\"\n : `/v1/component-folders/${componentFolder.id}/components`;\n\n const { data } = await api.get(url, {\n params: componentFolderParams,\n });\n\n const nameExt = getFormatExtension(format);\n const nameBase = \"components\";\n\n // we need to clean the folder name by itself first, otherwise we can\n // end up with \"empty\" words and weird hyphenation.\n const nameFolder = `__${cleanFileName(componentFolder.name)}`;\n const namePostfix = `__${variantApiId || \"base\"}`;\n\n const fileName = cleanFileName(\n `${nameBase}${nameFolder}${namePostfix}${nameExt}`\n );\n const filePath = path.join(consts.TEXT_DIR, fileName);\n\n let dataString = data;\n if (nameExt === \".json\") {\n dataString = JSON.stringify(data, null, 2);\n }\n\n const dataIsValid = getFormatDataIsValid[format];\n if (!dataIsValid(dataString)) {\n return \"\";\n }\n\n await writeFile(filePath, dataString);\n\n componentSources.push({\n type: \"components\",\n id: \"ditto_component_library\",\n name: \"ditto_component_library\",\n fileName,\n variant: variantApiId || \"base\",\n });\n\n return getSavedMessage(fileName);\n })\n );\n });\n\n const messages = await Promise.all(messagePromises);\n if (shouldLogOutputFiles) {\n msg += messages.join(\"\");\n }\n }\n\n if (shouldFetchComponentLibrary) {\n for (const format of formats) {\n await fetchComponentLibrary(format);\n }\n }\n\n async function fetchProjects(format: SupportedFormat) {\n let result = \"\";\n if (variants) {\n result = await downloadAndSaveVariants({\n variants,\n projects: validProjects,\n format,\n status,\n richText,\n token,\n });\n } else {\n result = await downloadAndSaveBase({\n projects: validProjects,\n format,\n status,\n richText,\n token,\n options: {\n meta,\n },\n });\n }\n\n if (shouldLogOutputFiles) {\n msg += result;\n }\n }\n\n if (validProjects.length) {\n for (const format of formats) {\n await fetchProjects(format);\n }\n }\n\n const sources: Source[] = [...validProjects, ...componentSources];\n\n if (hasJSONFormat) msg += generateJsDriver(sources, getJsonFormat(formats));\n\n if (shouldGenerateIOSBundles) {\n msg += \"iOS locale information detected, generating bundles..\\n\\n\";\n msg += await generateIOSBundles(localeByVariantApiId);\n msg += await generateSwiftDriver(source);\n }\n\n msg += `\\n\\n${output.success(\"Done\")}!`;\n\n spinner.stop();\n return console.log(msg);\n } catch (e: any) {\n console.error(e);\n\n spinner.stop();\n let error = e.message;\n if (e.response && e.response.status === 404) {\n await askForAnotherToken();\n pull();\n return;\n }\n if (e.response && e.response.status === 401) {\n error = \"You don't have access to the selected projects\";\n msg = `${output.errorText(error)}.\\nChoose others using the ${output.info(\n \"project\"\n )} command, or update your API key.`;\n return console.log(msg);\n }\n if (e.response && e.response.status === 403) {\n error =\n \"One or more of the requested projects don't have Developer Mode enabled\";\n msg = `${output.errorText(\n error\n )}.\\nPlease choose different projects using the ${output.info(\n \"project\"\n )} command, or turn on Developer Mode for all selected projects. Learn more here: ${output.subtle(\n \"https://www.dittowords.com/docs/ditto-developer-mode\"\n )}.`;\n return console.log(msg);\n }\n if (e.response && e.response.status === 400) {\n error = \"projects not found\";\n }\n msg = `We hit an error fetching text from the projects: ${output.errorText(\n error\n )}.\\nChoose others using the ${output.info(\"project\")} command.`;\n return console.log(msg);\n }\n}\n\nexport interface PullOptions {\n meta?: Record<string, string>;\n}\n\nexport const pull = async (options?: PullOptions) => {\n const meta = options ? options.meta : {};\n const token = config.getToken(consts.CONFIG_FILE, consts.API_HOST);\n const sourceInformation = config.parseSourceInformation();\n\n try {\n return await downloadAndSave(sourceInformation, token, { meta });\n } catch (e) {\n const eventId = Sentry.captureException(e);\n const eventStr = `\\n\\nError ID: ${output.info(eventId)}`;\n if (e instanceof AxiosError) {\n return quit(\n output.errorText(\n \"Something went wrong connecting to Ditto servers. Please contact support or try again later.\"\n ) + eventStr\n );\n }\n\n return quit(\n output.errorText(\n \"Something went wrong. Please contact support or try again later.\"\n ) + eventStr\n );\n }\n};\n\nexport default {\n pull,\n _testing: {\n cleanOutputFiles,\n downloadAndSaveVariant,\n downloadAndSaveVariants,\n downloadAndSaveBase,\n },\n};\n"],"names":["path","fs","config","consts","output","ora","sourcesToText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAEjB,iBAAgB;AAChB,aAAwB;AAExB,iBAAgC;AAChC,oBAAmB;AACnB,oBAAmB;AACnB,oBAAmB;AACnB,mBAAoC;AACpC,2BAA0B;AAC1B,8BAAiC;AACjC,2BAA8B;AAU9B,2BAA8B;AAC9B,kBAAqB;AACrB,mBAA2B;AAC3B,mCAAsC;AACtC,iCAAoC;AACpC,gCAAmC;AAenC,MAAM,wBAAwB,CAAC,QAC7B,OAAO,UAAU,KAAK,GAAG,IAAI,KAAK;AAE7B,MAAM,YAAY,CAACA,OAAc,SACtC,IAAI,QAAQ,CAAC,MAAM,UAAAC,QAAG,UAAUD,OAAM,sBAAsB,IAAI,GAAG,CAAC,CAAC;AAEvE,MAAM,oBAAuC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,MAAM,cAAiC,CAAC,eAAe,iBAAiB;AACxE,MAAM,eAA6B,CAAC,QAAQ,cAAc,KAAK;AAE/D,MAAM,gBAAgB,CAAC,YAAkC;AAGvD,QAAM,cAAc,QAAQ;AAAA,IAAO,CAAC,MAClC,aAAa,SAAS,CAAe;AAAA,EACvC;AAEA,SAAO,YAAY,YAAY,SAAS,CAAC,KAAK;AA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AO,QAAQ,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA;AAMO,MAAM,OAAO,CAAO,YAA0B;AACnD,QAAM,OAAO,UAAU,QAAQ,OAAO,CAAC;AACvC,QAAM,QAAQ,cAAAF,QAAO,SAAS,cAAAC,QAAO,aAAa,cAAAA,QAAO,QAAQ;AACjE,QAAM,oBAAoB,cAAAD,QAAO,uBAAuB;AAExD,MAAI;AACF,WAAO,MAAM,gBAAgB,mBAAmB,OAAO,EAAE,KAAK,CAAC;AAAA,EACjE,SAAS,GAAG;AACV,UAAM,UAAU,OAAO,iBAAiB,CAAC;AACzC,UAAM,WAAW;AAAA;AAAA,YAAiB,cAAAE,QAAO,KAAK,OAAO,CAAC;AACtD,QAAI,aAAa,yBAAY;AAC3B,iBAAO;AAAA,QACL,cAAAA,QAAO;AAAA,UACL;AAAA,QACF,IAAI;AAAA,MACN;AAAA,IACF;AAEA,eAAO;AAAA,MACL,cAAAA,QAAO;AAAA,QACL;AAAA,MACF,IAAI;AAAA,IACN;AAAA,EACF;AACF;AAEA,IAAO,eAAQ;AAAA,EACb;AAAA,EACA,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","debug_id":"130de1f8-09ed-546e-b0a2-30a311da1206"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2c3d33c0-3502-5a27-a98a-460ccebb5e74")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -24,7 +24,12 @@ __export(cleanFileName_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(cleanFileName_exports);
|
|
26
26
|
function cleanFileName(fileName) {
|
|
27
|
-
|
|
27
|
+
let parts = fileName.split(/\s{1,}/g);
|
|
28
|
+
parts = parts.map(
|
|
29
|
+
(part) => part.replace(/[^a-zA-Z0-9-_.]/g, "").toLowerCase()
|
|
30
|
+
);
|
|
31
|
+
parts = parts.filter((part) => part !== "");
|
|
32
|
+
return parts.join("-");
|
|
28
33
|
}
|
|
29
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
35
|
0 && (module.exports = {
|
|
@@ -32,4 +37,4 @@ function cleanFileName(fileName) {
|
|
|
32
37
|
});
|
|
33
38
|
//# sourceMappingURL=cleanFileName.js.map
|
|
34
39
|
|
|
35
|
-
//# debugId=
|
|
40
|
+
//# debugId=2c3d33c0-3502-5a27-a98a-460ccebb5e74
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/cleanFileName.ts"],"sourcesContent":["export function cleanFileName(fileName: string): string {\n
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/cleanFileName.ts"],"sourcesContent":["export function cleanFileName(fileName: string): string {\n let parts = fileName.split(/\\s{1,}/g);\n parts = parts.map((part) =>\n part.replace(/[^a-zA-Z0-9-_.]/g, \"\").toLowerCase()\n );\n parts = parts.filter((part) => part !== \"\");\n return parts.join(\"-\");\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,cAAc,UAA0B;AACtD,MAAI,QAAQ,SAAS,MAAM,SAAS;AACpC,UAAQ,MAAM;AAAA,IAAI,CAAC,SACjB,KAAK,QAAQ,oBAAoB,EAAE,EAAE,YAAY;AAAA,EACnD;AACA,UAAQ,MAAM,OAAO,CAAC,SAAS,SAAS,EAAE;AAC1C,SAAO,MAAM,KAAK,GAAG;AACvB","debug_id":"2c3d33c0-3502-5a27-a98a-460ccebb5e74"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6d536038-ec46-5c46-a8f3-18d15a529002")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var import_cleanFileName = require("./cleanFileName");
|
|
5
|
+
describe("cleanFileName tests", () => {
|
|
6
|
+
it("correctly cleans emojis", () => {
|
|
7
|
+
const folderName = "\u{1F44D}Good Folder";
|
|
8
|
+
expect((0, import_cleanFileName.cleanFileName)(folderName)).toEqual("good-folder");
|
|
9
|
+
const fileName = "\u{1F44D} Good Folder";
|
|
10
|
+
expect((0, import_cleanFileName.cleanFileName)(fileName)).toEqual("good-folder");
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=cleanFileName.test.js.map
|
|
14
|
+
|
|
15
|
+
//# debugId=6d536038-ec46-5c46-a8f3-18d15a529002
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/cleanFileName.test.ts"],"sourcesContent":["import { cleanFileName } from \"./cleanFileName\";\n\ndescribe(\"cleanFileName tests\", () => {\n it(\"correctly cleans emojis\", () => {\n const folderName = \"👍Good Folder\";\n expect(cleanFileName(folderName)).toEqual(\"good-folder\");\n\n const fileName = \"👍 Good Folder\";\n expect(cleanFileName(fileName)).toEqual(\"good-folder\");\n });\n});\n"],"names":[],"mappings":";;;AAAA,2BAA8B;AAE9B,SAAS,uBAAuB,MAAM;AACpC,KAAG,2BAA2B,MAAM;AAClC,UAAM,aAAa;AACnB,eAAO,oCAAc,UAAU,CAAC,EAAE,QAAQ,aAAa;AAEvD,UAAM,WAAW;AACjB,eAAO,oCAAc,QAAQ,CAAC,EAAE,QAAQ,aAAa;AAAA,EACvD,CAAC;AACH,CAAC","debug_id":"6d536038-ec46-5c46-a8f3-18d15a529002"}
|
package/lib/ditto.ts
CHANGED
|
@@ -32,6 +32,14 @@ function getVersion(): string {
|
|
|
32
32
|
|
|
33
33
|
const VERSION = getVersion();
|
|
34
34
|
|
|
35
|
+
const CONFIG_FILE_RELIANT_COMMANDS = [
|
|
36
|
+
"pull",
|
|
37
|
+
"none",
|
|
38
|
+
"project",
|
|
39
|
+
"project add",
|
|
40
|
+
"project remove",
|
|
41
|
+
];
|
|
42
|
+
|
|
35
43
|
type Command =
|
|
36
44
|
| "pull"
|
|
37
45
|
| "project"
|
|
@@ -152,7 +160,7 @@ const setupCommands = () => {
|
|
|
152
160
|
} else {
|
|
153
161
|
cmd.option(flags, description);
|
|
154
162
|
}
|
|
155
|
-
}
|
|
163
|
+
},
|
|
156
164
|
);
|
|
157
165
|
}
|
|
158
166
|
|
|
@@ -177,16 +185,18 @@ const setupCommands = () => {
|
|
|
177
185
|
const setupOptions = () => {
|
|
178
186
|
program.option(
|
|
179
187
|
"-m, --meta <data...>",
|
|
180
|
-
"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual"
|
|
188
|
+
"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual",
|
|
181
189
|
);
|
|
182
190
|
program.version(VERSION, "-v, --version", "Output the current version");
|
|
183
191
|
};
|
|
184
192
|
|
|
185
193
|
const executeCommand = async (
|
|
186
194
|
command: Command | "none",
|
|
187
|
-
options: any
|
|
195
|
+
options: any,
|
|
188
196
|
): Promise<void> => {
|
|
189
|
-
const needsInitialization =
|
|
197
|
+
const needsInitialization =
|
|
198
|
+
CONFIG_FILE_RELIANT_COMMANDS.includes(command) && needsTokenOrSource();
|
|
199
|
+
|
|
190
200
|
if (needsInitialization) {
|
|
191
201
|
try {
|
|
192
202
|
await init();
|
|
@@ -27,7 +27,9 @@ async function generateSuggestions(flags: {
|
|
|
27
27
|
componentFolder?: string;
|
|
28
28
|
}) {
|
|
29
29
|
const components = await fetchComponents({
|
|
30
|
-
|
|
30
|
+
...(flags.componentFolder
|
|
31
|
+
? { componentFolder: flags.componentFolder }
|
|
32
|
+
: {}),
|
|
31
33
|
});
|
|
32
34
|
const directory = flags.directory || ".";
|
|
33
35
|
|
|
@@ -66,7 +68,7 @@ async function findComponentsInJSXFiles(params: {
|
|
|
66
68
|
traverse(ast, {
|
|
67
69
|
JSXText(path) {
|
|
68
70
|
for (const [compApiId, component] of Object.entries(
|
|
69
|
-
params.components
|
|
71
|
+
params.components,
|
|
70
72
|
)) {
|
|
71
73
|
// If we haven't seen this component before, add it to the result
|
|
72
74
|
if (!result[compApiId]) {
|
|
@@ -77,11 +79,16 @@ async function findComponentsInJSXFiles(params: {
|
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
// Skip white space lines
|
|
84
|
+
!/^\s*$/.test(path.node.value) &&
|
|
85
|
+
!/^\s*$/.test(component.text) &&
|
|
86
|
+
path.node.value.includes(component.text)
|
|
87
|
+
) {
|
|
81
88
|
// Escape all special characters from the text so we can use it in a regex
|
|
82
89
|
const escapedText = component.text.replace(
|
|
83
90
|
/[.*+?^${}()|[\]\\]/g,
|
|
84
|
-
"\\$&"
|
|
91
|
+
"\\$&",
|
|
85
92
|
);
|
|
86
93
|
const regex = new RegExp(escapedText, "g");
|
|
87
94
|
let match;
|
|
@@ -103,7 +110,7 @@ async function findComponentsInJSXFiles(params: {
|
|
|
103
110
|
line,
|
|
104
111
|
match.index,
|
|
105
112
|
component.text,
|
|
106
|
-
`${component.text}
|
|
113
|
+
`${component.text}`,
|
|
107
114
|
);
|
|
108
115
|
|
|
109
116
|
// Initialize the occurrences array if it doesn't exist
|
|
@@ -125,7 +132,7 @@ async function findComponentsInJSXFiles(params: {
|
|
|
125
132
|
}
|
|
126
133
|
},
|
|
127
134
|
});
|
|
128
|
-
})
|
|
135
|
+
}),
|
|
129
136
|
);
|
|
130
137
|
}
|
|
131
138
|
|
|
@@ -138,7 +145,7 @@ function replaceAt(
|
|
|
138
145
|
str: string,
|
|
139
146
|
index: number,
|
|
140
147
|
searchString: string,
|
|
141
|
-
replacement: string
|
|
148
|
+
replacement: string,
|
|
142
149
|
) {
|
|
143
150
|
return (
|
|
144
151
|
str.substring(0, index) +
|
package/lib/pull.ts
CHANGED
|
@@ -436,7 +436,10 @@ async function downloadAndSave(
|
|
|
436
436
|
|
|
437
437
|
const nameExt = getFormatExtension(format);
|
|
438
438
|
const nameBase = "components";
|
|
439
|
-
|
|
439
|
+
|
|
440
|
+
// we need to clean the folder name by itself first, otherwise we can
|
|
441
|
+
// end up with "empty" words and weird hyphenation.
|
|
442
|
+
const nameFolder = `__${cleanFileName(componentFolder.name)}`;
|
|
440
443
|
const namePostfix = `__${variantApiId || "base"}`;
|
|
441
444
|
|
|
442
445
|
const fileName = cleanFileName(
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cleanFileName } from "./cleanFileName";
|
|
2
|
+
|
|
3
|
+
describe("cleanFileName tests", () => {
|
|
4
|
+
it("correctly cleans emojis", () => {
|
|
5
|
+
const folderName = "👍Good Folder";
|
|
6
|
+
expect(cleanFileName(folderName)).toEqual("good-folder");
|
|
7
|
+
|
|
8
|
+
const fileName = "👍 Good Folder";
|
|
9
|
+
expect(cleanFileName(fileName)).toEqual("good-folder");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export function cleanFileName(fileName: string): string {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.replace(/[^a-zA-Z0-9-_.]/g, "")
|
|
5
|
-
|
|
2
|
+
let parts = fileName.split(/\s{1,}/g);
|
|
3
|
+
parts = parts.map((part) =>
|
|
4
|
+
part.replace(/[^a-zA-Z0-9-_.]/g, "").toLowerCase()
|
|
5
|
+
);
|
|
6
|
+
parts = parts.filter((part) => part !== "");
|
|
7
|
+
return parts.join("-");
|
|
6
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dittowords/cli",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
4
4
|
"description": "Command Line Interface for Ditto (dittowords.com).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "bin/index.js",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@sentry/node": "^7.64.0",
|
|
62
62
|
"@types/babel-traverse": "^6.25.7",
|
|
63
63
|
"@types/fs-extra": "^11.0.1",
|
|
64
|
-
"axios": "^
|
|
64
|
+
"axios": "^1.6.0",
|
|
65
65
|
"boxen": "^5.1.2",
|
|
66
66
|
"chalk": "^4.1.0",
|
|
67
67
|
"commander": "^6.1.0",
|