@dittowords/cli 4.0.0 → 4.1.0-alpha

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.
Files changed (43) hide show
  1. package/README.md +29 -364
  2. package/bin/config.js +5 -3
  3. package/bin/config.js.map +1 -1
  4. package/bin/generate-swift-struct.js +6 -0
  5. package/bin/generate-swift-struct.js.map +1 -0
  6. package/bin/http/fetchComponentFolders.js +3 -3
  7. package/bin/http/fetchComponentFolders.js.map +1 -1
  8. package/bin/http/fetchComponents.js +13 -5
  9. package/bin/http/fetchComponents.js.map +1 -1
  10. package/bin/http/fetchVariants.js +3 -3
  11. package/bin/http/fetchVariants.js.map +1 -1
  12. package/bin/init/project.js +3 -3
  13. package/bin/init/project.js.map +1 -1
  14. package/bin/pull.js +82 -38
  15. package/bin/pull.js.map +1 -1
  16. package/bin/pull.test.js +26 -24
  17. package/bin/pull.test.js.map +1 -1
  18. package/bin/types.js +2 -2
  19. package/bin/types.js.map +1 -1
  20. package/bin/utils/determineModuleType.js +80 -0
  21. package/bin/utils/determineModuleType.js.map +1 -0
  22. package/bin/utils/generateIOSBundles.js +147 -0
  23. package/bin/utils/generateIOSBundles.js.map +1 -0
  24. package/bin/utils/generateJsDriver.js +117 -58
  25. package/bin/utils/generateJsDriver.js.map +1 -1
  26. package/bin/utils/generateJsDriverTypeFile.js +105 -0
  27. package/bin/utils/generateJsDriverTypeFile.js.map +1 -0
  28. package/bin/utils/generateSwiftDriver.js +93 -0
  29. package/bin/utils/generateSwiftDriver.js.map +1 -0
  30. package/lib/config.ts +4 -0
  31. package/lib/http/fetchComponentFolders.ts +1 -1
  32. package/lib/http/fetchComponents.ts +14 -9
  33. package/lib/http/fetchVariants.ts +1 -1
  34. package/lib/init/project.ts +1 -1
  35. package/lib/pull.test.ts +24 -22
  36. package/lib/pull.ts +106 -55
  37. package/lib/types.ts +4 -0
  38. package/lib/utils/determineModuleType.ts +57 -0
  39. package/lib/utils/generateIOSBundles.ts +122 -0
  40. package/lib/utils/generateJsDriver.ts +156 -51
  41. package/lib/utils/generateJsDriverTypeFile.ts +75 -0
  42. package/lib/utils/generateSwiftDriver.ts +48 -0
  43. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../lib/utils/generateJsDriver.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport consts from \"../consts\";\nimport output from \"../output\";\nimport { Source } from \"../types\";\nimport { cleanFileName } from \"./cleanFileName\";\n\n// compatability with legacy method of specifying project ids\n// that is still used by the default format\nconst stringifySourceId = (projectId: string) =>\n projectId === \"ditto_component_library\" ? projectId : `project_${projectId}`;\n\n/**\n * Generates an index.js file that can be consumed\n * by an SDK - this is a big DX improvement because\n * it provides a single entry point to get all data\n * (including variants) instead of having to import\n * each generated file individually.\n *\n * The generated file will have a unified format\n * independent of the CLI configuration used to fetch\n * data from Ditto.\n */\n\n// TODO: support ESM\nexport function generateJsDriver(sources: Source[]) {\n const sourceIdsByName: Record<string, string> = sources.reduce(\n (agg, source) => {\n if (source.fileName) {\n return { ...agg, [cleanFileName(source.fileName)]: source.id };\n }\n\n return agg;\n },\n {}\n );\n\n const projectFileNames = fs\n .readdirSync(consts.TEXT_DIR)\n .filter(\n (fileName) => /\\.json$/.test(fileName) && !/^components__/.test(fileName)\n );\n\n type DriverFile = Record<string, Record<string, string | object>>;\n const data: DriverFile = projectFileNames.reduce(\n (obj: Record<string, Record<string, string>>, fileName) => {\n const [sourceId, rest] = fileName.split(\"__\");\n const [variantApiId] = rest.split(\".\");\n\n const projectId = sourceIdsByName[sourceId];\n const projectIdStr = stringifySourceId(projectId);\n\n if (!obj[projectIdStr]) {\n obj[projectIdStr] = {};\n }\n\n obj[projectIdStr][variantApiId] = `require('./${fileName}')`;\n return obj;\n },\n {}\n );\n\n // Create arrays of stringified \"...require()\" statements,\n // each of which corresponds to one of the component files\n // (which are created on a per-component-folder basis)\n const componentData: Record<string, string[]> = {};\n sources\n .filter((s) => s.type === \"components\")\n .forEach((componentSource) => {\n if (componentSource.type !== \"components\") return;\n componentData[componentSource.variant] ??= [];\n componentData[componentSource.variant].push(\n `...require('./${componentSource.fileName}')`\n );\n });\n // Convert each array of stringified \"...require()\" statements\n // into a unified string, and set it on the final data object\n // that will be written to the driver file\n Object.keys(componentData).forEach((key) => {\n data.ditto_component_library ??= {};\n\n let str = \"{\";\n componentData[key].forEach((k, i) => {\n str += k;\n if (i < componentData[key].length - 1) str += \", \";\n });\n str += \"}\";\n data.ditto_component_library[key] = str;\n });\n\n let dataString = `module.exports = ${JSON.stringify(data, null, 2)}`\n // remove quotes around require statements\n .replace(/\"require\\((.*)\\)\"/g, \"require($1)\")\n // remove quotes around opening & closing curlies\n .replace(/\"\\{/g, \"{\")\n .replace(/\\}\"/g, \"}\");\n\n const filePath = path.resolve(consts.TEXT_DIR, \"index.js\");\n fs.writeFileSync(filePath, dataString, { encoding: \"utf8\" });\n\n return `Generated .js SDK driver at ${output.info(filePath)}`;\n}\n"],"names":["fs","consts","path","output"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AACjB,oBAAmB;AACnB,oBAAmB;AAEnB,2BAA8B;AAI9B,MAAM,oBAAoB,CAAC,cACzB,cAAc,4BAA4B,YAAY,WAAW,SAAS;AAerE,SAAS,iBAAiB,SAAmB;AAClD,QAAM,kBAA0C,QAAQ;AAAA,IACtD,CAAC,KAAK,WAAW;AACf,UAAI,OAAO,UAAU;AACnB,eAAO,iCAAK,MAAL,EAAU,KAAC,oCAAc,OAAO,QAAQ,CAAC,GAAG,OAAO,GAAG;AAAA,MAC/D;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,mBAAmB,UAAAA,QACtB,YAAY,cAAAC,QAAO,QAAQ,EAC3B;AAAA,IACC,CAAC,aAAa,UAAU,KAAK,QAAQ,KAAK,C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AAAD,QAAO,UAAU,UAAU;AACzD,YAAAD,QAAG,cAAc,UAAU,YAAY,EAAE,UAAU,OAAO,CAAC;AAE3D,SAAO,+BAA+B,cAAAG,QAAO,KAAK,QAAQ,CAAC;AAC7D","debug_id":"abf6148b-b36f-5809-b765-ac588ff7207f"}
1
+ {"version":3,"sources":["../../lib/utils/generateJsDriver.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport consts from \"../consts\";\nimport output from \"../output\";\nimport { Source } from \"../types\";\nimport { cleanFileName } from \"./cleanFileName\";\nimport { ModuleType, determineModuleType } from \"./determineModuleType\";\nimport { generateJsDriverTypeFile } from \"./generateJsDriverTypeFile\";\nimport { JSONFormat } from \"../pull\";\n\n// compatability with legacy method of specifying project ids\n// that is still used by the default format\nconst stringifySourceId = (projectId: string) =>\n projectId === \"ditto_component_library\" ? projectId : `project_${projectId}`;\n\n/**\n * Generates an index.js file that can be consumed\n * by an SDK - this is a big DX improvement because\n * it provides a single entry point to get all data\n * (including variants) instead of having to import\n * each generated file individually.\n *\n * The generated file will have a unified format\n * independent of the CLI configuration used to fetch\n * data from Ditto.\n *\n */\ntype DriverFile = Record<string, Record<string, string | object>>;\nexport function generateJsDriver(sources: Source[], format: JSONFormat) {\n const moduleType = determineModuleType();\n\n const fullyQualifiedSources = getFullyQualifiedJSONSources(sources);\n\n const variableNameGenerator = createVariableNameGenerator();\n const importStatements: string[] = [];\n\n const data: DriverFile = {};\n const dataComponents: Record<string, string[]> = {};\n\n fullyQualifiedSources.forEach((source) => {\n let variableName: string;\n if (source.type === \"components\") {\n variableName = variableNameGenerator.generate(\n source.fileName.split(\".\")[0]\n );\n } else {\n const fileNameWithoutExtension = source.fileName.split(\".\")[0];\n variableName = variableNameGenerator.generate(\n fileNameWithoutExtension.split(\"__\")[0]\n );\n }\n\n importStatements.push(\n getImportStatement(source.fileName, variableName, moduleType)\n );\n\n if (source.type === \"project\") {\n const { variantApiId } = source;\n const projectId = stringifySourceId(source.projectId);\n data[projectId] ??= {};\n data[projectId][variantApiId] = `{...${variableName}}`;\n } else {\n dataComponents[source.variantApiId] ??= [];\n dataComponents[source.variantApiId].push(`...${variableName}`);\n }\n });\n\n // Convert each array of stringified \"...require()\" statements\n // into a unified string, and set it on the final data object\n // that will be written to the driver file\n Object.keys(dataComponents).forEach((key) => {\n data.ditto_component_library ??= {};\n\n let str = \"{\";\n dataComponents[key].forEach((k: any, i: any) => {\n str += k;\n if (i < dataComponents[key].length - 1) str += \", \";\n });\n str += \"}\";\n data.ditto_component_library[key] = str;\n });\n\n let dataString = \"\";\n dataString += importStatements.join(\"\\n\") + \"\\n\\n\";\n dataString += `${getExportPrefix(moduleType)}`;\n dataString += `${JSON.stringify(data, null, 2)}`\n // remove quotes around opening & closing curlies\n .replace(/\"\\{/g, \"{\")\n .replace(/\\}\"/g, \"}\");\n\n const filePath = path.resolve(consts.TEXT_DIR, \"index.js\");\n fs.writeFileSync(filePath, dataString, { encoding: \"utf8\" });\n\n generateJsDriverTypeFile({\n format,\n moduleType,\n });\n\n return `Generated .js SDK driver at ${output.info(filePath)}`;\n}\n\ntype IFullyQualifiedJSONSource =\n | {\n type: \"components\";\n variantApiId: string;\n folderApiId: string;\n fileName: string;\n }\n | {\n type: \"project\";\n projectId: string;\n projectName: string;\n variantApiId: string;\n fileName: string;\n };\n\n/**\n * Upstream source data is a mess - this function is an attempt at cleaning it up\n * so that it can be used in a more straightforward way to generate the driver file.\n */\nfunction getFullyQualifiedJSONSources(\n sources: Source[]\n): IFullyQualifiedJSONSource[] {\n const projectIdsByCleanedFileName = new Map<string, string>();\n sources.forEach((source) => {\n if (!source.fileName || source.type === \"components\") {\n return;\n }\n projectIdsByCleanedFileName.set(cleanFileName(source.fileName), source.id);\n });\n\n const fileNames = fs.readdirSync(consts.TEXT_DIR);\n return fileNames\n .filter((f) => path.extname(f) === \".json\")\n .map((fileName) => {\n const parts = fileName.split(\"__\");\n\n if (parts.length === 3) {\n const [, folderApiId, rest] = parts;\n const [variantApiId] = rest.split(\".\");\n return {\n type: \"components\",\n variantApiId,\n folderApiId,\n fileName,\n };\n }\n\n if (parts.length === 2) {\n const [projectName, rest] = parts;\n const [variantApiId] = rest.split(\".\");\n const key = cleanFileName(fileName.split(\"__\")[0]);\n const projectId = projectIdsByCleanedFileName.get(key) || \"\";\n return {\n type: \"project\",\n projectId,\n projectName,\n variantApiId,\n fileName,\n };\n }\n\n throw new Error(\"Invalid JSON file generated: \" + fileName);\n });\n}\n\nfunction createVariableNameGenerator() {\n const variableNames = new Set<string>();\n\n return {\n generate: (str: string) => {\n const baseName = str.replace(/(\\W|-)/g, \"_\");\n let name = baseName;\n let i = 1;\n while (variableNames.has(name)) {\n name = `${baseName}${i}`;\n i++;\n }\n variableNames.add(name);\n return name;\n },\n };\n}\n\nfunction getExportPrefix(moduleType: ModuleType) {\n if (moduleType === \"commonjs\") {\n return \"module.exports = \";\n }\n if (moduleType === \"module\") {\n return \"export default \";\n }\n throw new Error(\"Unknown module type: \" + moduleType);\n}\n\nfunction getImportStatement(\n fileName: string,\n variableName: string,\n moduleType: ModuleType\n) {\n if (moduleType === \"commonjs\") {\n return `const ${variableName} = require('./${fileName}');`;\n }\n if (moduleType === \"module\") {\n return `import ${variableName} from './${fileName}';`;\n }\n throw new Error(\"Unknown module type: \" + moduleType);\n}\n"],"names":["path","consts","fs","output"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AACjB,oBAAmB;AACnB,oBAAmB;AAEnB,2BAA8B;AAC9B,iCAAgD;AAChD,sCAAyC;AAKzC,MAAM,oBAAoB,CAAC,cACzB,cAAc,4BAA4B,YAAY,WAAW,SAAS;AAerE,SAAS,iBAAiB,SAAmB,QAAoB;AACtE,QAAM,iBAAa,gDAAoB;AAEvC,QAAM,wBAAwB,6BAA6B,OAAO;AAElE,QAAM,wBAAwB,4BAA4B;AAC1D,QAAM,mBAA6B,CAAC;AA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AA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,kCAAkC,QAAQ;AAAA,EAC5D,CAAC;AACL;AAEA,SAAS,8BAA8B;AACrC,QAAM,gBAAgB,oBAAI,IAAY;AAEtC,SAAO;AAAA,IACL,UAAU,CAAC,QAAgB;AACzB,YAAM,WAAW,IAAI,QAAQ,WAAW,GAAG;AAC3C,UAAI,OAAO;AACX,UAAI,IAAI;AACR,aAAO,cAAc,IAAI,IAAI,GAAG;AAC9B,eAAO,GAAG,QAAQ,GAAG,CAAC;AACtB;AAAA,MACF;AACA,oBAAc,IAAI,IAAI;AACtB,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,SAAS,gBAAgB,YAAwB;AAC/C,MAAI,eAAe,YAAY;AAC7B,WAAO;AAAA,EACT;AACA,MAAI,eAAe,UAAU;AAC3B,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,0BAA0B,UAAU;AACtD;AAEA,SAAS,mBACP,UACA,cACA,YACA;AACA,MAAI,eAAe,YAAY;AAC7B,WAAO,SAAS,YAAY,iBAAiB,QAAQ;AAAA,EACvD;AACA,MAAI,eAAe,UAAU;AAC3B,WAAO,UAAU,YAAY,YAAY,QAAQ;AAAA,EACnD;AACA,QAAM,IAAI,MAAM,0BAA0B,UAAU;AACtD","debug_id":"399aa2f0-cd6c-5782-972b-6a17282f684b"}
@@ -0,0 +1,105 @@
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]="4f3c1f85-b18c-51c0-9a4e-6fa602477a2f")}catch(e){}}();
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var generateJsDriverTypeFile_exports = {};
32
+ __export(generateJsDriverTypeFile_exports, {
33
+ generateJsDriverTypeFile: () => generateJsDriverTypeFile
34
+ });
35
+ module.exports = __toCommonJS(generateJsDriverTypeFile_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_consts = __toESM(require("../consts"));
39
+ function getFormatString(format) {
40
+ switch (format) {
41
+ case "flat":
42
+ return "IJSONFlat";
43
+ case "nested":
44
+ return "IJSONNested";
45
+ case "structured":
46
+ return "IJSONStructured";
47
+ case "icu":
48
+ return "IJSONICU";
49
+ default:
50
+ return "_JSON";
51
+ }
52
+ }
53
+ function getExportString(exportedValue, moduleType) {
54
+ if (moduleType === "commonjs") {
55
+ return `export = ${exportedValue};`;
56
+ }
57
+ return `export default ${exportedValue};`;
58
+ }
59
+ function getTypesString(options) {
60
+ return `
61
+ interface IJSONFlat {
62
+ [key: string]: string;
63
+ }
64
+
65
+ interface IJSONStructured {
66
+ [key: string]: {
67
+ text: string;
68
+ status?: string;
69
+ notes?: string;
70
+ [property: string]: any;
71
+ };
72
+ }
73
+
74
+ interface IJSONNested {
75
+ [key: string]: string | IJSONNested;
76
+ }
77
+
78
+ type _JSON = IJSONFlat | IJSONStructured | IJSONNested;
79
+
80
+ interface IDriverFile {
81
+ [sourceKey: string]: {
82
+ [variantKey: string]: ${getFormatString(options.format)};
83
+ };
84
+ }
85
+
86
+ declare const driver: IDriverFile;
87
+
88
+ ${getExportString("driver", options.moduleType)}
89
+ `.trim();
90
+ }
91
+ function generateJsDriverTypeFile(options) {
92
+ const typeFileString = getTypesString(options);
93
+ import_fs.default.writeFileSync(
94
+ import_path.default.resolve(import_consts.default.TEXT_DIR, "index.d.ts"),
95
+ typeFileString + "\n",
96
+ "utf8"
97
+ );
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ generateJsDriverTypeFile
102
+ });
103
+ //# sourceMappingURL=generateJsDriverTypeFile.js.map
104
+
105
+ //# debugId=4f3c1f85-b18c-51c0-9a4e-6fa602477a2f
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../lib/utils/generateJsDriverTypeFile.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { ModuleType } from \"./determineModuleType\";\nimport { JSONFormat } from \"../pull\";\nimport consts from \"../consts\";\n\nfunction getFormatString(format: JSONFormat) {\n switch (format) {\n case \"flat\":\n return \"IJSONFlat\";\n case \"nested\":\n return \"IJSONNested\";\n case \"structured\":\n return \"IJSONStructured\";\n case \"icu\":\n return \"IJSONICU\";\n default:\n return \"_JSON\";\n }\n}\n\nfunction getExportString(exportedValue: string, moduleType: ModuleType) {\n if (moduleType === \"commonjs\") {\n return `export = ${exportedValue};`;\n }\n\n return `export default ${exportedValue};`;\n}\n\nfunction getTypesString(options: IOptions) {\n return `\ninterface IJSONFlat {\n [key: string]: string;\n}\n\ninterface IJSONStructured {\n [key: string]: {\n text: string;\n status?: string;\n notes?: string;\n [property: string]: any;\n };\n}\n\ninterface IJSONNested {\n [key: string]: string | IJSONNested;\n}\n\ntype _JSON = IJSONFlat | IJSONStructured | IJSONNested;\n\ninterface IDriverFile {\n [sourceKey: string]: {\n [variantKey: string]: ${getFormatString(options.format)};\n };\n}\n\ndeclare const driver: IDriverFile;\n\n${getExportString(\"driver\", options.moduleType)}\n`.trim();\n}\n\ninterface IOptions {\n format: JSONFormat;\n moduleType: ModuleType;\n}\n\nexport function generateJsDriverTypeFile(options: IOptions) {\n const typeFileString = getTypesString(options);\n fs.writeFileSync(\n path.resolve(consts.TEXT_DIR, \"index.d.ts\"),\n typeFileString + \"\\n\",\n \"utf8\"\n );\n}\n"],"names":["fs","path","consts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAGjB,oBAAmB;AAEnB,SAAS,gBAAgB,QAAoB;AAC3C,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,gBAAgB,eAAuB,YAAwB;AACtE,MAAI,eAAe,YAAY;AAC7B,WAAO,YAAY,aAAa;AAAA,EAClC;AAEA,SAAO,kBAAkB,aAAa;AACxC;AAEA,SAAS,eAAe,SAAmB;AACzC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAsBmB,gBAAgB,QAAQ,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzD,gBAAgB,UAAU,QAAQ,UAAU,CAAC;AAAA,EAC7C,KAAK;AACP;AAOO,SAAS,yBAAyB,SAAmB;AAC1D,QAAM,iBAAiB,eAAe,OAAO;AAC7C,YAAAA,QAAG;AAAA,IACD,YAAAC,QAAK,QAAQ,cAAAC,QAAO,UAAU,YAAY;AAAA,IAC1C,iBAAiB;AAAA,IACjB;AAAA,EACF;AACF","debug_id":"4f3c1f85-b18c-51c0-9a4e-6fa602477a2f"}
@@ -0,0 +1,93 @@
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]="b1e7fde6-15e5-5c0c-a0f0-a5eb5d6c8942")}catch(e){}}();
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var __async = (__this, __arguments, generator) => {
32
+ return new Promise((resolve, reject) => {
33
+ var fulfilled = (value) => {
34
+ try {
35
+ step(generator.next(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var rejected = (value) => {
41
+ try {
42
+ step(generator.throw(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
48
+ step((generator = generator.apply(__this, __arguments)).next());
49
+ });
50
+ };
51
+ var generateSwiftDriver_exports = {};
52
+ __export(generateSwiftDriver_exports, {
53
+ generateSwiftDriver: () => generateSwiftDriver
54
+ });
55
+ module.exports = __toCommonJS(generateSwiftDriver_exports);
56
+ var import_path = __toESM(require("path"));
57
+ var import_pull = require("../pull");
58
+ var import_api = require("../api");
59
+ var import_consts = __toESM(require("../consts"));
60
+ var import_output = __toESM(require("../output"));
61
+ function generateSwiftDriver(source) {
62
+ return __async(this, null, function* () {
63
+ const client = (0, import_api.createApiClient)();
64
+ const body = {
65
+ variants: source.variants,
66
+ localeByVariantId: source.localeByVariantApiId
67
+ };
68
+ if (source.componentFolders || source.componentRoot) {
69
+ body.components = {};
70
+ if (source.componentFolders) {
71
+ body.components.folders = source.componentFolders;
72
+ }
73
+ if (source.componentRoot) {
74
+ body.components.root = source.componentRoot;
75
+ }
76
+ } else if (source.shouldFetchComponentLibrary) {
77
+ body.components = true;
78
+ }
79
+ if (source.validProjects)
80
+ body.projects = source.validProjects;
81
+ const { data } = yield client.post("/v1/ios/swift-driver", body);
82
+ const filePath = import_path.default.join(import_consts.default.TEXT_DIR, "Ditto.swift");
83
+ yield (0, import_pull.writeFile)(filePath, data);
84
+ return `Successfully saved Swift driver to ${import_output.default.info("Ditto.swift")}`;
85
+ });
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ generateSwiftDriver
90
+ });
91
+ //# sourceMappingURL=generateSwiftDriver.js.map
92
+
93
+ //# debugId=b1e7fde6-15e5-5c0c-a0f0-a5eb5d6c8942
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../lib/utils/generateSwiftDriver.ts"],"sourcesContent":["import path from \"path\";\nimport { writeFile } from \"../pull\";\nimport { SourceInformation } from \"../types\";\nimport { createApiClient } from \"../api\";\nimport consts from \"../consts\";\nimport output from \"../output\";\n\ninterface IArg {\n variants: boolean;\n components?:\n | boolean\n | {\n root?: boolean | { status?: string };\n folders?: string[] | { id: string | null; status?: string }[];\n };\n projects?: string[] | { id: string; status?: string }[];\n localeByVariantId?: Record<string, string>;\n}\n\nexport async function generateSwiftDriver(source: SourceInformation) {\n const client = createApiClient();\n\n const body: IArg = {\n variants: source.variants,\n localeByVariantId: source.localeByVariantApiId,\n };\n\n if (source.componentFolders || source.componentRoot) {\n body.components = {};\n if (source.componentFolders) {\n body.components.folders = source.componentFolders;\n }\n if (source.componentRoot) {\n body.components.root = source.componentRoot;\n }\n } else if (source.shouldFetchComponentLibrary) {\n body.components = true;\n }\n\n if (source.validProjects) body.projects = source.validProjects;\n\n const { data } = await client.post<string>(\"/v1/ios/swift-driver\", body);\n\n const filePath = path.join(consts.TEXT_DIR, \"Ditto.swift\");\n await writeFile(filePath, data);\n\n return `Successfully saved Swift driver to ${output.info(\"Ditto.swift\")}`;\n}\n"],"names":["path","consts","output"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,kBAA0B;AAE1B,iBAAgC;AAChC,oBAAmB;AACnB,oBAAmB;AAcnB,SAAsB,oBAAoB,QAA2B;AAAA;AACnE,UAAM,aAAS,4BAAgB;AAE/B,UAAM,OAAa;AAAA,MACjB,UAAU,OAAO;AAAA,MACjB,mBAAmB,OAAO;AAAA,IAC5B;AAEA,QAAI,OAAO,oBAAoB,OAAO,eAAe;AACnD,WAAK,aAAa,CAAC;AACnB,UAAI,OAAO,kBAAkB;AAC3B,aAAK,WAAW,UAAU,OAAO;AAAA,MACnC;AACA,UAAI,OAAO,eAAe;AACxB,aAAK,WAAW,OAAO,OAAO;AAAA,MAChC;AAAA,IACF,WAAW,OAAO,6BAA6B;AAC7C,WAAK,aAAa;AAAA,IACpB;AAEA,QAAI,OAAO;AAAe,WAAK,WAAW,OAAO;AAEjD,UAAM,EAAE,KAAK,IAAI,MAAM,OAAO,KAAa,wBAAwB,IAAI;AAEvE,UAAM,WAAW,YAAAA,QAAK,KAAK,cAAAC,QAAO,UAAU,aAAa;AACzD,cAAM,uBAAU,UAAU,IAAI;AAE9B,WAAO,sCAAsC,cAAAC,QAAO,KAAK,aAAa,CAAC;AAAA,EACzE;AAAA","debug_id":"b1e7fde6-15e5-5c0c-a0f0-a5eb5d6c8942"}
package/lib/config.ts CHANGED
@@ -195,6 +195,7 @@ function parseSourceInformation(file?: string): SourceInformation {
195
195
  format,
196
196
  status,
197
197
  richText,
198
+ iosLocales,
198
199
  projects: projectsRoot,
199
200
  components: componentsRoot,
200
201
  } = readProjectConfigData(file);
@@ -251,6 +252,9 @@ function parseSourceInformation(file?: string): SourceInformation {
251
252
  hasComponentLibraryInProjects,
252
253
  componentRoot,
253
254
  componentFolders,
255
+ localeByVariantApiId: iosLocales
256
+ ? iosLocales.reduce((acc, e) => ({ ...acc, ...e }), {} as any)
257
+ : undefined,
254
258
  };
255
259
 
256
260
  Sentry.setContext("config", createSentryContext(result));
@@ -8,7 +8,7 @@ export async function fetchComponentFolders(): Promise<FetchComponentFoldersResp
8
8
  const api = createApiClient();
9
9
 
10
10
  const { data } = await api.get<FetchComponentFoldersResponse>(
11
- "/component-folders",
11
+ "/v1/component-folders",
12
12
  {}
13
13
  );
14
14
 
@@ -18,18 +18,23 @@ export async function fetchComponents(options: {
18
18
 
19
19
  if (options.componentFolder) {
20
20
  try {
21
- const { data } = await api.get<FetchComponentResponse>(`/component-folders/${options.componentFolder}/components`, {});
21
+ const { data } = await api.get<FetchComponentResponse>(
22
+ `/v1/component-folders/${options.componentFolder}/components`,
23
+ {}
24
+ );
22
25
 
23
26
  return data;
27
+ } catch (e) {
28
+ console.log(
29
+ `Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`
30
+ );
31
+ return {};
24
32
  }
25
- catch (e) {
26
- console.log(`Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`)
27
- return {}
28
- }
29
-
30
- }
31
- else {
32
- const { data } = await api.get<FetchComponentResponse>("/components", {});
33
+ } else {
34
+ const { data } = await api.get<FetchComponentResponse>(
35
+ "/v1/components",
36
+ {}
37
+ );
33
38
 
34
39
  return data;
35
40
  }
@@ -25,7 +25,7 @@ export async function fetchVariants(
25
25
  config.params.projectIds = validProjects.map(({ id }) => id);
26
26
  }
27
27
 
28
- const { data } = await api.get<{ apiID: string }[]>("/variants", config);
28
+ const { data } = await api.get<{ apiID: string }[]>("/v1/variants", config);
29
29
 
30
30
  return data;
31
31
  }
@@ -44,7 +44,7 @@ async function listProjects(token: Token, projectsAlreadySelected: Project[]) {
44
44
 
45
45
  let response: AxiosResponse<{ id: string; name: string }[]>;
46
46
  try {
47
- response = await api.get("/project-names");
47
+ response = await api.get("/v1/projects");
48
48
  } catch (e) {
49
49
  spinner.stop();
50
50
  throw e;
package/lib/pull.test.ts CHANGED
@@ -88,7 +88,10 @@ describe("downloadAndSaveBase", () => {
88
88
  (createApiClient as any).mockImplementation(() => ({
89
89
  get: () => ({ data: mockData }),
90
90
  }));
91
- const output = await downloadAndSaveBase(testProjects, "flat", undefined);
91
+ const output = await downloadAndSaveBase({
92
+ projects: testProjects,
93
+ format: "flat",
94
+ } as any);
92
95
  expect(/successfully saved/i.test(output)).toEqual(true);
93
96
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
94
97
  expect(directoryContents.length).toEqual(testProjects.length);
@@ -110,11 +113,10 @@ describe("downloadAndSaveBase", () => {
110
113
  (createApiClient as any).mockImplementation(() => ({
111
114
  get: () => ({ data: mockData }),
112
115
  }));
113
- const output = await downloadAndSaveBase(
114
- testProjects,
115
- "structured",
116
- undefined
117
- );
116
+ const output = await downloadAndSaveBase({
117
+ projects: testProjects,
118
+ format: "structured",
119
+ } as any);
118
120
  expect(/successfully saved/i.test(output)).toEqual(true);
119
121
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
120
122
  expect(directoryContents.length).toEqual(testProjects.length);
@@ -136,7 +138,10 @@ describe("downloadAndSaveBase", () => {
136
138
  (createApiClient as any).mockImplementation(() => ({
137
139
  get: () => ({ data: mockData }),
138
140
  }));
139
- const output = await downloadAndSaveBase(testProjects, "icu", undefined);
141
+ const output = await downloadAndSaveBase({
142
+ projects: testProjects,
143
+ format: "icu",
144
+ } as any);
140
145
  expect(/successfully saved/i.test(output)).toEqual(true);
141
146
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
142
147
  expect(directoryContents.length).toEqual(testProjects.length);
@@ -161,11 +166,10 @@ describe("downloadAndSaveBase", () => {
161
166
  (createApiClient as any).mockImplementation(() => ({
162
167
  get: () => ({ data: mockData }),
163
168
  }));
164
- const output = await downloadAndSaveBase(
165
- testProjects,
166
- "android",
167
- undefined
168
- );
169
+ const output = await downloadAndSaveBase({
170
+ projects: testProjects,
171
+ format: "android",
172
+ } as any);
169
173
  expect(/successfully saved/i.test(output)).toEqual(true);
170
174
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
171
175
  expect(directoryContents.length).toEqual(testProjects.length);
@@ -187,11 +191,10 @@ describe("downloadAndSaveBase", () => {
187
191
  (createApiClient as any).mockImplementation(() => ({
188
192
  get: () => ({ data: mockData }),
189
193
  }));
190
- const output = await downloadAndSaveBase(
191
- testProjects,
192
- "ios-strings",
193
- undefined
194
- );
194
+ const output = await downloadAndSaveBase({
195
+ projects: testProjects,
196
+ format: "ios-strings",
197
+ } as any);
195
198
  expect(/successfully saved/i.test(output)).toEqual(true);
196
199
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
197
200
  expect(directoryContents.length).toEqual(testProjects.length);
@@ -231,11 +234,10 @@ describe("downloadAndSaveBase", () => {
231
234
  (createApiClient as any).mockImplementation(() => ({
232
235
  get: () => ({ data: mockData }),
233
236
  }));
234
- const output = await downloadAndSaveBase(
235
- testProjects,
236
- "ios-stringsdict",
237
- undefined
238
- );
237
+ const output = await downloadAndSaveBase({
238
+ projects: testProjects,
239
+ format: "ios-stringsdict",
240
+ } as any);
239
241
  expect(/successfully saved/i.test(output)).toEqual(true);
240
242
  const directoryContents = fs.readdirSync(consts.TEXT_DIR);
241
243
  expect(directoryContents.length).toEqual(testProjects.length);