@andre1502/react-utilities 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +340 -0
- package/dist/Config/Config.d.ts +28 -0
- package/dist/Config/Config.js +200 -0
- package/dist/Config/Config.js.map +1 -0
- package/dist/Config/GoogleAuth.d.ts +15 -0
- package/dist/Config/GoogleAuth.js +71 -0
- package/dist/Config/GoogleAuth.js.map +1 -0
- package/dist/Config/Locales.d.ts +18 -0
- package/dist/Config/Locales.js +62 -0
- package/dist/Config/Locales.js.map +1 -0
- package/dist/Config/Output.d.ts +10 -0
- package/dist/Config/Output.js +28 -0
- package/dist/Config/Output.js.map +1 -0
- package/dist/Config/Sitemap.d.ts +13 -0
- package/dist/Config/Sitemap.js +73 -0
- package/dist/Config/Sitemap.js.map +1 -0
- package/dist/Format/NumberFormat.d.ts +6 -0
- package/dist/Format/NumberFormat.js +77 -0
- package/dist/Format/NumberFormat.js.map +1 -0
- package/dist/Format/NumberParser.d.ts +9 -0
- package/dist/Format/NumberParser.js +51 -0
- package/dist/Format/NumberParser.js.map +1 -0
- package/dist/React-BaJ1KfGF.js +87 -0
- package/dist/React-BaJ1KfGF.js.map +1 -0
- package/dist/React-qUl0CBmE.js +109 -0
- package/dist/React-qUl0CBmE.js.map +1 -0
- package/dist/ReactNative-CqUrY2ZJ.js +3856 -0
- package/dist/ReactNative-CqUrY2ZJ.js.map +1 -0
- package/dist/ReactNative-mNnws-b5.js +3834 -0
- package/dist/ReactNative-mNnws-b5.js.map +1 -0
- package/dist/Sentry/Build.d.ts +9 -0
- package/dist/Sentry/Build.js +88 -0
- package/dist/Sentry/Build.js.map +1 -0
- package/dist/Sentry/React.d.ts +18 -0
- package/dist/Sentry/React.js +104 -0
- package/dist/Sentry/React.js.map +1 -0
- package/dist/Sentry/ReactNative.d.ts +18 -0
- package/dist/Sentry/ReactNative.js +114 -0
- package/dist/Sentry/ReactNative.js.map +1 -0
- package/dist/Sentry/Utils.d.ts +2 -0
- package/dist/Sentry/Utils.js +24 -0
- package/dist/Sentry/Utils.js.map +1 -0
- package/dist/Utils/Files.d.ts +7 -0
- package/dist/Utils/Files.js +52 -0
- package/dist/Utils/Files.js.map +1 -0
- package/dist/Utils-Cq948gfa.js +20 -0
- package/dist/Utils-Cq948gfa.js.map +1 -0
- package/dist/Utils-Dilye04y.js +22 -0
- package/dist/Utils-Dilye04y.js.map +1 -0
- package/dist/config-cli.cjs +471 -0
- package/dist/config-cli.cjs.map +1 -0
- package/dist/config-cli.d.ts +34 -0
- package/dist/config-cli.js +220 -0
- package/dist/config-cli.js.map +1 -0
- package/dist/config-cli.mjs +443 -0
- package/dist/config-cli.mjs.map +1 -0
- package/dist/enums/CurrencySymbolEnum.d.ts +5 -0
- package/dist/enums/CurrencySymbolEnum.js +13 -0
- package/dist/enums/CurrencySymbolEnum.js.map +1 -0
- package/dist/format.cjs +122 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.js +55 -0
- package/dist/format.js.map +1 -0
- package/dist/format.mjs +117 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index-cli.cjs +24 -0
- package/dist/index-cli.cjs.map +1 -0
- package/dist/index-cli.d.ts +2 -0
- package/dist/index-cli.js +28 -0
- package/dist/index-cli.js.map +1 -0
- package/dist/index-cli.mjs +12 -0
- package/dist/index-cli.mjs.map +1 -0
- package/dist/index-fmt.cjs +16 -0
- package/dist/index-fmt.cjs.map +1 -0
- package/dist/index-fmt.d.ts +1 -0
- package/dist/index-fmt.js +17 -0
- package/dist/index-fmt.js.map +1 -0
- package/dist/index-fmt.mjs +3 -0
- package/dist/index-fmt.mjs.map +1 -0
- package/dist/index-rn.cjs +21 -0
- package/dist/index-rn.cjs.map +1 -0
- package/dist/index-rn.d.ts +2 -0
- package/dist/index-rn.js +28 -0
- package/dist/index-rn.js.map +1 -0
- package/dist/index-rn.mjs +6 -0
- package/dist/index-rn.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces/Config/ConfigOptions.d.ts +8 -0
- package/dist/interfaces/Config/ConfigOptions.js +6 -0
- package/dist/interfaces/Config/ConfigOptions.js.map +1 -0
- package/dist/interfaces/Config/OutputMap.d.ts +3 -0
- package/dist/interfaces/Config/OutputMap.js +6 -0
- package/dist/interfaces/Config/OutputMap.js.map +1 -0
- package/dist/interfaces/Config/OutputOptions.d.ts +7 -0
- package/dist/interfaces/Config/OutputOptions.js +6 -0
- package/dist/interfaces/Config/OutputOptions.js.map +1 -0
- package/dist/interfaces/Config/SitemapMap.d.ts +5 -0
- package/dist/interfaces/Config/SitemapMap.js +6 -0
- package/dist/interfaces/Config/SitemapMap.js.map +1 -0
- package/dist/interfaces/Config/StringMap.d.ts +3 -0
- package/dist/interfaces/Config/StringMap.js +6 -0
- package/dist/interfaces/Config/StringMap.js.map +1 -0
- package/dist/interfaces/Format/FormatOptions.d.ts +14 -0
- package/dist/interfaces/Format/FormatOptions.js +6 -0
- package/dist/interfaces/Format/FormatOptions.js.map +1 -0
- package/dist/interfaces/Sentry/InitOptions.d.ts +20 -0
- package/dist/interfaces/Sentry/InitOptions.js +6 -0
- package/dist/interfaces/Sentry/InitOptions.js.map +1 -0
- package/dist/interfaces/Sentry/InitOptionsRN.d.ts +4 -0
- package/dist/interfaces/Sentry/InitOptionsRN.js +6 -0
- package/dist/interfaces/Sentry/InitOptionsRN.js.map +1 -0
- package/dist/interfaces/Sentry/SourceMapOptions.d.ts +7 -0
- package/dist/interfaces/Sentry/SourceMapOptions.js +6 -0
- package/dist/interfaces/Sentry/SourceMapOptions.js.map +1 -0
- package/dist/sentry-cli.cjs +119 -0
- package/dist/sentry-cli.cjs.map +1 -0
- package/dist/sentry-cli.d.ts +9 -0
- package/dist/sentry-cli.js +50 -0
- package/dist/sentry-cli.js.map +1 -0
- package/dist/sentry-cli.mjs +98 -0
- package/dist/sentry-cli.mjs.map +1 -0
- package/dist/sentry-rn.cjs +11 -0
- package/dist/sentry-rn.cjs.map +1 -0
- package/dist/sentry-rn.d.ts +2 -0
- package/dist/sentry-rn.js +28 -0
- package/dist/sentry-rn.js.map +1 -0
- package/dist/sentry-rn.mjs +4 -0
- package/dist/sentry-rn.mjs.map +1 -0
- package/dist/sentry.cjs +11 -0
- package/dist/sentry.cjs.map +1 -0
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +28 -0
- package/dist/sentry.js.map +1 -0
- package/dist/sentry.mjs +4 -0
- package/dist/sentry.mjs.map +1 -0
- package/dist/types/Config/OptionType.d.ts +2 -0
- package/dist/types/Config/OptionType.js +6 -0
- package/dist/types/Config/OptionType.js.map +1 -0
- package/dist/types/Format/OptionType.d.ts +3 -0
- package/dist/types/Format/OptionType.js +6 -0
- package/dist/types/Format/OptionType.js.map +1 -0
- package/dist/types/Sentry/OptionType.d.ts +1 -0
- package/dist/types/Sentry/OptionType.js +6 -0
- package/dist/types/Sentry/OptionType.js.map +1 -0
- package/package.json +139 -0
- package/src/Config/Config.ts +258 -0
- package/src/Config/GoogleAuth.ts +54 -0
- package/src/Config/Locales.ts +72 -0
- package/src/Config/Output.ts +29 -0
- package/src/Config/Sitemap.ts +67 -0
- package/src/Format/NumberFormat.ts +96 -0
- package/src/Format/NumberParser.ts +42 -0
- package/src/Sentry/Build.ts +67 -0
- package/src/Sentry/React.ts +127 -0
- package/src/Sentry/ReactNative.ts +133 -0
- package/src/Sentry/Utils.ts +26 -0
- package/src/Utils/Files.ts +51 -0
- package/src/config-cli.ts +152 -0
- package/src/enums/CurrencySymbolEnum.ts +5 -0
- package/src/format.ts +39 -0
- package/src/index-cli.ts +2 -0
- package/src/index-fmt.ts +1 -0
- package/src/index-rn.ts +2 -0
- package/src/index.ts +2 -0
- package/src/interfaces/Config/ConfigOptions.ts +9 -0
- package/src/interfaces/Config/OutputMap.ts +3 -0
- package/src/interfaces/Config/OutputOptions.ts +8 -0
- package/src/interfaces/Config/SitemapMap.ts +5 -0
- package/src/interfaces/Config/StringMap.ts +3 -0
- package/src/interfaces/Format/FormatOptions.ts +19 -0
- package/src/interfaces/Sentry/InitOptions.ts +23 -0
- package/src/interfaces/Sentry/InitOptionsRN.ts +5 -0
- package/src/interfaces/Sentry/SourceMapOptions.ts +7 -0
- package/src/sentry-cli.ts +16 -0
- package/src/sentry-rn.ts +2 -0
- package/src/sentry.ts +2 -0
- package/src/types/Config/OptionType.ts +2 -0
- package/src/types/Format/OptionType.ts +15 -0
- package/src/types/Sentry/OptionType.ts +1 -0
package/package.json
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
{
|
2
|
+
"name": "@andre1502/react-utilities",
|
3
|
+
"version": "0.9.0",
|
4
|
+
"description": "module to combine common functions",
|
5
|
+
"repository": {
|
6
|
+
"type": "git",
|
7
|
+
"url": "https://github.com/andre1502/react-utilities"
|
8
|
+
},
|
9
|
+
"license": "MIT",
|
10
|
+
"author": "andre1502",
|
11
|
+
"type": "module",
|
12
|
+
"exports": {
|
13
|
+
".": {
|
14
|
+
"types": "./dist/index.d.ts",
|
15
|
+
"require": "./dist/index.cjs",
|
16
|
+
"import": "./dist/index.mjs"
|
17
|
+
},
|
18
|
+
"./fmt": {
|
19
|
+
"types": "./dist/index-fmt.d.ts",
|
20
|
+
"require": "./dist/index-fmt.cjs",
|
21
|
+
"import": "./dist/index-fmt.mjs"
|
22
|
+
},
|
23
|
+
"./react-native": {
|
24
|
+
"types": "./dist/index-rn.d.ts",
|
25
|
+
"require": "./dist/index-rn.cjs",
|
26
|
+
"import": "./dist/index-rn.mjs"
|
27
|
+
},
|
28
|
+
"./cli": {
|
29
|
+
"types": "./dist/index-cli.d.ts",
|
30
|
+
"require": "./dist/index-cli.cjs",
|
31
|
+
"import": "./dist/index-cli.mjs"
|
32
|
+
},
|
33
|
+
"./format": {
|
34
|
+
"types": "./dist/format.d.ts",
|
35
|
+
"require": "./dist/format.cjs",
|
36
|
+
"import": "./dist/format.mjs"
|
37
|
+
},
|
38
|
+
"./sentry": {
|
39
|
+
"types": "./dist/sentry.d.ts",
|
40
|
+
"require": "./dist/sentry.cjs",
|
41
|
+
"import": "./dist/sentry.mjs"
|
42
|
+
},
|
43
|
+
"./sentry-rn": {
|
44
|
+
"types": "./dist/sentry-rn.d.ts",
|
45
|
+
"require": "./dist/sentry-rn.cjs",
|
46
|
+
"import": "./dist/sentry-rn.mjs"
|
47
|
+
},
|
48
|
+
"./sentry-cli": {
|
49
|
+
"types": "./dist/sentry-cli.d.ts",
|
50
|
+
"require": "./dist/sentry-cli.cjs",
|
51
|
+
"import": "./dist/sentry-cli.mjs"
|
52
|
+
},
|
53
|
+
"./config-cli": {
|
54
|
+
"types": "./dist/config-cli.d.ts",
|
55
|
+
"require": "./dist/config-cli.cjs",
|
56
|
+
"import": "./dist/config-cli.mjs"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"main": "dist/index.cjs",
|
60
|
+
"module": "dist/index.mjs",
|
61
|
+
"react-native": "dist/index-rn.mjs",
|
62
|
+
"types": "dist/index.d.ts",
|
63
|
+
"files": [
|
64
|
+
"src",
|
65
|
+
"dist"
|
66
|
+
],
|
67
|
+
"scripts": {
|
68
|
+
"prebuild": "rm -rf ./tsconfig.tsbuildinfo && rm -rf ./.rollup.cache && rm -rf ./dist",
|
69
|
+
"build": "yarn prebuild && yarn build:esm && yarn build:cjs && yarn build:bundles && yarn declarations",
|
70
|
+
"build:bundles": "cross-env BABEL_ENV=esmBundled node --max-old-space-size=8192 ./node_modules/rollup/dist/bin/rollup --config",
|
71
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --extensions '.ts' --out-dir 'dist' --source-maps",
|
72
|
+
"build:esm": "cross-env BABEL_ENV=esmUnbundled babel src --extensions '.ts' --out-dir 'dist' --source-maps",
|
73
|
+
"declarations": "tsc -p tsconfig.json",
|
74
|
+
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
75
|
+
"lint": "eslint . --ext .ts,.tsx --ignore-path .gitignore --fix",
|
76
|
+
"prepublishOnly": "yarn build",
|
77
|
+
"test": "echo \"Warn: no test specified, ignore it\" && exit 0"
|
78
|
+
},
|
79
|
+
"dependencies": {
|
80
|
+
"@formatjs/intl-datetimeformat": "^6.12.5",
|
81
|
+
"@formatjs/intl-displaynames": "^6.6.8",
|
82
|
+
"@formatjs/intl-getcanonicallocales": "^2.3.0",
|
83
|
+
"@formatjs/intl-listformat": "^7.5.7",
|
84
|
+
"@formatjs/intl-locale": "^4.0.0",
|
85
|
+
"@formatjs/intl-numberformat": "^8.10.3",
|
86
|
+
"@formatjs/intl-pluralrules": "^5.2.14",
|
87
|
+
"@formatjs/intl-relativetimeformat": "^11.2.14",
|
88
|
+
"@sentry/react-native": "^5.26.0",
|
89
|
+
"@types/lodash": "^4.17.7",
|
90
|
+
"google-auth-library": "^9.11.0",
|
91
|
+
"googleapis": "^140.0.1",
|
92
|
+
"lodash": "^4.17.21",
|
93
|
+
"sitemap": "^8.0.0"
|
94
|
+
},
|
95
|
+
"devDependencies": {
|
96
|
+
"@babel/cli": "^7.24.8",
|
97
|
+
"@babel/core": "^7.24.9",
|
98
|
+
"@babel/preset-env": "^7.24.8",
|
99
|
+
"@babel/preset-react": "^7.24.7",
|
100
|
+
"@babel/preset-typescript": "^7.24.7",
|
101
|
+
"@rollup/plugin-babel": "^6.0.4",
|
102
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
103
|
+
"@rollup/plugin-json": "^6.1.0",
|
104
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
105
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
106
|
+
"@types/node": "^20.14.11",
|
107
|
+
"@types/react": "^18.3.3",
|
108
|
+
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
109
|
+
"@typescript-eslint/parser": "^7.16.1",
|
110
|
+
"cross-env": "^7.0.3",
|
111
|
+
"eslint": "^9.7.0",
|
112
|
+
"eslint-config-prettier": "^9.1.0",
|
113
|
+
"eslint-plugin-prettier": "^5.1.3",
|
114
|
+
"eslint-plugin-react": "^7.34.4",
|
115
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
116
|
+
"eslint-plugin-storybook": "^0.8.0",
|
117
|
+
"prettier": "^3.3.3",
|
118
|
+
"prettier-plugin-organize-imports": "^4.0.0",
|
119
|
+
"prettier-plugin-packagejson": "^2.5.1",
|
120
|
+
"rollup": "^4.19.1",
|
121
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
122
|
+
"tslib": "^2.6.3",
|
123
|
+
"typescript": "^5.5.3",
|
124
|
+
"yarn-upgrade-all": "^0.7.2"
|
125
|
+
},
|
126
|
+
"peerDependencies": {
|
127
|
+
"react": "*",
|
128
|
+
"react-dom": "*",
|
129
|
+
"react-native": "*",
|
130
|
+
"tslib": "*"
|
131
|
+
},
|
132
|
+
"optionalDependencies": {
|
133
|
+
"@rollup/rollup-linux-x64-gnu": "^4.13.2"
|
134
|
+
},
|
135
|
+
"packageManager": "yarn@4.3.1",
|
136
|
+
"publishConfig": {
|
137
|
+
"@andre1502:registry": "https://registry.npmjs.org/"
|
138
|
+
}
|
139
|
+
}
|
@@ -0,0 +1,258 @@
|
|
1
|
+
import * as lodash from 'lodash';
|
2
|
+
import { OutputMap } from '../interfaces/Config/OutputMap';
|
3
|
+
import { OutputOptions } from '../interfaces/Config/OutputOptions';
|
4
|
+
import { outputToFile } from './Output';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Process config data
|
8
|
+
*
|
9
|
+
* @param {any[][]} rows
|
10
|
+
* @return {OutputMap}
|
11
|
+
*/
|
12
|
+
const processConfig = (rows: any[][]): OutputMap => {
|
13
|
+
let versionConfig: OutputMap = {};
|
14
|
+
|
15
|
+
let params = rows[0].map((key) => {
|
16
|
+
return key;
|
17
|
+
});
|
18
|
+
|
19
|
+
rows.forEach((row: string[], index: number) => {
|
20
|
+
if (index === 0) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
versionConfig = processRow(row, params, versionConfig);
|
25
|
+
});
|
26
|
+
|
27
|
+
return versionConfig;
|
28
|
+
};
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Process config item
|
32
|
+
*
|
33
|
+
* @param {string[]} data
|
34
|
+
* @param {string[]} params
|
35
|
+
* @param {OutputMap} versionConfig
|
36
|
+
* @return {OutputMap}
|
37
|
+
*/
|
38
|
+
const processRow = (
|
39
|
+
data: string[],
|
40
|
+
params: string[],
|
41
|
+
versionConfig: OutputMap,
|
42
|
+
): OutputMap => {
|
43
|
+
const versionName = data[0];
|
44
|
+
versionConfig[versionName] = {};
|
45
|
+
|
46
|
+
params.forEach((paramsName, index) => {
|
47
|
+
if (index === 0 || data[index] === undefined || data[index] === '') {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
versionConfig[versionName][paramsName] = paramsTypeHandler(data[index]);
|
52
|
+
});
|
53
|
+
|
54
|
+
return versionConfig;
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Check is JSON value
|
59
|
+
*
|
60
|
+
* @param {string} str
|
61
|
+
* @return {boolean}
|
62
|
+
*/
|
63
|
+
const isJsonString = (str: string): boolean => {
|
64
|
+
try {
|
65
|
+
JSON.parse(str);
|
66
|
+
} catch (e) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
|
70
|
+
return true;
|
71
|
+
};
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Handling config value type
|
75
|
+
*
|
76
|
+
* @param {string} params
|
77
|
+
* @return {any}
|
78
|
+
*/
|
79
|
+
const paramsTypeHandler = (params: string): any => {
|
80
|
+
const booleanText = ['TRUE', 'FALSE'];
|
81
|
+
|
82
|
+
if (booleanText.includes(params.toUpperCase())) {
|
83
|
+
return params === 'TRUE';
|
84
|
+
}
|
85
|
+
|
86
|
+
if (isJsonString(params)) {
|
87
|
+
return JSON.parse(params);
|
88
|
+
}
|
89
|
+
|
90
|
+
return params;
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Export config data into js file
|
95
|
+
*
|
96
|
+
* @param {OutputMap} data
|
97
|
+
* @param {OutputOptions} options
|
98
|
+
* @return {void}
|
99
|
+
*/
|
100
|
+
const exportConfig = (data: OutputMap, options: OutputOptions): void => {
|
101
|
+
const config = {
|
102
|
+
params: data,
|
103
|
+
};
|
104
|
+
|
105
|
+
const content = `module.exports = ${JSON.stringify(config, null, 2)}`;
|
106
|
+
|
107
|
+
outputToFile(content, options);
|
108
|
+
};
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Handling env map value
|
112
|
+
*
|
113
|
+
* @param {string} env
|
114
|
+
* @return {string}
|
115
|
+
*/
|
116
|
+
const envMap = (env: string): string => {
|
117
|
+
let result;
|
118
|
+
|
119
|
+
switch (env) {
|
120
|
+
case 'dev':
|
121
|
+
case 'develop':
|
122
|
+
case 'development':
|
123
|
+
result = 'dev';
|
124
|
+
break;
|
125
|
+
case 'stg':
|
126
|
+
case 'stag':
|
127
|
+
case 'staging':
|
128
|
+
result = 'staging';
|
129
|
+
break;
|
130
|
+
case 'prd':
|
131
|
+
case 'prod':
|
132
|
+
case 'production':
|
133
|
+
result = 'production';
|
134
|
+
break;
|
135
|
+
default:
|
136
|
+
throw new Error(`env ${env} not supported.`);
|
137
|
+
}
|
138
|
+
|
139
|
+
return result;
|
140
|
+
};
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Mapping content to exportAs value
|
144
|
+
*
|
145
|
+
* @param {string} key
|
146
|
+
* @param {any} value
|
147
|
+
* @param {string} exportAs
|
148
|
+
* @return {string}
|
149
|
+
*/
|
150
|
+
const contentMap = (key: string, value: any, exportAs: string): string => {
|
151
|
+
let content = '';
|
152
|
+
|
153
|
+
switch (exportAs) {
|
154
|
+
case 'ts':
|
155
|
+
if (lodash.isNull(value)) {
|
156
|
+
content += `export const ${key}: string | null = ${value};\n`;
|
157
|
+
} else if (typeof value === 'boolean') {
|
158
|
+
content += `export const ${key}: boolean = ${value};\n`;
|
159
|
+
} else {
|
160
|
+
content += `export const ${key} = '${value}';\n`;
|
161
|
+
}
|
162
|
+
break;
|
163
|
+
case 'js':
|
164
|
+
content += `export const ${key} = "${value}";\n`;
|
165
|
+
break;
|
166
|
+
case 'env':
|
167
|
+
content += `${key} = "${value}"\n`;
|
168
|
+
break;
|
169
|
+
default:
|
170
|
+
throw new Error(`exportAs ${exportAs} not supported.`);
|
171
|
+
}
|
172
|
+
|
173
|
+
return content;
|
174
|
+
};
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Transform config
|
178
|
+
*
|
179
|
+
* @param {OutputMap} data
|
180
|
+
* @param {string} env
|
181
|
+
* @param {string} configKeyPrefix
|
182
|
+
* @param {OutputOptions} options
|
183
|
+
* @return {void}
|
184
|
+
*/
|
185
|
+
const transformConfig = (
|
186
|
+
data: OutputMap,
|
187
|
+
env: string,
|
188
|
+
configKeyPrefix: string,
|
189
|
+
options: OutputOptions,
|
190
|
+
): void => {
|
191
|
+
const envKey = configKeyPrefix ? `${configKeyPrefix}ENV` : 'ENV';
|
192
|
+
|
193
|
+
let content = contentMap(envKey, envMap(env), options.exportAs!);
|
194
|
+
|
195
|
+
Object.keys(data).forEach((key) => {
|
196
|
+
const newConfigKey = configKeyPrefix ? `${configKeyPrefix}${key}` : key;
|
197
|
+
|
198
|
+
if (key === 'BASE_PROJECT') {
|
199
|
+
const extensionFile = [
|
200
|
+
`.${data[key]}.js`,
|
201
|
+
`.${data[key]}.jsx`,
|
202
|
+
`.${data[key]}.ts`,
|
203
|
+
`.${data[key]}.tsx`,
|
204
|
+
`.${data[key]}.css`,
|
205
|
+
`.${data[key]}.json`,
|
206
|
+
`.${data[key]}.scss`,
|
207
|
+
];
|
208
|
+
|
209
|
+
content += contentMap(
|
210
|
+
newConfigKey,
|
211
|
+
extensionFile.join(','),
|
212
|
+
options.exportAs!,
|
213
|
+
);
|
214
|
+
|
215
|
+
return;
|
216
|
+
}
|
217
|
+
|
218
|
+
if (key === 'SITEMAP') {
|
219
|
+
content += contentMap(
|
220
|
+
newConfigKey,
|
221
|
+
JSON.stringify(data[key]),
|
222
|
+
options.exportAs!,
|
223
|
+
);
|
224
|
+
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
|
228
|
+
if (Array.isArray(data[key])) {
|
229
|
+
content += contentMap(
|
230
|
+
newConfigKey,
|
231
|
+
data[key].join(','),
|
232
|
+
options.exportAs!,
|
233
|
+
);
|
234
|
+
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
|
238
|
+
if (typeof data[key] === 'object') {
|
239
|
+
if (data[key].hasOwnProperty(env)) {
|
240
|
+
content += contentMap(newConfigKey, data[key][env], options.exportAs!);
|
241
|
+
} else {
|
242
|
+
content += contentMap(
|
243
|
+
newConfigKey,
|
244
|
+
JSON.stringify(data[key]),
|
245
|
+
options.exportAs!,
|
246
|
+
);
|
247
|
+
}
|
248
|
+
|
249
|
+
return;
|
250
|
+
}
|
251
|
+
|
252
|
+
content += contentMap(newConfigKey, data[key], options.exportAs!);
|
253
|
+
});
|
254
|
+
|
255
|
+
outputToFile(content, options);
|
256
|
+
};
|
257
|
+
|
258
|
+
export { exportConfig, processConfig, transformConfig };
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { existsSync } from 'fs';
|
2
|
+
import { GoogleAuth } from 'google-auth-library';
|
3
|
+
import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
|
4
|
+
import { google } from 'googleapis';
|
5
|
+
import * as path from 'path';
|
6
|
+
import * as process from 'process';
|
7
|
+
|
8
|
+
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
|
9
|
+
const GOOGLE_APPLICATION_CREDENTIALS_PATH = path.join(
|
10
|
+
process.cwd(),
|
11
|
+
'/google_application_credentials.json',
|
12
|
+
);
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Authenticate using google console service account.
|
16
|
+
* @return {GoogleAuth<JSONClient>}
|
17
|
+
*/
|
18
|
+
const authorizeServiceAccount = (): GoogleAuth<JSONClient> => {
|
19
|
+
const isExist = existsSync(GOOGLE_APPLICATION_CREDENTIALS_PATH);
|
20
|
+
|
21
|
+
const options: any = {
|
22
|
+
scopes: SCOPES,
|
23
|
+
};
|
24
|
+
|
25
|
+
if (isExist) {
|
26
|
+
options.keyFile = GOOGLE_APPLICATION_CREDENTIALS_PATH;
|
27
|
+
}
|
28
|
+
|
29
|
+
return new GoogleAuth(options);
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {GoogleAuth<JSONClient>} auth The authenticated Google OAuth client.
|
34
|
+
* @param {string} spreadsheetId
|
35
|
+
* @param {string} spreadsheetTab
|
36
|
+
* @return {Promise<any[][] | null | undefined>}
|
37
|
+
*/
|
38
|
+
const fetchGoogleSheet = async (
|
39
|
+
auth: GoogleAuth<JSONClient>,
|
40
|
+
spreadsheetId: string,
|
41
|
+
spreadsheetTab: string,
|
42
|
+
): Promise<any[][] | null | undefined> => {
|
43
|
+
const sheets = google.sheets({ version: 'v4', auth });
|
44
|
+
|
45
|
+
const res = await sheets.spreadsheets.values.get({
|
46
|
+
spreadsheetId: spreadsheetId,
|
47
|
+
range: spreadsheetTab,
|
48
|
+
majorDimension: 'COLUMNS',
|
49
|
+
});
|
50
|
+
|
51
|
+
return res.data.values;
|
52
|
+
};
|
53
|
+
|
54
|
+
export { authorizeServiceAccount, fetchGoogleSheet };
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { OutputMap } from '../interfaces/Config/OutputMap';
|
2
|
+
import { OutputOptions } from '../interfaces/Config/OutputOptions';
|
3
|
+
import { StringMap } from '../interfaces/Config/StringMap';
|
4
|
+
import { outputToFile } from './Output';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Process locales data
|
8
|
+
*
|
9
|
+
* @param {any[][]} rows
|
10
|
+
* @return {OutputMap}
|
11
|
+
*/
|
12
|
+
const processLocales = (rows: any[][]): OutputMap => {
|
13
|
+
let keys = rows[0].map((key) => {
|
14
|
+
return key;
|
15
|
+
});
|
16
|
+
|
17
|
+
let data: OutputMap = {};
|
18
|
+
|
19
|
+
rows.forEach((lang: string[], index: number) => {
|
20
|
+
if (index === 0) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
let langData: StringMap = {};
|
25
|
+
|
26
|
+
lang.forEach((data: string, dIndex: number) => {
|
27
|
+
if (dIndex === 0) {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
|
31
|
+
langData[keys[dIndex]] = data;
|
32
|
+
});
|
33
|
+
|
34
|
+
data[lang[0]] = langData;
|
35
|
+
});
|
36
|
+
|
37
|
+
return data;
|
38
|
+
};
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Export locales data to file
|
42
|
+
*
|
43
|
+
* @param {OutputMap} data
|
44
|
+
* @param {OutputOptions} options
|
45
|
+
* @return {void}
|
46
|
+
*/
|
47
|
+
const exportLocales = (data: OutputMap, options: OutputOptions): void => {
|
48
|
+
Object.keys(data).forEach((key) => {
|
49
|
+
options.filename = `${key}.${options.exportAs!.toLowerCase()}`;
|
50
|
+
|
51
|
+
let content = '';
|
52
|
+
|
53
|
+
switch (options.exportAs) {
|
54
|
+
case 'ts':
|
55
|
+
content = 'export default ' + JSON.stringify(data[key], null, 2);
|
56
|
+
break;
|
57
|
+
case 'json':
|
58
|
+
content = JSON.stringify(data[key], null, 2);
|
59
|
+
break;
|
60
|
+
default:
|
61
|
+
throw new Error(`exportAs ${options.exportAs} not supported.`);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (!content) {
|
65
|
+
throw new Error(`empty content, please check remote value.`);
|
66
|
+
}
|
67
|
+
|
68
|
+
outputToFile(content, options);
|
69
|
+
});
|
70
|
+
};
|
71
|
+
|
72
|
+
export { exportLocales, processLocales };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { writeFile } from 'fs';
|
2
|
+
import { OutputOptions } from '../interfaces/Config/OutputOptions';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Write content into target file
|
6
|
+
*
|
7
|
+
* @param {string} content
|
8
|
+
* @param {OutputOptions} options
|
9
|
+
* @return {void}
|
10
|
+
*/
|
11
|
+
const outputToFile = (content: string, options: OutputOptions): void => {
|
12
|
+
let filename = options.filename;
|
13
|
+
|
14
|
+
if (options.isFilenameLowercase) {
|
15
|
+
filename = filename.toLowerCase();
|
16
|
+
}
|
17
|
+
|
18
|
+
const filePath = `${options.folder}/${filename}`;
|
19
|
+
|
20
|
+
writeFile(filePath, content, 'utf8', function (err) {
|
21
|
+
if (err) {
|
22
|
+
throw err;
|
23
|
+
}
|
24
|
+
|
25
|
+
console.log(filePath, content);
|
26
|
+
});
|
27
|
+
};
|
28
|
+
|
29
|
+
export { outputToFile };
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { SitemapStream, streamToPromise } from 'sitemap';
|
2
|
+
import { Readable } from 'stream';
|
3
|
+
import { OutputOptions } from '../interfaces/Config/OutputOptions';
|
4
|
+
import { SitemapMap } from '../interfaces/Config/SitemapMap';
|
5
|
+
import { outputToFile } from './Output';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Generate Sitemap Robots
|
9
|
+
*
|
10
|
+
* @param {string} hostname
|
11
|
+
* @param {OutputOptions} options
|
12
|
+
* @return {void}
|
13
|
+
*/
|
14
|
+
const generateRobots = (hostname: string, options: OutputOptions): void => {
|
15
|
+
let content = [
|
16
|
+
'# https://www.robotstxt.org/robotstxt.html',
|
17
|
+
`Sitemap: ${hostname}/${options.filename}`,
|
18
|
+
'User-agent: *',
|
19
|
+
'Disallow:',
|
20
|
+
];
|
21
|
+
|
22
|
+
options.filename = 'robots.txt';
|
23
|
+
|
24
|
+
outputToFile(content.join('\r\n'), options);
|
25
|
+
};
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Transform Sitemap
|
29
|
+
*
|
30
|
+
* @param {string} hostname
|
31
|
+
* @param {SitemapMap[]} urls
|
32
|
+
* @param {boolean} includeRobots
|
33
|
+
* @param {OutputOptions} options
|
34
|
+
* @return {Promise<void>}
|
35
|
+
*/
|
36
|
+
const transformSitemap = async (
|
37
|
+
hostname: string,
|
38
|
+
urls: SitemapMap[],
|
39
|
+
includeRobots: boolean,
|
40
|
+
options: OutputOptions,
|
41
|
+
): Promise<void> => {
|
42
|
+
const stream = new SitemapStream({
|
43
|
+
hostname: hostname,
|
44
|
+
lastmodDateOnly: false,
|
45
|
+
xmlns: {
|
46
|
+
news: false,
|
47
|
+
xhtml: false,
|
48
|
+
image: false,
|
49
|
+
video: false,
|
50
|
+
custom: [
|
51
|
+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',
|
52
|
+
'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"',
|
53
|
+
],
|
54
|
+
},
|
55
|
+
});
|
56
|
+
const content = await streamToPromise(Readable.from(urls).pipe(stream)).then(
|
57
|
+
(data) => data.toString(),
|
58
|
+
);
|
59
|
+
|
60
|
+
outputToFile(content, options);
|
61
|
+
|
62
|
+
if (includeRobots) {
|
63
|
+
generateRobots(hostname, options);
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
export { transformSitemap };
|