@vitus-labs/tools-core 0.27.0 → 0.28.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/.babelrc.js +1 -0
- package/lib/analysis/vitus-tools-core.js.html +6444 -0
- package/lib/analysis/vitus-tools-core.module.js.html +6444 -0
- package/lib/index.d.ts +14 -0
- package/lib/types/index.d.ts +13 -0
- package/lib/vitus-tools-core.js +132 -0
- package/lib/vitus-tools-core.js.map +1 -0
- package/lib/vitus-tools-core.module.js +116 -0
- package/lib/vitus-tools-core.module.js.map +1 -0
- package/package.json +20 -6
- package/{index.js → src/index.ts} +48 -27
- package/tsconfig.json +23 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const findFile: (filename: string) => string | undefined;
|
|
2
|
+
declare const loadFileToJSON: (filename: string) => any;
|
|
3
|
+
declare const loadConfigParam: (filename: string) => (key: string, defaultValue?: {}) => any;
|
|
4
|
+
declare const loadVLToolsConfig: (key: string) => {
|
|
5
|
+
readonly config: any;
|
|
6
|
+
get: (param: string, defaultValue?: any) => any;
|
|
7
|
+
merge: (param: Record<string, any>) => any;
|
|
8
|
+
};
|
|
9
|
+
declare const swapGlobals: (globals: Record<string, string>) => {};
|
|
10
|
+
declare const PKG: any;
|
|
11
|
+
declare const CONFIG: any;
|
|
12
|
+
declare const TS_CONFIG: any;
|
|
13
|
+
|
|
14
|
+
export { CONFIG, PKG, TS_CONFIG, findFile, loadConfigParam, loadFileToJSON, loadVLToolsConfig, swapGlobals };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const findFile: (filename: string) => string | undefined;
|
|
2
|
+
declare const loadFileToJSON: (filename: string) => any;
|
|
3
|
+
declare const loadConfigParam: (filename: string) => (key: string, defaultValue?: {}) => any;
|
|
4
|
+
declare const loadVLToolsConfig: (key: string) => {
|
|
5
|
+
readonly config: any;
|
|
6
|
+
get: (param: string, defaultValue?: any) => any;
|
|
7
|
+
merge: (param: Record<string, any>) => any;
|
|
8
|
+
};
|
|
9
|
+
declare const swapGlobals: (globals: Record<string, string>) => {};
|
|
10
|
+
declare const PKG: any;
|
|
11
|
+
declare const CONFIG: any;
|
|
12
|
+
declare const TS_CONFIG: any;
|
|
13
|
+
export { findFile, loadConfigParam, loadFileToJSON, loadVLToolsConfig, swapGlobals, PKG, CONFIG, TS_CONFIG, };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var findUp = require('find-up');
|
|
7
|
+
var lodash = require('lodash');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
12
|
+
var findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
|
|
13
|
+
|
|
14
|
+
// --------------------------------------------------------
|
|
15
|
+
// FIND & READ file helpers
|
|
16
|
+
// --------------------------------------------------------
|
|
17
|
+
const findFile = (filename) => findUp__default["default"].sync(filename, { type: 'file' });
|
|
18
|
+
const loadFileToJSON = (filename) => {
|
|
19
|
+
const file = findFile(filename);
|
|
20
|
+
if (!file)
|
|
21
|
+
return {};
|
|
22
|
+
let data;
|
|
23
|
+
// try to read an exported module first
|
|
24
|
+
try {
|
|
25
|
+
data = require(file);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// ignore eror
|
|
29
|
+
}
|
|
30
|
+
// try to read a plain json file like tsconfig.json
|
|
31
|
+
if (!data) {
|
|
32
|
+
try {
|
|
33
|
+
data = JSON.parse(fs__default["default"].readFileSync(file, 'utf-8'));
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
// ignore error
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
};
|
|
41
|
+
// --------------------------------------------------------
|
|
42
|
+
// GET PACKAGE.JSON info
|
|
43
|
+
// --------------------------------------------------------
|
|
44
|
+
const getPackageJSON = () => {
|
|
45
|
+
const data = loadFileToJSON('package.json');
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
// --------------------------------------------------------
|
|
49
|
+
// PACKAGE.json parsing functions
|
|
50
|
+
// --------------------------------------------------------
|
|
51
|
+
// GET LIST OF DEPENDENCIES from package.json
|
|
52
|
+
const getDependenciesList = (types) => {
|
|
53
|
+
const pkg = getPackageJSON();
|
|
54
|
+
let result = [];
|
|
55
|
+
types.forEach((item) => {
|
|
56
|
+
const data = pkg[item];
|
|
57
|
+
result = [...result, ...Object.keys(data || {})];
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
// parse namespace name
|
|
62
|
+
// const parseNamespace = (name) =>
|
|
63
|
+
// name.startsWith('@') ? name.split('/')[0] : ''
|
|
64
|
+
// converts package name to umd or iife valid format
|
|
65
|
+
// example: napespace-package-name => namespacePackageName
|
|
66
|
+
const camelspaceBundleName = (name) => {
|
|
67
|
+
const parsedName = name.replace('@', '').replace('/', '-');
|
|
68
|
+
const arrayStringsCamel = (arr) => arr.map((item, i) => i === 0
|
|
69
|
+
? item
|
|
70
|
+
: item.charAt(0).toUpperCase() + item.substr(1).toLowerCase());
|
|
71
|
+
const arr = parsedName.split('-');
|
|
72
|
+
const result = arrayStringsCamel(arr).join('');
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
// --------------------------------------------------------
|
|
76
|
+
// PACKAGE JSON DATA
|
|
77
|
+
// --------------------------------------------------------
|
|
78
|
+
const getPkgData = () => {
|
|
79
|
+
const pkg = getPackageJSON();
|
|
80
|
+
const { name } = pkg;
|
|
81
|
+
// const namespace = parseNamespace(name)
|
|
82
|
+
return {
|
|
83
|
+
...pkg,
|
|
84
|
+
// nameWithoutPrefix: name.replace(namespace, '').replace('/', ''),
|
|
85
|
+
// namespace,
|
|
86
|
+
// namespaceName: namespace.replace('@', ''),
|
|
87
|
+
// rootPath: findFilePath('package.json'),
|
|
88
|
+
bundleName: camelspaceBundleName(name),
|
|
89
|
+
externalDependencies: getDependenciesList([
|
|
90
|
+
'dependencies',
|
|
91
|
+
'peerDependencies',
|
|
92
|
+
]),
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
// --------------------------------------------------------
|
|
96
|
+
// LOAD EXTERNAL CONFIGURATION
|
|
97
|
+
// --------------------------------------------------------
|
|
98
|
+
const getExternalConfig = () => loadFileToJSON('vl-tools.config.js');
|
|
99
|
+
const loadConfigParam = (filename) => (key, defaultValue = {}) => {
|
|
100
|
+
const externalConfig = loadFileToJSON(filename);
|
|
101
|
+
return lodash.get(externalConfig, key, defaultValue);
|
|
102
|
+
};
|
|
103
|
+
const loadVLToolsConfig = (key) => {
|
|
104
|
+
const externalConfig = getExternalConfig();
|
|
105
|
+
const result = lodash.get(externalConfig, key);
|
|
106
|
+
const cloneAndEnhance = (config) => ({
|
|
107
|
+
get config() {
|
|
108
|
+
return config;
|
|
109
|
+
},
|
|
110
|
+
get: (param, defaultValue) => lodash.get(config, param, defaultValue),
|
|
111
|
+
merge: (param) => cloneAndEnhance(lodash.merge(param, config)),
|
|
112
|
+
});
|
|
113
|
+
return cloneAndEnhance(result);
|
|
114
|
+
};
|
|
115
|
+
const swapGlobals = (globals) => Object.entries(globals).reduce((acc, [key, value]) => {
|
|
116
|
+
// eslint-disable-next-line no-param-reassign
|
|
117
|
+
acc[value] = key;
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
const PKG = getPkgData();
|
|
121
|
+
const CONFIG = getExternalConfig();
|
|
122
|
+
const TS_CONFIG = loadFileToJSON('tsconfig.json');
|
|
123
|
+
|
|
124
|
+
exports.CONFIG = CONFIG;
|
|
125
|
+
exports.PKG = PKG;
|
|
126
|
+
exports.TS_CONFIG = TS_CONFIG;
|
|
127
|
+
exports.findFile = findFile;
|
|
128
|
+
exports.loadConfigParam = loadConfigParam;
|
|
129
|
+
exports.loadFileToJSON = loadFileToJSON;
|
|
130
|
+
exports.loadVLToolsConfig = loadVLToolsConfig;
|
|
131
|
+
exports.swapGlobals = swapGlobals;
|
|
132
|
+
//# sourceMappingURL=vitus-tools-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-tools-core.js","sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs'\nimport findUp from 'find-up'\nimport { get, merge } from 'lodash'\n\n// --------------------------------------------------------\n// FIND & READ file helpers\n// --------------------------------------------------------\nconst findFile = (filename: string) => findUp.sync(filename, { type: 'file' })\n\nconst loadFileToJSON = (filename: string) => {\n const file = findFile(filename)\n\n if (!file) return {}\n\n let data\n\n // try to read an exported module first\n try {\n data = require(file)\n } catch (e) {\n // ignore eror\n }\n\n // try to read a plain json file like tsconfig.json\n if (!data) {\n try {\n data = JSON.parse(fs.readFileSync(file, 'utf-8'))\n } catch (e) {\n // ignore error\n }\n }\n\n return data\n}\n\n// --------------------------------------------------------\n// GET PACKAGE.JSON info\n// --------------------------------------------------------\nconst getPackageJSON = () => {\n const data = loadFileToJSON('package.json')\n\n return data\n}\n\n// --------------------------------------------------------\n// PACKAGE.json parsing functions\n// --------------------------------------------------------\n\n// GET LIST OF DEPENDENCIES from package.json\nconst getDependenciesList = (types: any) => {\n const pkg = getPackageJSON()\n let result: any = []\n\n types.forEach((item: any) => {\n const data = pkg[item]\n result = [...result, ...Object.keys(data || {})]\n })\n\n return result\n}\n\n// parse namespace name\n// const parseNamespace = (name) =>\n// name.startsWith('@') ? name.split('/')[0] : ''\n\n// converts package name to umd or iife valid format\n// example: napespace-package-name => namespacePackageName\nconst camelspaceBundleName = (name: string) => {\n const parsedName = name.replace('@', '').replace('/', '-')\n const arrayStringsCamel = (arr: any) =>\n arr.map((item: any, i: any) =>\n i === 0\n ? item\n : item.charAt(0).toUpperCase() + item.substr(1).toLowerCase()\n )\n const arr = parsedName.split('-')\n const result = arrayStringsCamel(arr).join('')\n\n return result\n}\n\n// --------------------------------------------------------\n// PACKAGE JSON DATA\n// --------------------------------------------------------\nconst getPkgData = () => {\n const pkg = getPackageJSON()\n const { name } = pkg\n // const namespace = parseNamespace(name)\n\n return {\n ...pkg,\n // nameWithoutPrefix: name.replace(namespace, '').replace('/', ''),\n // namespace,\n // namespaceName: namespace.replace('@', ''),\n // rootPath: findFilePath('package.json'),\n bundleName: camelspaceBundleName(name),\n externalDependencies: getDependenciesList([\n 'dependencies',\n 'peerDependencies',\n ]),\n }\n}\n\n// --------------------------------------------------------\n// LOAD EXTERNAL CONFIGURATION\n// --------------------------------------------------------\nconst getExternalConfig = () => loadFileToJSON('vl-tools.config.js')\n\nconst loadConfigParam =\n (filename: string) =>\n (key: string, defaultValue = {}) => {\n const externalConfig = loadFileToJSON(filename)\n\n return get(externalConfig, key, defaultValue)\n }\n\nconst loadVLToolsConfig = (key: string) => {\n const externalConfig = getExternalConfig()\n const result = get(externalConfig, key)\n\n const cloneAndEnhance = (config) => ({\n get config() {\n return config\n },\n get: (param: string, defaultValue?: any) =>\n get(config, param, defaultValue),\n merge: (param: Record<string, any>) =>\n cloneAndEnhance(merge(param, config)),\n })\n\n return cloneAndEnhance(result)\n}\n\nconst swapGlobals = (globals: Record<string, string>) =>\n Object.entries(globals).reduce((acc, [key, value]) => {\n // eslint-disable-next-line no-param-reassign\n acc[value] = key\n return acc\n }, {})\n\nconst PKG = getPkgData()\nconst CONFIG = getExternalConfig()\nconst TS_CONFIG = loadFileToJSON('tsconfig.json')\n\nexport {\n findFile,\n loadConfigParam,\n loadFileToJSON,\n loadVLToolsConfig,\n swapGlobals,\n PKG,\n CONFIG,\n TS_CONFIG,\n}\n"],"names":["findUp","fs","get","merge"],"mappings":";;;;;;;;;;;;;AAIA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,CAAC,QAAgB,KAAKA,0BAAM,CAAC,IAAI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CAAA;IAE/C,OAAOC,UAAG,CAAC,cAAc,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;AAC/C,EAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;AACxC,IAAA,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAA;IAC1C,MAAM,MAAM,GAAGA,UAAG,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;AAEvC,IAAA,MAAM,eAAe,GAAG,CAAC,MAAM,MAAM;AACnC,QAAA,IAAI,MAAM,GAAA;AACR,YAAA,OAAO,MAAM,CAAA;SACd;AACD,QAAA,GAAG,EAAE,CAAC,KAAa,EAAE,YAAkB,KACrCA,UAAG,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC;AAClC,QAAA,KAAK,EAAE,CAAC,KAA0B,KAChC,eAAe,CAACC,YAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACxC,KAAA,CAAC,CAAA;AAEF,IAAA,OAAO,eAAe,CAAC,MAAM,CAAC,CAAA;AAChC,EAAC;AAEK,MAAA,WAAW,GAAG,CAAC,OAA+B,KAClD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;;AAEnD,IAAA,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA;AAChB,IAAA,OAAO,GAAG,CAAA;AACZ,CAAC,EAAE,EAAE,EAAC;AAER,MAAM,GAAG,GAAG,UAAU,GAAE;AACxB,MAAM,MAAM,GAAG,iBAAiB,GAAE;AAClC,MAAM,SAAS,GAAG,cAAc,CAAC,eAAe;;;;;;;;;;;"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import findUp from 'find-up';
|
|
3
|
+
import { get, merge } from 'lodash';
|
|
4
|
+
|
|
5
|
+
// --------------------------------------------------------
|
|
6
|
+
// FIND & READ file helpers
|
|
7
|
+
// --------------------------------------------------------
|
|
8
|
+
const findFile = (filename) => findUp.sync(filename, { type: 'file' });
|
|
9
|
+
const loadFileToJSON = (filename) => {
|
|
10
|
+
const file = findFile(filename);
|
|
11
|
+
if (!file)
|
|
12
|
+
return {};
|
|
13
|
+
let data;
|
|
14
|
+
// try to read an exported module first
|
|
15
|
+
try {
|
|
16
|
+
data = require(file);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
// ignore eror
|
|
20
|
+
}
|
|
21
|
+
// try to read a plain json file like tsconfig.json
|
|
22
|
+
if (!data) {
|
|
23
|
+
try {
|
|
24
|
+
data = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// ignore error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
// --------------------------------------------------------
|
|
33
|
+
// GET PACKAGE.JSON info
|
|
34
|
+
// --------------------------------------------------------
|
|
35
|
+
const getPackageJSON = () => {
|
|
36
|
+
const data = loadFileToJSON('package.json');
|
|
37
|
+
return data;
|
|
38
|
+
};
|
|
39
|
+
// --------------------------------------------------------
|
|
40
|
+
// PACKAGE.json parsing functions
|
|
41
|
+
// --------------------------------------------------------
|
|
42
|
+
// GET LIST OF DEPENDENCIES from package.json
|
|
43
|
+
const getDependenciesList = (types) => {
|
|
44
|
+
const pkg = getPackageJSON();
|
|
45
|
+
let result = [];
|
|
46
|
+
types.forEach((item) => {
|
|
47
|
+
const data = pkg[item];
|
|
48
|
+
result = [...result, ...Object.keys(data || {})];
|
|
49
|
+
});
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
// parse namespace name
|
|
53
|
+
// const parseNamespace = (name) =>
|
|
54
|
+
// name.startsWith('@') ? name.split('/')[0] : ''
|
|
55
|
+
// converts package name to umd or iife valid format
|
|
56
|
+
// example: napespace-package-name => namespacePackageName
|
|
57
|
+
const camelspaceBundleName = (name) => {
|
|
58
|
+
const parsedName = name.replace('@', '').replace('/', '-');
|
|
59
|
+
const arrayStringsCamel = (arr) => arr.map((item, i) => i === 0
|
|
60
|
+
? item
|
|
61
|
+
: item.charAt(0).toUpperCase() + item.substr(1).toLowerCase());
|
|
62
|
+
const arr = parsedName.split('-');
|
|
63
|
+
const result = arrayStringsCamel(arr).join('');
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
// --------------------------------------------------------
|
|
67
|
+
// PACKAGE JSON DATA
|
|
68
|
+
// --------------------------------------------------------
|
|
69
|
+
const getPkgData = () => {
|
|
70
|
+
const pkg = getPackageJSON();
|
|
71
|
+
const { name } = pkg;
|
|
72
|
+
// const namespace = parseNamespace(name)
|
|
73
|
+
return {
|
|
74
|
+
...pkg,
|
|
75
|
+
// nameWithoutPrefix: name.replace(namespace, '').replace('/', ''),
|
|
76
|
+
// namespace,
|
|
77
|
+
// namespaceName: namespace.replace('@', ''),
|
|
78
|
+
// rootPath: findFilePath('package.json'),
|
|
79
|
+
bundleName: camelspaceBundleName(name),
|
|
80
|
+
externalDependencies: getDependenciesList([
|
|
81
|
+
'dependencies',
|
|
82
|
+
'peerDependencies',
|
|
83
|
+
]),
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
// --------------------------------------------------------
|
|
87
|
+
// LOAD EXTERNAL CONFIGURATION
|
|
88
|
+
// --------------------------------------------------------
|
|
89
|
+
const getExternalConfig = () => loadFileToJSON('vl-tools.config.js');
|
|
90
|
+
const loadConfigParam = (filename) => (key, defaultValue = {}) => {
|
|
91
|
+
const externalConfig = loadFileToJSON(filename);
|
|
92
|
+
return get(externalConfig, key, defaultValue);
|
|
93
|
+
};
|
|
94
|
+
const loadVLToolsConfig = (key) => {
|
|
95
|
+
const externalConfig = getExternalConfig();
|
|
96
|
+
const result = get(externalConfig, key);
|
|
97
|
+
const cloneAndEnhance = (config) => ({
|
|
98
|
+
get config() {
|
|
99
|
+
return config;
|
|
100
|
+
},
|
|
101
|
+
get: (param, defaultValue) => get(config, param, defaultValue),
|
|
102
|
+
merge: (param) => cloneAndEnhance(merge(param, config)),
|
|
103
|
+
});
|
|
104
|
+
return cloneAndEnhance(result);
|
|
105
|
+
};
|
|
106
|
+
const swapGlobals = (globals) => Object.entries(globals).reduce((acc, [key, value]) => {
|
|
107
|
+
// eslint-disable-next-line no-param-reassign
|
|
108
|
+
acc[value] = key;
|
|
109
|
+
return acc;
|
|
110
|
+
}, {});
|
|
111
|
+
const PKG = getPkgData();
|
|
112
|
+
const CONFIG = getExternalConfig();
|
|
113
|
+
const TS_CONFIG = loadFileToJSON('tsconfig.json');
|
|
114
|
+
|
|
115
|
+
export { CONFIG, PKG, TS_CONFIG, findFile, loadConfigParam, loadFileToJSON, loadVLToolsConfig, swapGlobals };
|
|
116
|
+
//# sourceMappingURL=vitus-tools-core.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-tools-core.module.js","sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs'\nimport findUp from 'find-up'\nimport { get, merge } from 'lodash'\n\n// --------------------------------------------------------\n// FIND & READ file helpers\n// --------------------------------------------------------\nconst findFile = (filename: string) => findUp.sync(filename, { type: 'file' })\n\nconst loadFileToJSON = (filename: string) => {\n const file = findFile(filename)\n\n if (!file) return {}\n\n let data\n\n // try to read an exported module first\n try {\n data = require(file)\n } catch (e) {\n // ignore eror\n }\n\n // try to read a plain json file like tsconfig.json\n if (!data) {\n try {\n data = JSON.parse(fs.readFileSync(file, 'utf-8'))\n } catch (e) {\n // ignore error\n }\n }\n\n return data\n}\n\n// --------------------------------------------------------\n// GET PACKAGE.JSON info\n// --------------------------------------------------------\nconst getPackageJSON = () => {\n const data = loadFileToJSON('package.json')\n\n return data\n}\n\n// --------------------------------------------------------\n// PACKAGE.json parsing functions\n// --------------------------------------------------------\n\n// GET LIST OF DEPENDENCIES from package.json\nconst getDependenciesList = (types: any) => {\n const pkg = getPackageJSON()\n let result: any = []\n\n types.forEach((item: any) => {\n const data = pkg[item]\n result = [...result, ...Object.keys(data || {})]\n })\n\n return result\n}\n\n// parse namespace name\n// const parseNamespace = (name) =>\n// name.startsWith('@') ? name.split('/')[0] : ''\n\n// converts package name to umd or iife valid format\n// example: napespace-package-name => namespacePackageName\nconst camelspaceBundleName = (name: string) => {\n const parsedName = name.replace('@', '').replace('/', '-')\n const arrayStringsCamel = (arr: any) =>\n arr.map((item: any, i: any) =>\n i === 0\n ? item\n : item.charAt(0).toUpperCase() + item.substr(1).toLowerCase()\n )\n const arr = parsedName.split('-')\n const result = arrayStringsCamel(arr).join('')\n\n return result\n}\n\n// --------------------------------------------------------\n// PACKAGE JSON DATA\n// --------------------------------------------------------\nconst getPkgData = () => {\n const pkg = getPackageJSON()\n const { name } = pkg\n // const namespace = parseNamespace(name)\n\n return {\n ...pkg,\n // nameWithoutPrefix: name.replace(namespace, '').replace('/', ''),\n // namespace,\n // namespaceName: namespace.replace('@', ''),\n // rootPath: findFilePath('package.json'),\n bundleName: camelspaceBundleName(name),\n externalDependencies: getDependenciesList([\n 'dependencies',\n 'peerDependencies',\n ]),\n }\n}\n\n// --------------------------------------------------------\n// LOAD EXTERNAL CONFIGURATION\n// --------------------------------------------------------\nconst getExternalConfig = () => loadFileToJSON('vl-tools.config.js')\n\nconst loadConfigParam =\n (filename: string) =>\n (key: string, defaultValue = {}) => {\n const externalConfig = loadFileToJSON(filename)\n\n return get(externalConfig, key, defaultValue)\n }\n\nconst loadVLToolsConfig = (key: string) => {\n const externalConfig = getExternalConfig()\n const result = get(externalConfig, key)\n\n const cloneAndEnhance = (config) => ({\n get config() {\n return config\n },\n get: (param: string, defaultValue?: any) =>\n get(config, param, defaultValue),\n merge: (param: Record<string, any>) =>\n cloneAndEnhance(merge(param, config)),\n })\n\n return cloneAndEnhance(result)\n}\n\nconst swapGlobals = (globals: Record<string, string>) =>\n Object.entries(globals).reduce((acc, [key, value]) => {\n // eslint-disable-next-line no-param-reassign\n acc[value] = key\n return acc\n }, {})\n\nconst PKG = getPkgData()\nconst CONFIG = getExternalConfig()\nconst TS_CONFIG = loadFileToJSON('tsconfig.json')\n\nexport {\n findFile,\n loadConfigParam,\n loadFileToJSON,\n loadVLToolsConfig,\n swapGlobals,\n PKG,\n CONFIG,\n TS_CONFIG,\n}\n"],"names":[],"mappings":";;;;AAIA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,CAAC,QAAgB,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAC;AAE9E,MAAM,cAAc,GAAG,CAAC,QAAgB,KAAI;AAC1C,IAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAE/B,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,EAAE,CAAA;AAEpB,IAAA,IAAI,IAAI,CAAA;;IAGR,IAAI;AACF,QAAA,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACrB,KAAA;AAAC,IAAA,OAAO,CAAC,EAAE;;AAEX,KAAA;;IAGD,IAAI,CAAC,IAAI,EAAE;QACT,IAAI;AACF,YAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;AAClD,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;;AAEX,SAAA;AACF,KAAA;AAED,IAAA,OAAO,IAAI,CAAA;AACb,EAAC;AAED;AACA;AACA;AACA,MAAM,cAAc,GAAG,MAAK;AAC1B,IAAA,MAAM,IAAI,GAAG,cAAc,CAAC,cAAc,CAAC,CAAA;AAE3C,IAAA,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;AACA;AACA;AAEA;AACA,MAAM,mBAAmB,GAAG,CAAC,KAAU,KAAI;AACzC,IAAA,MAAM,GAAG,GAAG,cAAc,EAAE,CAAA;IAC5B,IAAI,MAAM,GAAQ,EAAE,CAAA;AAEpB,IAAA,KAAK,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AM,MAAM,GAAG,iBAAiB,GAAE;AAClC,MAAM,SAAS,GAAG,cAAc,CAAC,eAAe;;;;"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.com>",
|
|
6
6
|
"maintainers": [
|
|
7
7
|
"Vit Bokisch <vit@bokisch.com>"
|
|
8
8
|
],
|
|
9
|
-
"main": "
|
|
9
|
+
"main": "lib/vitus-tools-core.js",
|
|
10
|
+
"module": "lib/vitus-tools-core.module.js",
|
|
11
|
+
"types": "lib/index.d.ts",
|
|
10
12
|
"publishConfig": {
|
|
11
13
|
"access": "public"
|
|
12
14
|
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"prepublish": "yarn build",
|
|
17
|
+
"build": "yarn vl_build",
|
|
18
|
+
"build:watch": "yarn vl_build-watch",
|
|
19
|
+
"lint:ts": "eslint src/*",
|
|
20
|
+
"lint": "yarn lint:ts"
|
|
21
|
+
},
|
|
13
22
|
"dependencies": {
|
|
14
|
-
"find-up": "
|
|
15
|
-
"lodash
|
|
16
|
-
|
|
23
|
+
"find-up": "5.0.0",
|
|
24
|
+
"lodash": "^4.17.21"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@vitus-labs/tools-babel": "0.28.0",
|
|
28
|
+
"@vitus-labs/tools-core": "0.28.0",
|
|
29
|
+
"@vitus-labs/tools-rollup": "0.28.0",
|
|
30
|
+
"@vitus-labs/tools-typescript": "0.28.0"
|
|
17
31
|
},
|
|
18
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "ea44ed3cff22c88f4c00e56d679db9e64a29639c"
|
|
19
33
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const merge = require('lodash.merge')
|
|
5
|
-
const get = require('lodash.get')
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import findUp from 'find-up'
|
|
3
|
+
import { get, merge } from 'lodash'
|
|
6
4
|
|
|
7
5
|
// --------------------------------------------------------
|
|
8
6
|
// FIND & READ file helpers
|
|
9
7
|
// --------------------------------------------------------
|
|
10
|
-
const findFile = (filename) => findUp.sync(filename, { type: 'file' })
|
|
8
|
+
const findFile = (filename: string) => findUp.sync(filename, { type: 'file' })
|
|
11
9
|
|
|
12
|
-
const loadFileToJSON = (filename) => {
|
|
10
|
+
const loadFileToJSON = (filename: string) => {
|
|
13
11
|
const file = findFile(filename)
|
|
14
12
|
|
|
15
13
|
if (!file) return {}
|
|
@@ -49,11 +47,11 @@ const getPackageJSON = () => {
|
|
|
49
47
|
// --------------------------------------------------------
|
|
50
48
|
|
|
51
49
|
// GET LIST OF DEPENDENCIES from package.json
|
|
52
|
-
const getDependenciesList = (types) => {
|
|
50
|
+
const getDependenciesList = (types: any) => {
|
|
53
51
|
const pkg = getPackageJSON()
|
|
54
|
-
let result = []
|
|
52
|
+
let result: any = []
|
|
55
53
|
|
|
56
|
-
types.forEach((item) => {
|
|
54
|
+
types.forEach((item: any) => {
|
|
57
55
|
const data = pkg[item]
|
|
58
56
|
result = [...result, ...Object.keys(data || {})]
|
|
59
57
|
})
|
|
@@ -67,10 +65,10 @@ const getDependenciesList = (types) => {
|
|
|
67
65
|
|
|
68
66
|
// converts package name to umd or iife valid format
|
|
69
67
|
// example: napespace-package-name => namespacePackageName
|
|
70
|
-
const camelspaceBundleName = (name) => {
|
|
68
|
+
const camelspaceBundleName = (name: string) => {
|
|
71
69
|
const parsedName = name.replace('@', '').replace('/', '-')
|
|
72
|
-
const arrayStringsCamel = (arr) =>
|
|
73
|
-
arr.map((item, i) =>
|
|
70
|
+
const arrayStringsCamel = (arr: any) =>
|
|
71
|
+
arr.map((item: any, i: any) =>
|
|
74
72
|
i === 0
|
|
75
73
|
? item
|
|
76
74
|
: item.charAt(0).toUpperCase() + item.substr(1).toLowerCase()
|
|
@@ -108,26 +106,49 @@ const getPkgData = () => {
|
|
|
108
106
|
// --------------------------------------------------------
|
|
109
107
|
const getExternalConfig = () => loadFileToJSON('vl-tools.config.js')
|
|
110
108
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
109
|
+
const loadConfigParam =
|
|
110
|
+
(filename: string) =>
|
|
111
|
+
(key: string, defaultValue = {}) => {
|
|
112
|
+
const externalConfig = loadFileToJSON(filename)
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
return get(externalConfig, key, defaultValue)
|
|
115
|
+
}
|
|
119
116
|
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
const loadVLToolsConfig = (key: string) => {
|
|
118
|
+
const externalConfig = getExternalConfig()
|
|
119
|
+
const result = get(externalConfig, key)
|
|
120
|
+
|
|
121
|
+
const cloneAndEnhance = (config) => ({
|
|
122
|
+
get config() {
|
|
123
|
+
return config
|
|
124
|
+
},
|
|
125
|
+
get: (param: string, defaultValue?: any) =>
|
|
126
|
+
get(config, param, defaultValue),
|
|
127
|
+
merge: (param: Record<string, any>) =>
|
|
128
|
+
cloneAndEnhance(merge(param, config)),
|
|
122
129
|
})
|
|
123
130
|
|
|
124
|
-
return result
|
|
131
|
+
return cloneAndEnhance(result)
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
const swapGlobals = (globals: Record<string, string>) =>
|
|
135
|
+
Object.entries(globals).reduce((acc, [key, value]) => {
|
|
136
|
+
// eslint-disable-next-line no-param-reassign
|
|
137
|
+
acc[value] = key
|
|
138
|
+
return acc
|
|
139
|
+
}, {})
|
|
140
|
+
|
|
141
|
+
const PKG = getPkgData()
|
|
142
|
+
const CONFIG = getExternalConfig()
|
|
143
|
+
const TS_CONFIG = loadFileToJSON('tsconfig.json')
|
|
144
|
+
|
|
145
|
+
export {
|
|
128
146
|
findFile,
|
|
129
|
-
|
|
147
|
+
loadConfigParam,
|
|
148
|
+
loadFileToJSON,
|
|
149
|
+
loadVLToolsConfig,
|
|
130
150
|
swapGlobals,
|
|
131
|
-
PKG
|
|
132
|
-
CONFIG
|
|
151
|
+
PKG,
|
|
152
|
+
CONFIG,
|
|
153
|
+
TS_CONFIG,
|
|
133
154
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vitus-labs/tools-typescript/lib",
|
|
3
|
+
"include": [
|
|
4
|
+
"src"
|
|
5
|
+
],
|
|
6
|
+
"exclude": [
|
|
7
|
+
"node_modules",
|
|
8
|
+
"__stories__",
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"compilerOptions": {
|
|
12
|
+
"strictNullChecks": true,
|
|
13
|
+
"types": ["@vitus-labs/tools-rollup"],
|
|
14
|
+
"rootDir": "src",
|
|
15
|
+
"outDir": "lib",
|
|
16
|
+
"baseUrl": ".",
|
|
17
|
+
"paths": {
|
|
18
|
+
"~/*": [
|
|
19
|
+
"src/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|