@looker/sdk-codegen-scripts 21.4.8 → 21.5.1
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/CHANGELOG.md +25 -1
- package/lib/convert.js +0 -10
- package/lib/convert.js.map +1 -1
- package/lib/declarationMiner.js +11 -37
- package/lib/declarationMiner.js.map +1 -1
- package/lib/esm/convert.js +20 -18
- package/lib/esm/convert.js.map +1 -1
- package/lib/esm/declarationMiner.js +32 -41
- package/lib/esm/declarationMiner.js.map +1 -1
- package/lib/esm/exampleMiner.js +52 -77
- package/lib/esm/exampleMiner.js.map +1 -1
- package/lib/esm/fetchSpec.js +65 -83
- package/lib/esm/fetchSpec.js.map +1 -1
- package/lib/esm/index.js +93 -8
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/languages.js +16 -11
- package/lib/esm/languages.js.map +1 -1
- package/lib/esm/legacy.js +8 -9
- package/lib/esm/legacy.js.map +1 -1
- package/lib/esm/legacyGenerator.js +19 -22
- package/lib/esm/legacyGenerator.js.map +1 -1
- package/lib/esm/nodeUtils.js +39 -22
- package/lib/esm/nodeUtils.js.map +1 -1
- package/lib/esm/prettify.js +15 -9
- package/lib/esm/prettify.js.map +1 -1
- package/lib/esm/reformatter.js +53 -102
- package/lib/esm/reformatter.js.map +1 -1
- package/lib/esm/sdkConfig.js +19 -13
- package/lib/esm/sdkConfig.js.map +1 -1
- package/lib/esm/sdkGen.js +43 -59
- package/lib/esm/sdkGen.js.map +1 -1
- package/lib/esm/sdkGenerator.js +34 -47
- package/lib/esm/sdkGenerator.js.map +1 -1
- package/lib/esm/specConvert.js +20 -27
- package/lib/esm/specConvert.js.map +1 -1
- package/lib/esm/testUtils/index.js +28 -0
- package/lib/esm/testUtils/index.js.map +1 -0
- package/lib/esm/testUtils/mocks.js +16 -0
- package/lib/esm/testUtils/mocks.js.map +1 -0
- package/lib/esm/testUtils/testUtils.js +66 -0
- package/lib/esm/testUtils/testUtils.js.map +1 -0
- package/lib/esm/utils.js +43 -60
- package/lib/esm/utils.js.map +1 -1
- package/lib/esm/yamlToJson.js +8 -6
- package/lib/esm/yamlToJson.js.map +1 -1
- package/lib/exampleMiner.js +4 -89
- package/lib/exampleMiner.js.map +1 -1
- package/lib/fetchSpec.js +6 -76
- package/lib/fetchSpec.js.map +1 -1
- package/lib/index.js +0 -16
- package/lib/index.js.map +1 -1
- package/lib/languages.js +0 -11
- package/lib/languages.js.map +1 -1
- package/lib/legacy.js +0 -5
- package/lib/legacy.js.map +1 -1
- package/lib/legacyGenerator.js +0 -15
- package/lib/legacyGenerator.js.map +1 -1
- package/lib/nodeUtils.js +1 -34
- package/lib/nodeUtils.js.map +1 -1
- package/lib/prettify.js +5 -14
- package/lib/prettify.js.map +1 -1
- package/lib/reformatter.js +3 -70
- package/lib/reformatter.js.map +1 -1
- package/lib/sdkConfig.js +0 -16
- package/lib/sdkConfig.js.map +1 -1
- package/lib/sdkGen.js +0 -41
- package/lib/sdkGen.js.map +1 -1
- package/lib/sdkGenerator.js +4 -52
- package/lib/sdkGenerator.js.map +1 -1
- package/lib/specConvert.js +0 -19
- package/lib/specConvert.js.map +1 -1
- package/lib/testUtils/index.js +0 -4
- package/lib/testUtils/index.js.map +1 -1
- package/lib/testUtils/mocks.js +0 -4
- package/lib/testUtils/mocks.js.map +1 -1
- package/lib/testUtils/testUtils.js +1 -17
- package/lib/testUtils/testUtils.js.map +1 -1
- package/lib/utils.js +6 -48
- package/lib/utils.js.map +1 -1
- package/lib/yamlToJson.js +0 -7
- package/lib/yamlToJson.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"legacyGenerator.js","names":["defaultApiVersion","props","versions","api_versions","split","length","generate","fileName","spec","path","language","legacy","apiVersion","apiPath","options","run","runConfig","name","targets","log","api_version","lookerVersions","fetchLookerVersions","specs","getSpecsFromVersions","openApiFile","logConvertSpec","languages","legacyLanguages","results","find","t","localeCompare","tag","push"],"sources":["../src/legacyGenerator.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport { log } from '@looker/sdk-codegen-utils'\nimport type { IGeneratorSpec, IApiVersion } from '@looker/sdk-codegen'\nimport { getSpecsFromVersions, legacyLanguages } from '@looker/sdk-codegen'\nimport type { ISDKConfigProps } from './sdkConfig'\nimport { run } from './nodeUtils'\nimport { fetchLookerVersions, logConvertSpec } from './fetchSpec'\n\n/**\n * Returns the last version in the .ini api_versions comma-delimited list\n * @param {ISDKConfigProps} props\n * @returns {string}\n */\nconst defaultApiVersion = (props: ISDKConfigProps) => {\n const versions = (props.api_versions || '4.0').split(',')\n return versions[versions.length - 1]\n}\n\n/**\n * Generate API bindings with the OpenAPI legacy code generator\n * DEPRECATED: This is using the legacy code generator perform the generation for specific API version, configuration,\n * and language\n *\n * @param {string} fileName specification file name\n * @param {IGeneratorSpec} spec for language generator options\n * @param {ISDKConfigProps} props SDK configuration properties\n * @returns {Promise<Buffer | string>}\n */\nconst generate = async (\n fileName: string,\n spec: IGeneratorSpec,\n props: ISDKConfigProps\n) => {\n const path = spec.path ? spec.path : spec.language\n const language = spec.legacy ? spec.legacy : spec.language\n const apiVersion = defaultApiVersion(props)\n const apiPath = `./api/${apiVersion}/${path}`\n const options = spec.options || ''\n return run('openapi-generator-cli', [\n 'generate',\n '-i',\n fileName,\n '-g',\n language,\n '-o',\n apiPath,\n '--enable-post-process-file',\n options,\n ])\n}\n\n/**\n * Generate all languages for the specified configuration\n * @param name configuration name\n * @param props SDK configuration properties\n * @param targets Optional array of languages to generate\n * @returns generation promises\n */\nexport const runConfig = async (\n name: string,\n props: ISDKConfigProps,\n targets: string[] = []\n) => {\n log(`processing ${name} configuration ...`)\n const apiVersion = defaultApiVersion(props)\n props.api_version = apiVersion\n const lookerVersions = await fetchLookerVersions(props)\n const specs = await getSpecsFromVersions(lookerVersions as IApiVersion)\n const openApiFile = await logConvertSpec(name, specs[apiVersion], props)\n const languages = legacyLanguages()\n\n const results: any[] = []\n for (const language of languages) {\n if (\n targets.length === 0 ||\n targets.find((t) => t.localeCompare(language.language) === 0)\n ) {\n const tag = `${name} API ${language.language} version ${apiVersion}`\n log(`generating ${tag} ...`)\n results.push(await generate(openApiFile, language, props))\n }\n }\n\n return results\n}\n"],"mappings":";;;;;;AA0BA;AAEA;AAEA;AACA;AAAiE;AAAA;AAOjE,IAAMA,iBAAiB,GAAIC,KAAsB,IAAK;EACpD,IAAMC,QAAQ,GAAG,CAACD,KAAK,CAACE,YAAY,IAAI,KAAK,EAAEC,KAAK,CAAC,GAAG,CAAC;EACzD,OAAOF,QAAQ,CAACA,QAAQ,CAACG,MAAM,GAAG,CAAC,CAAC;AACtC,CAAC;AAYD,IAAMC,QAAQ;EAAA,6BAAG,WACfC,QAAgB,EAChBC,IAAoB,EACpBP,KAAsB,EACnB;IACH,IAAMQ,IAAI,GAAGD,IAAI,CAACC,IAAI,GAAGD,IAAI,CA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,CAAC,EAC7D;QACA,IAAMuB,GAAG,aAAMhB,IAAI,kBAAQP,QAAQ,CAACA,QAAQ,sBAAYE,UAAU,CAAE;QACpE,IAAAO,oBAAG,uBAAec,GAAG,UAAO;QAC5BJ,OAAO,CAACK,IAAI,OAAO5B,QAAQ,CAACmB,WAAW,EAAEf,QAAQ,EAAET,KAAK,CAAC,CAAC;MAC5D;IACF,CAAC;IATD,KAAK,IAAMS,QAAQ,IAAIiB,SAAS;MAAA;IAAA;IAWhC,OAAOE,OAAO;EAChB,CAAC;EAAA,gBA1BYb,SAAS;IAAA;EAAA;AAAA,GA0BrB;AAAA"}
|
package/lib/nodeUtils.js
CHANGED
|
@@ -3,46 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.writeFileSync = exports.utf8Encoding = exports.run = exports.rootFile = exports.readFileSync = exports.quit = exports.isFileSync = exports.isDirSync = exports.getRootPath = exports.fail = exports.createJsonFile = void 0;
|
|
8
7
|
var fs = _interopRequireWildcard(require("fs"));
|
|
9
|
-
|
|
10
8
|
var _child_process = require("child_process");
|
|
11
|
-
|
|
12
9
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
10
|
var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
14
|
var utf8 = 'utf-8';
|
|
23
15
|
var utf8Encoding = {
|
|
24
16
|
encoding: utf8
|
|
25
17
|
};
|
|
26
18
|
exports.utf8Encoding = utf8Encoding;
|
|
27
|
-
|
|
28
19
|
var readFileSync = function readFileSync(filePath) {
|
|
29
20
|
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : utf8;
|
|
30
21
|
return fs.readFileSync(filePath, {
|
|
31
22
|
encoding: encoding
|
|
32
23
|
});
|
|
33
24
|
};
|
|
34
|
-
|
|
35
25
|
exports.readFileSync = readFileSync;
|
|
36
|
-
|
|
37
26
|
var writeFileSync = function writeFileSync(filePath, data) {
|
|
38
27
|
var encoding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : utf8;
|
|
39
28
|
return fs.writeFileSync(filePath, data, {
|
|
40
29
|
encoding: encoding
|
|
41
30
|
});
|
|
42
31
|
};
|
|
43
|
-
|
|
44
32
|
exports.writeFileSync = writeFileSync;
|
|
45
|
-
|
|
46
33
|
var isDirSync = filePath => {
|
|
47
34
|
try {
|
|
48
35
|
return fs.statSync(filePath).isDirectory();
|
|
@@ -54,26 +41,18 @@ var isDirSync = filePath => {
|
|
|
54
41
|
}
|
|
55
42
|
}
|
|
56
43
|
};
|
|
57
|
-
|
|
58
44
|
exports.isDirSync = isDirSync;
|
|
59
45
|
var homeToRoost = '../../../';
|
|
60
|
-
|
|
61
46
|
var getRootPath = () => _path.default.join(__dirname, homeToRoost);
|
|
62
|
-
|
|
63
47
|
exports.getRootPath = getRootPath;
|
|
64
|
-
|
|
65
48
|
var rootFile = function rootFile() {
|
|
66
49
|
var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
67
50
|
return _path.default.join(getRootPath(), fileName);
|
|
68
51
|
};
|
|
69
|
-
|
|
70
52
|
exports.rootFile = rootFile;
|
|
71
|
-
|
|
72
53
|
var createJsonFile = (fileName, content) => {
|
|
73
54
|
var fullName = rootFile(fileName);
|
|
74
|
-
|
|
75
55
|
var dir = _path.default.dirname(fullName);
|
|
76
|
-
|
|
77
56
|
var data = typeof content === 'string' ? content : JSON.stringify(content);
|
|
78
57
|
if (!isDirSync(dir)) fs.mkdirSync(dir, {
|
|
79
58
|
recursive: true
|
|
@@ -81,9 +60,7 @@ var createJsonFile = (fileName, content) => {
|
|
|
81
60
|
fs.writeFileSync(fullName, data, utf8Encoding);
|
|
82
61
|
return fullName;
|
|
83
62
|
};
|
|
84
|
-
|
|
85
63
|
exports.createJsonFile = createJsonFile;
|
|
86
|
-
|
|
87
64
|
var isFileSync = filePath => {
|
|
88
65
|
try {
|
|
89
66
|
return fs.statSync(filePath).isFile();
|
|
@@ -95,9 +72,7 @@ var isFileSync = filePath => {
|
|
|
95
72
|
}
|
|
96
73
|
}
|
|
97
74
|
};
|
|
98
|
-
|
|
99
75
|
exports.isFileSync = isFileSync;
|
|
100
|
-
|
|
101
76
|
var quit = err => {
|
|
102
77
|
if (err) {
|
|
103
78
|
if (typeof err === 'string') {
|
|
@@ -105,27 +80,21 @@ var quit = err => {
|
|
|
105
80
|
err = new Error('Failure');
|
|
106
81
|
err.message = message;
|
|
107
82
|
}
|
|
108
|
-
|
|
109
83
|
console.error("Error: ".concat(err.name, ", ").concat(err.message));
|
|
110
84
|
console.error(err.stack);
|
|
111
85
|
process.exit(1);
|
|
112
86
|
} else {
|
|
113
87
|
process.exit(0);
|
|
114
88
|
}
|
|
115
|
-
|
|
116
89
|
return '';
|
|
117
90
|
};
|
|
118
|
-
|
|
119
91
|
exports.quit = quit;
|
|
120
|
-
|
|
121
92
|
var fail = (name, message) => {
|
|
122
93
|
var err = new Error(message);
|
|
123
94
|
err.name = name;
|
|
124
95
|
return quit(err);
|
|
125
96
|
};
|
|
126
|
-
|
|
127
97
|
exports.fail = fail;
|
|
128
|
-
|
|
129
98
|
var run = function run(command, args, errMsg) {
|
|
130
99
|
var warning = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
131
100
|
var options = {
|
|
@@ -134,7 +103,6 @@ var run = function run(command, args, errMsg) {
|
|
|
134
103
|
timeout: 300 * 1000,
|
|
135
104
|
windowsHide: true
|
|
136
105
|
};
|
|
137
|
-
|
|
138
106
|
try {
|
|
139
107
|
command += ' ' + args.join(' ');
|
|
140
108
|
return (0, _child_process.execSync)(command, options);
|
|
@@ -147,6 +115,5 @@ var run = function run(command, args, errMsg) {
|
|
|
147
115
|
}
|
|
148
116
|
}
|
|
149
117
|
};
|
|
150
|
-
|
|
151
118
|
exports.run = run;
|
|
152
119
|
//# sourceMappingURL=nodeUtils.js.map
|
package/lib/nodeUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"nodeUtils.js","names":["utf8","utf8Encoding","encoding","readFileSync","filePath","fs","writeFileSync","data","isDirSync","statSync","isDirectory","e","code","homeToRoost","getRootPath","path","join","__dirname","rootFile","fileName","createJsonFile","content","fullName","dir","dirname","JSON","stringify","mkdirSync","recursive","isFileSync","isFile","quit","err","message","Error","console","error","name","stack","process","exit","fail","run","command","args","errMsg","warning","options","maxBuffer","timeout","windowsHide","execSync","warn"],"sources":["../src/nodeUtils.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport type { ExecSyncOptionsWithStringEncoding } from 'child_process'\nimport { execSync } from 'child_process'\nimport path from 'path'\nimport { warn } from '@looker/sdk-codegen-utils'\n\nconst utf8: BufferEncoding = 'utf-8'\nexport const utf8Encoding = { encoding: utf8 }\n\n/**\n * Abstraction of reading a file so all refs go to one place\n * @param filePath name of file\n * @param encoding character encoding. defaults to utf-8\n * @returns {string}\n */\nexport const readFileSync = (\n filePath: string,\n encoding: BufferEncoding = utf8\n) => fs.readFileSync(filePath, { encoding: encoding })\n\nexport const writeFileSync = (\n filePath: string,\n data: any,\n encoding: BufferEncoding = utf8\n) => fs.writeFileSync(filePath, data, { encoding: encoding })\n\nexport const isDirSync = (filePath: string) => {\n try {\n return fs.statSync(filePath).isDirectory()\n } catch (e: any) {\n if (e.code === 'ENOENT') {\n return false\n } else {\n throw e\n }\n }\n}\n\nconst homeToRoost = '../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\n\n/**\n * Creates the directory if needed, converts content to JSON string, writes file\n *\n * @param fileName to write that may include a relative path\n * @param {object | string} content to convert to a JSON string\n * @returns name of file written\n */\nexport const createJsonFile = (\n fileName: string,\n content: Record<string, unknown> | string\n) => {\n const fullName = rootFile(fileName)\n const dir = path.dirname(fullName)\n const data = typeof content === 'string' ? content : JSON.stringify(content)\n if (!isDirSync(dir)) fs.mkdirSync(dir, { recursive: true })\n fs.writeFileSync(fullName, data, utf8Encoding)\n return fullName\n}\n\nexport const isFileSync = (filePath: string) => {\n try {\n return fs.statSync(filePath).isFile()\n } catch (e: any) {\n if (e.code === 'ENOENT') {\n return false\n } else {\n throw e\n }\n }\n}\n\nexport const quit = (err?: Error | string) => {\n if (err) {\n if (typeof err === 'string') {\n const message = err\n err = new Error('Failure')\n err.message = message\n }\n console.error(`Error: ${err.name}, ${err.message}`)\n console.error(err.stack)\n process.exit(1)\n } else {\n process.exit(0)\n }\n return '' // spoof return type for TypeScript to not complain\n}\n\nexport const fail = (name: string, message: string) => {\n const err = new Error(message)\n err.name = name\n return quit(err)\n}\n\nexport const run = (\n command: string,\n args: string[],\n errMsg?: string,\n warning = false\n) => {\n // https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options\n const options: ExecSyncOptionsWithStringEncoding = {\n encoding: 'utf8',\n maxBuffer: 1024 * 2048,\n timeout: 300 * 1000,\n windowsHide: true,\n }\n try {\n // const result = await spawnSync(command, args, options)\n command += ' ' + args.join(' ')\n return execSync(command, options)\n } catch (e: any) {\n if (warning) {\n warn(`${errMsg}: ${e.message}`)\n return ''\n } else {\n return quit(errMsg || e)\n }\n }\n}\n"],"mappings":";;;;;;AA0BA;AAEA;AACA;AACA;AAAgD;AAAA;AAAA;AAEhD,IAAMA,IAAoB,GAAG,OAAO;AAC7B,IAAMC,YAAY,GAAG;EAAEC,QAAQ,EAAEF;AAAK,CAAC;AAAA;AAQvC,IAAMG,YAAY,GAAG,SAAfA,YAAY,CACvBC,QAAgB;EAAA,IAChBF,QAAwB,uEAAGF,IAAI;EAAA,OAC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,GAAG,CACdC,OAAe,EACfC,IAAc,EACdC,MAAe,EAEZ;EAAA,IADHC,OAAO,uEAAG,KAAK;EAGf,IAAMC,OAA0C,GAAG;IACjD7C,QAAQ,EAAE,MAAM;IAChB8C,SAAS,EAAE,IAAI,GAAG,IAAI;IACtBC,OAAO,EAAE,GAAG,GAAG,IAAI;IACnBC,WAAW,EAAE;EACf,CAAC;EACD,IAAI;IAEFP,OAAO,IAAI,GAAG,GAAGC,IAAI,CAAC5B,IAAI,CAAC,GAAG,CAAC;IAC/B,OAAO,IAAAmC,uBAAQ,EAACR,OAAO,EAAEI,OAAO,CAAC;EACnC,CAAC,CAAC,OAAOpC,CAAM,EAAE;IACf,IAAImC,OAAO,EAAE;MACX,IAAAM,qBAAI,YAAIP,MAAM,eAAKlC,CAAC,CAACsB,OAAO,EAAG;MAC/B,OAAO,EAAE;IACX,CAAC,MAAM;MACL,OAAOF,IAAI,CAACc,MAAM,IAAIlC,CAAC,CAAC;IAC1B;EACF;AACF,CAAC;AAAA"}
|
package/lib/prettify.js
CHANGED
|
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.prettify = void 0;
|
|
7
|
-
|
|
8
7
|
var prettier = _interopRequireWildcard(require("prettier"));
|
|
9
|
-
|
|
10
8
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
|
|
12
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
20
15
|
var prettierTs = {
|
|
21
16
|
bracketSpacing: true,
|
|
22
17
|
endOfLine: 'auto',
|
|
@@ -28,16 +23,12 @@ var prettierTs = {
|
|
|
28
23
|
trailingComma: 'es5',
|
|
29
24
|
arrowParens: 'always'
|
|
30
25
|
};
|
|
31
|
-
|
|
32
26
|
var prettify = function prettify(code) {
|
|
33
27
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
-
|
|
35
28
|
var merged = _objectSpread(_objectSpread({}, prettierTs), {
|
|
36
29
|
options
|
|
37
30
|
});
|
|
38
|
-
|
|
39
31
|
return prettier.format(code, merged);
|
|
40
32
|
};
|
|
41
|
-
|
|
42
33
|
exports.prettify = prettify;
|
|
43
34
|
//# sourceMappingURL=prettify.js.map
|
package/lib/prettify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"prettify.js","names":["prettierTs","bracketSpacing","endOfLine","parser","proseWrap","quoteProps","semi","singleQuote","trailingComma","arrowParens","prettify","code","options","merged","prettier","format"],"sources":["../src/prettify.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as prettier from 'prettier'\n\nconst prettierTs: prettier.Options = {\n bracketSpacing: true,\n endOfLine: 'auto',\n parser: 'typescript',\n proseWrap: 'preserve',\n quoteProps: 'as-needed',\n semi: false,\n singleQuote: true,\n trailingComma: 'es5',\n arrowParens: 'always',\n}\n\n/**\n * Format code with Prettier\n * @param code to format\n * @param options prettier.Options to override the default processing. Typescript options are the default\n */\nexport const prettify = (code: string, options: prettier.Options = {}) => {\n const merged: prettier.Options = { ...prettierTs, ...{ options } }\n return prettier.format(code, merged)\n}\n"],"mappings":";;;;;;AA0BA;AAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEpC,IAAMA,UAA4B,GAAG;EACnCC,cAAc,EAAE,IAAI;EACpBC,SAAS,EAAE,MAAM;EACjBC,MAAM,EAAE,YAAY;EACpBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,IAAI,EAAE,KAAK;EACXC,WAAW,EAAE,IAAI;EACjBC,aAAa,EAAE,KAAK;EACpBC,WAAW,EAAE;AACf,CAAC;AAOM,IAAMC,QAAQ,GAAG,SAAXA,QAAQ,CAAIC,IAAY,EAAqC;EAAA,IAAnCC,OAAyB,uEAAG,CAAC,CAAC;EACnE,IAAMC,MAAwB,mCAAQb,UAAU,GAAK;IAAEY;EAAQ,CAAC,CAAE;EAClE,OAAOE,QAAQ,CAACC,MAAM,CAACJ,IAAI,EAAEE,MAAM,CAAC;AACtC,CAAC;AAAA"}
|
package/lib/reformatter.js
CHANGED
|
@@ -4,65 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FilesFormatter = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var fs = _interopRequireWildcard(require("fs"));
|
|
11
|
-
|
|
12
9
|
var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
|
|
13
|
-
|
|
14
10
|
var _nodeUtils = require("./nodeUtils");
|
|
15
|
-
|
|
16
11
|
var _prettify = require("./prettify");
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
24
17
|
var writeFile = (fileName, content) => {
|
|
25
18
|
fs.writeFileSync(fileName, content, _nodeUtils.utf8Encoding);
|
|
26
19
|
};
|
|
27
|
-
|
|
28
20
|
var noFormatter = (language, files) => {
|
|
29
21
|
var list = files.join('\n ');
|
|
30
22
|
return (0, _sdkCodegenUtils.warn)("There is no ".concat(language, " formatter. Skipped reformatting of:\n ").concat(list));
|
|
31
23
|
};
|
|
32
|
-
|
|
33
24
|
var fullPath = weirdPath => path.resolve(weirdPath);
|
|
34
|
-
|
|
35
25
|
class BaseFormatter {
|
|
36
26
|
constructor(language) {
|
|
37
27
|
var fileSep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : " \n";
|
|
38
28
|
this.language = language;
|
|
39
29
|
this.fileSep = fileSep;
|
|
40
30
|
}
|
|
41
|
-
|
|
42
31
|
reformat(files) {
|
|
43
32
|
return noFormatter(this.language, files);
|
|
44
33
|
}
|
|
45
|
-
|
|
46
34
|
skipping() {
|
|
47
35
|
return (0, _sdkCodegenUtils.warn)("Version information was not retrieved. Skipping ".concat(this.language, " SDK version updating."));
|
|
48
36
|
}
|
|
49
|
-
|
|
50
37
|
reformatted(files) {
|
|
51
38
|
return (0, _sdkCodegenUtils.success)("Reformatted ".concat(this.language, " files:\n ").concat(files.join(this.fileSep)));
|
|
52
39
|
}
|
|
53
|
-
|
|
54
40
|
}
|
|
55
|
-
|
|
56
41
|
class PythonFormatter extends BaseFormatter {
|
|
57
42
|
constructor() {
|
|
58
43
|
super('Python');
|
|
59
|
-
|
|
60
44
|
_defineProperty(this, "instructions", 'To reformat Python files, please install pipenv: https://docs.pipenv.org/en/latest/install/#installing-pipenv');
|
|
61
45
|
}
|
|
62
|
-
|
|
63
46
|
reformat(files) {
|
|
64
47
|
var pipEnvExists = (0, _nodeUtils.run)('command', ['-v', 'pipenv'], this.instructions, true);
|
|
65
|
-
|
|
66
48
|
if (pipEnvExists.includes('pipenv')) {
|
|
67
49
|
var list = files.join(' ');
|
|
68
50
|
(0, _nodeUtils.run)('pipenv', ['run', 'black', list], 'Python reformat', true);
|
|
@@ -71,15 +53,12 @@ class PythonFormatter extends BaseFormatter {
|
|
|
71
53
|
return (0, _sdkCodegenUtils.danger)(this.instructions);
|
|
72
54
|
}
|
|
73
55
|
}
|
|
74
|
-
|
|
75
56
|
versionStamp(gen) {
|
|
76
57
|
if (gen.versions && gen.versions.lookerVersion) {
|
|
77
58
|
var stampFile = fullPath(gen.fileName('sdk/constants'));
|
|
78
|
-
|
|
79
59
|
if (!(0, _nodeUtils.isFileSync)(stampFile)) {
|
|
80
60
|
(0, _sdkCodegenUtils.warn)("".concat(stampFile, " was not found. Skipping version update."));
|
|
81
61
|
}
|
|
82
|
-
|
|
83
62
|
var content = (0, _nodeUtils.readFileSync)(stampFile);
|
|
84
63
|
var sdkVersionPattern = /sdk_version = ['"].*['"]/i;
|
|
85
64
|
var envPattern = /environment_prefix = ['"].*['"]/i;
|
|
@@ -88,42 +67,32 @@ class PythonFormatter extends BaseFormatter {
|
|
|
88
67
|
writeFile(stampFile, content);
|
|
89
68
|
return (0, _sdkCodegenUtils.success)("updated ".concat(stampFile, " to ").concat(gen.versions.lookerVersion));
|
|
90
69
|
}
|
|
91
|
-
|
|
92
70
|
return this.skipping();
|
|
93
71
|
}
|
|
94
|
-
|
|
95
72
|
}
|
|
96
|
-
|
|
97
73
|
class TypescriptFormatter extends BaseFormatter {
|
|
98
74
|
constructor() {
|
|
99
75
|
super('TypeScript');
|
|
100
76
|
}
|
|
101
|
-
|
|
102
77
|
reformat(files) {
|
|
103
78
|
files.forEach(f => {
|
|
104
79
|
this.reformatFile(f);
|
|
105
80
|
});
|
|
106
81
|
return (0, _sdkCodegenUtils.success)(files);
|
|
107
82
|
}
|
|
108
|
-
|
|
109
83
|
reformatFile(fileName) {
|
|
110
84
|
var source = (0, _prettify.prettify)((0, _nodeUtils.readFileSync)(fileName));
|
|
111
|
-
|
|
112
85
|
if (source) {
|
|
113
86
|
writeFile(fileName, source);
|
|
114
87
|
}
|
|
115
|
-
|
|
116
88
|
return fileName;
|
|
117
89
|
}
|
|
118
|
-
|
|
119
90
|
versionStamp(gen) {
|
|
120
91
|
if (gen.versions && gen.versions.lookerVersion) {
|
|
121
92
|
var stampFile = fullPath(gen.fileName('../../sdk/src/constants'));
|
|
122
|
-
|
|
123
93
|
if (!(0, _nodeUtils.isFileSync)(stampFile)) {
|
|
124
94
|
(0, _sdkCodegenUtils.warn)("".concat(stampFile, " was not found. Skipping version update."));
|
|
125
95
|
}
|
|
126
|
-
|
|
127
96
|
var content = (0, _nodeUtils.readFileSync)(stampFile);
|
|
128
97
|
var sdkVersionPattern = /sdkVersion = ['"].*['"]/i;
|
|
129
98
|
var envPattern = /environmentPrefix = ['"].*['"]/i;
|
|
@@ -132,25 +101,19 @@ class TypescriptFormatter extends BaseFormatter {
|
|
|
132
101
|
writeFile(stampFile, content);
|
|
133
102
|
return (0, _sdkCodegenUtils.success)("updated ".concat(stampFile, " to ").concat(gen.versions.lookerVersion));
|
|
134
103
|
}
|
|
135
|
-
|
|
136
104
|
return this.skipping();
|
|
137
105
|
}
|
|
138
|
-
|
|
139
106
|
}
|
|
140
|
-
|
|
141
107
|
class KotlinFormatter extends BaseFormatter {
|
|
142
108
|
constructor() {
|
|
143
109
|
super('Kotlin');
|
|
144
110
|
}
|
|
145
|
-
|
|
146
111
|
versionStamp(gen) {
|
|
147
112
|
if (gen.versions && gen.versions.lookerVersion) {
|
|
148
113
|
var stampFile = fullPath(gen.fileName('sdk/Constants'));
|
|
149
|
-
|
|
150
114
|
if (!(0, _nodeUtils.isFileSync)(stampFile)) {
|
|
151
115
|
(0, _sdkCodegenUtils.warn)("".concat(stampFile, " was not found. Skipping version update."));
|
|
152
116
|
}
|
|
153
|
-
|
|
154
117
|
var content = (0, _nodeUtils.readFileSync)(stampFile);
|
|
155
118
|
var lookerPattern = /\bLOOKER_VERSION = ['"].*['"]/i;
|
|
156
119
|
var apiPattern = /\bAPI_VERSION = ['"].*['"]/i;
|
|
@@ -161,25 +124,19 @@ class KotlinFormatter extends BaseFormatter {
|
|
|
161
124
|
writeFile(stampFile, content);
|
|
162
125
|
return (0, _sdkCodegenUtils.success)("updated ".concat(stampFile, " to ").concat(gen.versions.spec.version, ".").concat(gen.versions.lookerVersion));
|
|
163
126
|
}
|
|
164
|
-
|
|
165
127
|
return this.skipping();
|
|
166
128
|
}
|
|
167
|
-
|
|
168
129
|
}
|
|
169
|
-
|
|
170
130
|
class SwiftFormatter extends BaseFormatter {
|
|
171
131
|
constructor() {
|
|
172
132
|
super('Swift');
|
|
173
133
|
}
|
|
174
|
-
|
|
175
134
|
versionStamp(gen) {
|
|
176
135
|
if (gen.versions && gen.versions.lookerVersion) {
|
|
177
136
|
var stampFile = fullPath(gen.fileName('rtl/constants'));
|
|
178
|
-
|
|
179
137
|
if (!(0, _nodeUtils.isFileSync)(stampFile)) {
|
|
180
138
|
(0, _sdkCodegenUtils.warn)("".concat(stampFile, " was not found. Skipping version update."));
|
|
181
139
|
}
|
|
182
|
-
|
|
183
140
|
var content = (0, _nodeUtils.readFileSync)(stampFile);
|
|
184
141
|
var lookerPattern = /lookerVersion = ['"].*['"]/i;
|
|
185
142
|
var apiPattern = /apiVersion = ['"].*['"]/i;
|
|
@@ -190,25 +147,19 @@ class SwiftFormatter extends BaseFormatter {
|
|
|
190
147
|
writeFile(stampFile, content);
|
|
191
148
|
return (0, _sdkCodegenUtils.success)("updated ".concat(stampFile, " to ").concat(gen.versions.spec.version, ".").concat(gen.versions.lookerVersion));
|
|
192
149
|
}
|
|
193
|
-
|
|
194
150
|
return this.skipping();
|
|
195
151
|
}
|
|
196
|
-
|
|
197
152
|
}
|
|
198
|
-
|
|
199
153
|
class CsharpFormatter extends BaseFormatter {
|
|
200
154
|
constructor() {
|
|
201
155
|
super('C#');
|
|
202
156
|
}
|
|
203
|
-
|
|
204
157
|
versionStamp(gen) {
|
|
205
158
|
if (gen.versions && gen.versions.lookerVersion) {
|
|
206
159
|
var stampFile = fullPath(gen.fileName('rtl/Constants'));
|
|
207
|
-
|
|
208
160
|
if (!(0, _nodeUtils.isFileSync)(stampFile)) {
|
|
209
161
|
(0, _sdkCodegenUtils.warn)("".concat(stampFile, " was not found. Skipping version update."));
|
|
210
162
|
}
|
|
211
|
-
|
|
212
163
|
var content = (0, _nodeUtils.readFileSync)(stampFile);
|
|
213
164
|
var lookerPattern = /LookerVersion = ['"].*['"]/i;
|
|
214
165
|
var apiPattern = /ApiVersion = ['"].*['"]/i;
|
|
@@ -219,22 +170,16 @@ class CsharpFormatter extends BaseFormatter {
|
|
|
219
170
|
writeFile(stampFile, content);
|
|
220
171
|
return (0, _sdkCodegenUtils.success)("updated ".concat(stampFile, " to ").concat(gen.versions.spec.version, ".").concat(gen.versions.lookerVersion));
|
|
221
172
|
}
|
|
222
|
-
|
|
223
173
|
return this.skipping();
|
|
224
174
|
}
|
|
225
|
-
|
|
226
175
|
}
|
|
227
|
-
|
|
228
176
|
class GoFormatter extends BaseFormatter {
|
|
229
177
|
constructor() {
|
|
230
178
|
super('Go');
|
|
231
|
-
|
|
232
179
|
_defineProperty(this, "instructions", 'To reformat Go files, please install gofmt: https://go.dev/blog/gofmt');
|
|
233
180
|
}
|
|
234
|
-
|
|
235
181
|
reformat(files) {
|
|
236
182
|
var gofmtExists = (0, _nodeUtils.run)('command', ['-v', 'gofmt'], this.instructions, true);
|
|
237
|
-
|
|
238
183
|
if (gofmtExists.includes('gofmt')) {
|
|
239
184
|
var list = files.join(' ');
|
|
240
185
|
(0, _nodeUtils.run)('gofmt', ['-w', list], 'Go reformat', true);
|
|
@@ -243,13 +188,10 @@ class GoFormatter extends BaseFormatter {
|
|
|
243
188
|
return (0, _sdkCodegenUtils.danger)(this.instructions);
|
|
244
189
|
}
|
|
245
190
|
}
|
|
246
|
-
|
|
247
191
|
versionStamp() {
|
|
248
192
|
return (0, _sdkCodegenUtils.warn)('Skipping SDK version updating - not implemented for Go.');
|
|
249
193
|
}
|
|
250
|
-
|
|
251
194
|
}
|
|
252
|
-
|
|
253
195
|
var fileFormatters = {
|
|
254
196
|
'.cs': new CsharpFormatter(),
|
|
255
197
|
'.kt': new KotlinFormatter(),
|
|
@@ -258,43 +200,34 @@ var fileFormatters = {
|
|
|
258
200
|
'.ts': new TypescriptFormatter(),
|
|
259
201
|
'.go': new GoFormatter()
|
|
260
202
|
};
|
|
261
|
-
|
|
262
203
|
class FilesFormatter {
|
|
263
204
|
constructor() {
|
|
264
205
|
_defineProperty(this, "files", {});
|
|
265
206
|
}
|
|
266
|
-
|
|
267
207
|
addFile(fileName) {
|
|
268
208
|
var key = path.extname(fileName);
|
|
269
|
-
|
|
270
209
|
if (key in this.files) {
|
|
271
210
|
this.files[key].push(fileName);
|
|
272
211
|
} else {
|
|
273
212
|
this.files[key] = [fileName];
|
|
274
213
|
}
|
|
275
214
|
}
|
|
276
|
-
|
|
277
215
|
clear() {
|
|
278
216
|
this.files = {};
|
|
279
217
|
}
|
|
280
|
-
|
|
281
218
|
reformat(files) {
|
|
282
219
|
if (files) files.forEach(f => this.addFile(f));
|
|
283
220
|
Object.entries(this.files).forEach(_ref => {
|
|
284
221
|
var [key, list] = _ref;
|
|
285
|
-
|
|
286
222
|
if (key in fileFormatters) {
|
|
287
223
|
fileFormatters[key].reformat(list);
|
|
288
224
|
}
|
|
289
225
|
});
|
|
290
226
|
}
|
|
291
|
-
|
|
292
227
|
versionStamp(gen) {
|
|
293
228
|
var formatter = fileFormatters[gen.fileExtension];
|
|
294
229
|
return formatter.versionStamp(gen);
|
|
295
230
|
}
|
|
296
|
-
|
|
297
231
|
}
|
|
298
|
-
|
|
299
232
|
exports.FilesFormatter = FilesFormatter;
|
|
300
233
|
//# sourceMappingURL=reformatter.js.map
|