@looker/sdk-codegen-scripts 21.4.8 → 21.5.0
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 +18 -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,17 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runConfig = void 0;
|
|
7
|
+
var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
|
|
8
|
+
var _sdkCodegen = require("@looker/sdk-codegen");
|
|
9
|
+
var _nodeUtils = require("./nodeUtils");
|
|
10
|
+
var _fetchSpec = require("./fetchSpec");
|
|
1
11
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
-
|
|
3
12
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
-
|
|
5
|
-
import { log } from '@looker/sdk-codegen-utils';
|
|
6
|
-
import { getSpecsFromVersions, legacyLanguages } from '@looker/sdk-codegen';
|
|
7
|
-
import { run } from './nodeUtils';
|
|
8
|
-
import { fetchLookerVersions, logConvertSpec } from './fetchSpec';
|
|
9
|
-
|
|
10
13
|
var defaultApiVersion = props => {
|
|
11
14
|
var versions = (props.api_versions || '4.0').split(',');
|
|
12
15
|
return versions[versions.length - 1];
|
|
13
16
|
};
|
|
14
|
-
|
|
15
17
|
var generate = function () {
|
|
16
18
|
var _ref = _asyncToGenerator(function* (fileName, spec, props) {
|
|
17
19
|
var path = spec.path ? spec.path : spec.language;
|
|
@@ -19,43 +21,38 @@ var generate = function () {
|
|
|
19
21
|
var apiVersion = defaultApiVersion(props);
|
|
20
22
|
var apiPath = "./api/".concat(apiVersion, "/").concat(path);
|
|
21
23
|
var options = spec.options || '';
|
|
22
|
-
return run('openapi-generator-cli', ['generate', '-i', fileName, '-g', language, '-o', apiPath, '--enable-post-process-file', options]);
|
|
24
|
+
return (0, _nodeUtils.run)('openapi-generator-cli', ['generate', '-i', fileName, '-g', language, '-o', apiPath, '--enable-post-process-file', options]);
|
|
23
25
|
});
|
|
24
|
-
|
|
25
26
|
return function generate(_x, _x2, _x3) {
|
|
26
27
|
return _ref.apply(this, arguments);
|
|
27
28
|
};
|
|
28
29
|
}();
|
|
29
|
-
|
|
30
|
-
export var runConfig = function () {
|
|
30
|
+
var runConfig = function () {
|
|
31
31
|
var _ref2 = _asyncToGenerator(function* (name, props) {
|
|
32
32
|
var targets = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
33
|
-
log("processing ".concat(name, " configuration ..."));
|
|
33
|
+
(0, _sdkCodegenUtils.log)("processing ".concat(name, " configuration ..."));
|
|
34
34
|
var apiVersion = defaultApiVersion(props);
|
|
35
35
|
props.api_version = apiVersion;
|
|
36
|
-
var lookerVersions = yield fetchLookerVersions(props);
|
|
37
|
-
var specs = yield getSpecsFromVersions(lookerVersions);
|
|
38
|
-
var openApiFile = yield logConvertSpec(name, specs[apiVersion], props);
|
|
39
|
-
var languages = legacyLanguages();
|
|
36
|
+
var lookerVersions = yield (0, _fetchSpec.fetchLookerVersions)(props);
|
|
37
|
+
var specs = yield (0, _sdkCodegen.getSpecsFromVersions)(lookerVersions);
|
|
38
|
+
var openApiFile = yield (0, _fetchSpec.logConvertSpec)(name, specs[apiVersion], props);
|
|
39
|
+
var languages = (0, _sdkCodegen.legacyLanguages)();
|
|
40
40
|
var results = [];
|
|
41
|
-
|
|
42
41
|
var _loop = function* _loop(language) {
|
|
43
42
|
if (targets.length === 0 || targets.find(t => t.localeCompare(language.language) === 0)) {
|
|
44
43
|
var tag = "".concat(name, " API ").concat(language.language, " version ").concat(apiVersion);
|
|
45
|
-
log("generating ".concat(tag, " ..."));
|
|
44
|
+
(0, _sdkCodegenUtils.log)("generating ".concat(tag, " ..."));
|
|
46
45
|
results.push(yield generate(openApiFile, language, props));
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
|
-
|
|
50
48
|
for (var language of languages) {
|
|
51
49
|
yield* _loop(language);
|
|
52
50
|
}
|
|
53
|
-
|
|
54
51
|
return results;
|
|
55
52
|
});
|
|
56
|
-
|
|
57
53
|
return function runConfig(_x4, _x5) {
|
|
58
54
|
return _ref2.apply(this, arguments);
|
|
59
55
|
};
|
|
60
56
|
}();
|
|
57
|
+
exports.runConfig = runConfig;
|
|
61
58
|
//# sourceMappingURL=legacyGenerator.js.map
|
|
@@ -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;AA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AAC,gCAAoB,EAACH,cAAc,CAAgB;IACvE,IAAMI,WAAW,SAAS,IAAAC,yBAAc,EAACT,IAAI,EAAEM,KAAK,CAACX,UAAU,CAAC,EAAEX,KAAK,CAAC;IACxE,IAAM0B,SAAS,GAAG,IAAAC,2BAAe,GAAE;IAEnC,IAAMC,OAAc,GAAG,EAAE;IAAA,sCACS;MAChC,IACEX,OAAO,CAACb,MAAM,KAAK,CAAC,IACpBa,OAAO,CAACY,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,aAAa,CAACtB,QAAQ,CAACA,QAAQ,CAAC,KAAK,CAAC,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/esm/nodeUtils.js
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
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;
|
|
7
|
+
var fs = _interopRequireWildcard(require("fs"));
|
|
8
|
+
var _child_process = require("child_process");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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); }
|
|
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; }
|
|
5
14
|
var utf8 = 'utf-8';
|
|
6
|
-
|
|
15
|
+
var utf8Encoding = {
|
|
7
16
|
encoding: utf8
|
|
8
17
|
};
|
|
9
|
-
|
|
18
|
+
exports.utf8Encoding = utf8Encoding;
|
|
19
|
+
var readFileSync = function readFileSync(filePath) {
|
|
10
20
|
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : utf8;
|
|
11
21
|
return fs.readFileSync(filePath, {
|
|
12
22
|
encoding: encoding
|
|
13
23
|
});
|
|
14
24
|
};
|
|
15
|
-
|
|
25
|
+
exports.readFileSync = readFileSync;
|
|
26
|
+
var writeFileSync = function writeFileSync(filePath, data) {
|
|
16
27
|
var encoding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : utf8;
|
|
17
28
|
return fs.writeFileSync(filePath, data, {
|
|
18
29
|
encoding: encoding
|
|
19
30
|
});
|
|
20
31
|
};
|
|
21
|
-
|
|
32
|
+
exports.writeFileSync = writeFileSync;
|
|
33
|
+
var isDirSync = filePath => {
|
|
22
34
|
try {
|
|
23
35
|
return fs.statSync(filePath).isDirectory();
|
|
24
36
|
} catch (e) {
|
|
@@ -29,15 +41,18 @@ export var isDirSync = filePath => {
|
|
|
29
41
|
}
|
|
30
42
|
}
|
|
31
43
|
};
|
|
44
|
+
exports.isDirSync = isDirSync;
|
|
32
45
|
var homeToRoost = '../../../';
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
var getRootPath = () => _path.default.join(__dirname, homeToRoost);
|
|
47
|
+
exports.getRootPath = getRootPath;
|
|
48
|
+
var rootFile = function rootFile() {
|
|
35
49
|
var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
36
|
-
return
|
|
50
|
+
return _path.default.join(getRootPath(), fileName);
|
|
37
51
|
};
|
|
38
|
-
|
|
52
|
+
exports.rootFile = rootFile;
|
|
53
|
+
var createJsonFile = (fileName, content) => {
|
|
39
54
|
var fullName = rootFile(fileName);
|
|
40
|
-
var dir =
|
|
55
|
+
var dir = _path.default.dirname(fullName);
|
|
41
56
|
var data = typeof content === 'string' ? content : JSON.stringify(content);
|
|
42
57
|
if (!isDirSync(dir)) fs.mkdirSync(dir, {
|
|
43
58
|
recursive: true
|
|
@@ -45,7 +60,8 @@ export var createJsonFile = (fileName, content) => {
|
|
|
45
60
|
fs.writeFileSync(fullName, data, utf8Encoding);
|
|
46
61
|
return fullName;
|
|
47
62
|
};
|
|
48
|
-
|
|
63
|
+
exports.createJsonFile = createJsonFile;
|
|
64
|
+
var isFileSync = filePath => {
|
|
49
65
|
try {
|
|
50
66
|
return fs.statSync(filePath).isFile();
|
|
51
67
|
} catch (e) {
|
|
@@ -56,29 +72,30 @@ export var isFileSync = filePath => {
|
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
};
|
|
59
|
-
|
|
75
|
+
exports.isFileSync = isFileSync;
|
|
76
|
+
var quit = err => {
|
|
60
77
|
if (err) {
|
|
61
78
|
if (typeof err === 'string') {
|
|
62
79
|
var message = err;
|
|
63
80
|
err = new Error('Failure');
|
|
64
81
|
err.message = message;
|
|
65
82
|
}
|
|
66
|
-
|
|
67
83
|
console.error("Error: ".concat(err.name, ", ").concat(err.message));
|
|
68
84
|
console.error(err.stack);
|
|
69
85
|
process.exit(1);
|
|
70
86
|
} else {
|
|
71
87
|
process.exit(0);
|
|
72
88
|
}
|
|
73
|
-
|
|
74
89
|
return '';
|
|
75
90
|
};
|
|
76
|
-
|
|
91
|
+
exports.quit = quit;
|
|
92
|
+
var fail = (name, message) => {
|
|
77
93
|
var err = new Error(message);
|
|
78
94
|
err.name = name;
|
|
79
95
|
return quit(err);
|
|
80
96
|
};
|
|
81
|
-
|
|
97
|
+
exports.fail = fail;
|
|
98
|
+
var run = function run(command, args, errMsg) {
|
|
82
99
|
var warning = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
83
100
|
var options = {
|
|
84
101
|
encoding: 'utf8',
|
|
@@ -86,17 +103,17 @@ export var run = function run(command, args, errMsg) {
|
|
|
86
103
|
timeout: 300 * 1000,
|
|
87
104
|
windowsHide: true
|
|
88
105
|
};
|
|
89
|
-
|
|
90
106
|
try {
|
|
91
107
|
command += ' ' + args.join(' ');
|
|
92
|
-
return execSync(command, options);
|
|
108
|
+
return (0, _child_process.execSync)(command, options);
|
|
93
109
|
} catch (e) {
|
|
94
110
|
if (warning) {
|
|
95
|
-
warn("".concat(errMsg, ": ").concat(e.message));
|
|
111
|
+
(0, _sdkCodegenUtils.warn)("".concat(errMsg, ": ").concat(e.message));
|
|
96
112
|
return '';
|
|
97
113
|
} else {
|
|
98
114
|
return quit(errMsg || e);
|
|
99
115
|
}
|
|
100
116
|
}
|
|
101
117
|
};
|
|
118
|
+
exports.run = run;
|
|
102
119
|
//# sourceMappingURL=nodeUtils.js.map
|
package/lib/esm/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,OAC5BK,EAAE,CAACF,YAAY,CAACC,QAAQ,EAAE;IAAEF,QAAQ,EAAEA;EAAS,CAAC,CAAC;AAAA;AAAA;AAE/C,IAAMI,aAAa,GAAG,SAAhBA,aAAa,CACxBF,QAAgB,EAChBG,IAAS;EAAA,IACTL,QAAwB,uEAAGF,IAAI;EAAA,OAC5BK,EAAE,CAACC,aAAa,CAACF,QAAQ,EAAEG,IAAI,EAAE;IAAEL,QAAQ,EAAEA;EAAS,CAAC,CAAC;AAAA;AAAA;AAEtD,IAAMM,SAAS,GAAIJ,QAAgB,IAAK;EAC7C,IAAI;IACF,OAAOC,EAAE,CAACI,QAAQ,CAACL,QAAQ,CAAC,CAACM,WAAW,EAAE;EAC5C,CAAC,CAAC,OAAOC,CAAM,EAAE;IACf,IAAIA,CAAC,CAACC,IAAI,KAAK,QAAQ,EAAE;MACvB,OAAO,KAAK;IACd,CAAC,MAAM;MACL,MAAMD,CAAC;IACT;EACF;AACF,CAAC;AAAA;AAED,IAAME,WAAW,GAAG,WAAW;AAExB,IAAMC,WAAW,GAAG,MAAMC,aAAI,CAACC,IAAI,CAACC,SAAS,EAAEJ,WAAW,CAAC;AAAA;AAC3D,IAAMK,QAAQ,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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prettify = void 0;
|
|
7
|
+
var prettier = _interopRequireWildcard(require("prettier"));
|
|
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); }
|
|
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; }
|
|
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); }
|
|
8
15
|
var prettierTs = {
|
|
9
16
|
bracketSpacing: true,
|
|
10
17
|
endOfLine: 'auto',
|
|
@@ -16,13 +23,12 @@ var prettierTs = {
|
|
|
16
23
|
trailingComma: 'es5',
|
|
17
24
|
arrowParens: 'always'
|
|
18
25
|
};
|
|
19
|
-
|
|
26
|
+
var prettify = function prettify(code) {
|
|
20
27
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
21
|
-
|
|
22
28
|
var merged = _objectSpread(_objectSpread({}, prettierTs), {
|
|
23
29
|
options
|
|
24
30
|
});
|
|
25
|
-
|
|
26
31
|
return prettier.format(code, merged);
|
|
27
32
|
};
|
|
33
|
+
exports.prettify = prettify;
|
|
28
34
|
//# sourceMappingURL=prettify.js.map
|
package/lib/esm/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"}
|