yini-parser 1.0.0-alpha.2 → 1.0.0-alpha.3
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/dist/config/env.d.ts +20 -6
- package/dist/config/env.js +59 -12
- package/dist/core/types.d.ts +10 -0
- package/dist/index.js +17 -9
- package/dist/parseEntry.js +10 -0
- package/dist/utils/system.js +2 -2
- package/package.json +9 -9
package/dist/config/env.d.ts
CHANGED
|
@@ -11,10 +11,24 @@ type TNodeEnv = 'development' | 'production' | 'test';
|
|
|
11
11
|
* @note Since this is a library (as opposed to a Web/App), we don't use "staging".
|
|
12
12
|
*/
|
|
13
13
|
type TAppEnv = 'local' | 'ci' | 'production';
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
|
|
14
|
+
declare const localNodeEnv: TNodeEnv;
|
|
15
|
+
declare const localAppEnv: TAppEnv;
|
|
16
|
+
/** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */
|
|
17
|
+
export declare const isDevEnv: () => boolean;
|
|
18
|
+
/** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */
|
|
19
|
+
export declare const isProdEnv: () => boolean;
|
|
20
|
+
/** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */
|
|
21
|
+
export declare const isTestEnv: () => boolean;
|
|
22
|
+
/** Will be based on the local argument when this process was launched.
|
|
23
|
+
* @returns True if the DEV flag is set.
|
|
24
|
+
* @example npm run start -- isDev=1
|
|
25
|
+
* @example node dist/index.js isDev=1
|
|
26
|
+
*/
|
|
17
27
|
export declare const isDev: () => boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
/** Will be based on the local argument when this process was launched.
|
|
29
|
+
* @returns True if the DEBUG flag is set.
|
|
30
|
+
* @example npm run start -- isDebug=1
|
|
31
|
+
* @example node dist/index.js isDebug=1
|
|
32
|
+
*/
|
|
33
|
+
export declare const isDebug: () => boolean;
|
|
34
|
+
export { localNodeEnv, localAppEnv };
|
package/dist/config/env.js
CHANGED
|
@@ -1,15 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
exports.
|
|
6
|
-
const
|
|
7
|
-
exports.
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
3
|
+
exports.localAppEnv = exports.localNodeEnv = exports.isDebug = exports.isDev = exports.isTestEnv = exports.isProdEnv = exports.isDevEnv = void 0;
|
|
4
|
+
const localNodeEnv = (process.env.NODE_ENV || 'production');
|
|
5
|
+
exports.localNodeEnv = localNodeEnv;
|
|
6
|
+
const localAppEnv = (process.env.APP_ENV || 'production');
|
|
7
|
+
exports.localAppEnv = localAppEnv;
|
|
8
|
+
// export const initEnvs = () => {
|
|
9
|
+
// const localNodeEnv = (process.env.NODE_ENV || 'production') as TNodeEnv
|
|
10
|
+
// const localAppEnv = (process.env?.APP_ENV || 'production') as TAppEnv
|
|
11
|
+
// return { localNodeEnv, localAppEnv }
|
|
12
|
+
// }
|
|
13
|
+
// const { localNodeEnv, localAppEnv } = initEnvs()
|
|
14
|
+
/** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */
|
|
15
|
+
const isDevEnv = () => localNodeEnv === 'development';
|
|
16
|
+
exports.isDevEnv = isDevEnv;
|
|
17
|
+
/** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */
|
|
18
|
+
const isProdEnv = () => localNodeEnv === 'production';
|
|
19
|
+
exports.isProdEnv = isProdEnv;
|
|
20
|
+
/** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */
|
|
21
|
+
const isTestEnv = () => localNodeEnv === 'test';
|
|
22
|
+
exports.isTestEnv = isTestEnv;
|
|
23
|
+
/** Will be based on the local argument when this process was launched.
|
|
24
|
+
* @returns True if the DEV flag is set.
|
|
25
|
+
* @example npm run start -- isDev=1
|
|
26
|
+
* @example node dist/index.js isDev=1
|
|
27
|
+
*/
|
|
28
|
+
const isDev = () => {
|
|
29
|
+
const len = process.argv.length;
|
|
30
|
+
// NOTE: We will start with index 2, since the first element will be
|
|
31
|
+
// execPath. The second element will be the path to the
|
|
32
|
+
// JavaScript file being executed.
|
|
33
|
+
for (let i = 2; i < len; i++) {
|
|
34
|
+
const val = process.argv[i] || '';
|
|
35
|
+
if (val.toLowerCase() === 'isdev=1' ||
|
|
36
|
+
val.toLowerCase() === 'isdev=true') {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
11
42
|
exports.isDev = isDev;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
/** Will be based on the local argument when this process was launched.
|
|
44
|
+
* @returns True if the DEBUG flag is set.
|
|
45
|
+
* @example npm run start -- isDebug=1
|
|
46
|
+
* @example node dist/index.js isDebug=1
|
|
47
|
+
*/
|
|
48
|
+
const isDebug = () => {
|
|
49
|
+
const len = process.argv.length;
|
|
50
|
+
// NOTE: We will start with index 2, since the first element will be
|
|
51
|
+
// execPath. The second element will be the path to the
|
|
52
|
+
// JavaScript file being executed.
|
|
53
|
+
for (let i = 2; i < len; i++) {
|
|
54
|
+
const val = process.argv[i] || '';
|
|
55
|
+
if (val.toLowerCase() === 'isdebug=1' ||
|
|
56
|
+
val.toLowerCase() === 'isdebug=true') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
exports.isDebug = isDebug;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ export interface IParseMetaData {
|
|
|
21
21
|
errors: null | number;
|
|
22
22
|
warnings: null | number;
|
|
23
23
|
infoAndNotices: null | number;
|
|
24
|
+
envs: {
|
|
25
|
+
NODE_ENV: undefined | string;
|
|
26
|
+
APP_ENV: undefined | string;
|
|
27
|
+
libNodeEnv: undefined | string;
|
|
28
|
+
libAppEnv: undefined | string;
|
|
29
|
+
};
|
|
30
|
+
libFlags: {
|
|
31
|
+
isDev: boolean;
|
|
32
|
+
isDebug: boolean;
|
|
33
|
+
};
|
|
24
34
|
};
|
|
25
35
|
timing?: {
|
|
26
36
|
totalMs: null | number;
|
package/dist/index.js
CHANGED
|
@@ -21,16 +21,24 @@ const system_1 = require("./utils/system");
|
|
|
21
21
|
const YINI_1 = __importDefault(require("./YINI"));
|
|
22
22
|
var YINI_2 = require("./YINI");
|
|
23
23
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(YINI_2).default; } });
|
|
24
|
-
if ((0, env_1.isDev)() || (0, env_1.isDebug)()) {
|
|
25
|
-
console.log('process.env?.NODE_ENV = ' + ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV));
|
|
26
|
-
console.log('process.env?.APP_ENV = ' + ((_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV));
|
|
27
|
-
console.log('process.env?.IS_DEBUG = ' + ((_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG));
|
|
28
|
-
}
|
|
29
|
-
// console.log('NODE_ENV = ' + NODE_ENV)
|
|
30
|
-
// console.log('APP_ENV = ' + APP_ENV)
|
|
31
24
|
(0, system_1.debugPrint)();
|
|
32
25
|
(0, system_1.debugPrint)('-> Entered index.ts');
|
|
33
26
|
(0, system_1.debugPrint)();
|
|
27
|
+
if ((0, env_1.isDev)() || (0, env_1.isDebug)()) {
|
|
28
|
+
console.log(`process.env?.NODE_ENV = '${(_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV}'`);
|
|
29
|
+
console.log(`process.env?.APP_ENV = '${(_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV}'`);
|
|
30
|
+
console.log(`process.env?.IS_DEBUG = '${(_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG}'`);
|
|
31
|
+
(0, system_1.debugPrint)();
|
|
32
|
+
console.log(`localNodeEnv = '${env_1.localNodeEnv}'`);
|
|
33
|
+
console.log(` localAppEnv = '${env_1.localAppEnv}'`);
|
|
34
|
+
console.log(' isProdEnv() = ' + (0, env_1.isProdEnv)());
|
|
35
|
+
console.log(' isDevEnv() = ' + (0, env_1.isDevEnv)());
|
|
36
|
+
console.log(' isTestEnv() = ' + (0, env_1.isTestEnv)());
|
|
37
|
+
console.log();
|
|
38
|
+
console.log(' isDev() = ' + (0, env_1.isDev)());
|
|
39
|
+
console.log(' isDebug() = ' + (0, env_1.isDebug)());
|
|
40
|
+
console.log();
|
|
41
|
+
}
|
|
34
42
|
const debugTestObj = {
|
|
35
43
|
name: 'e_test',
|
|
36
44
|
lang: 'TypeScript',
|
|
@@ -38,7 +46,7 @@ const debugTestObj = {
|
|
|
38
46
|
(0, system_1.debugPrint)('debugTestObj:');
|
|
39
47
|
(0, system_1.debugPrint)(debugTestObj);
|
|
40
48
|
(0, system_1.debugPrint)();
|
|
41
|
-
if ((0, env_1.
|
|
49
|
+
if ((0, env_1.isProdEnv)()) {
|
|
42
50
|
// Do nothing, and exit.
|
|
43
51
|
}
|
|
44
52
|
else {
|
|
@@ -89,7 +97,7 @@ listItems = ["a", "b", "c"]
|
|
|
89
97
|
// console.debug(invalidInput1)
|
|
90
98
|
// }
|
|
91
99
|
// YINI.parse(invalidInput1)
|
|
92
|
-
if (env_1.
|
|
100
|
+
if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') {
|
|
93
101
|
/*
|
|
94
102
|
YINI.parse(`
|
|
95
103
|
--^ Section0
|
package/dist/parseEntry.js
CHANGED
|
@@ -127,6 +127,16 @@ const parseMain = (yiniContent, options = {
|
|
|
127
127
|
errors: errorHandler.getNumOfErrors(),
|
|
128
128
|
warnings: errorHandler.getNumOfWarnings(),
|
|
129
129
|
infoAndNotices: errorHandler.getNumOfInfoAndNotices(),
|
|
130
|
+
envs: {
|
|
131
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
132
|
+
APP_ENV: process.env.APP_ENV,
|
|
133
|
+
libNodeEnv: env_1.localNodeEnv,
|
|
134
|
+
libAppEnv: env_1.localAppEnv,
|
|
135
|
+
},
|
|
136
|
+
libFlags: {
|
|
137
|
+
isDev: (0, env_1.isDev)(),
|
|
138
|
+
isDebug: (0, env_1.isDebug)(),
|
|
139
|
+
},
|
|
130
140
|
};
|
|
131
141
|
}
|
|
132
142
|
if (options.isWithTiming) {
|
package/dist/utils/system.js
CHANGED
|
@@ -11,11 +11,11 @@ const debugPrint = (str = '') => {
|
|
|
11
11
|
};
|
|
12
12
|
exports.debugPrint = debugPrint;
|
|
13
13
|
const devPrint = (str = '') => {
|
|
14
|
-
(0, env_1.isDev)() && !(0, env_1.
|
|
14
|
+
(0, env_1.isDev)() && !(0, env_1.isTestEnv)() && console.log('DEV: ' + str);
|
|
15
15
|
};
|
|
16
16
|
exports.devPrint = devPrint;
|
|
17
17
|
const printObject = (obj) => {
|
|
18
|
-
if ((0, env_1.
|
|
18
|
+
if ((0, env_1.isProdEnv)() || ((0, env_1.isTestEnv)() && !(0, env_1.isDebug)()))
|
|
19
19
|
return;
|
|
20
20
|
const str = JSON.stringify(obj, null, 4);
|
|
21
21
|
console.log(str);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yini-parser",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "YINI parser for JavaScript/TypeScript, an INI-inspired configuration format, meant to be readable, and easy to use.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"read",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
},
|
|
37
37
|
"private": false,
|
|
38
38
|
"scripts": {
|
|
39
|
-
"start": "
|
|
40
|
-
"start:debug": "
|
|
41
|
-
"start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts",
|
|
42
|
-
"start:dev:debug": "cross-env
|
|
39
|
+
"start": "npm run build && node dist/index.js",
|
|
40
|
+
"start:debug": "npm run start -- isDebug=1",
|
|
41
|
+
"start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts isDev=1",
|
|
42
|
+
"start:dev:debug": "cross-env npm run start:dev -- isDebug=1",
|
|
43
43
|
"start-w-clean": "npm run tsc && npm run clean:ts-js && npm run start:dev",
|
|
44
44
|
"test": "cross-env NODE_ENV=test APP_ENV=local jest --bail --verbose --runInBand",
|
|
45
|
-
"test:debug": "cross-env
|
|
45
|
+
"test:debug": "cross-env npm run test -- --isDebug=1",
|
|
46
46
|
"test:smoke": "cross-env NODE_ENV=test APP_ENV=local jest tests/smoke --bail --verbose --runInBand",
|
|
47
47
|
"test:unit": "cross-env NODE_ENV=test APP_ENV=local jest tests/unit --bail --verbose --runInBand",
|
|
48
48
|
"test:integr": "cross-env NODE_ENV=test APP_ENV=local jest tests/integration --bail --verbose --runInBand",
|
|
49
|
-
"test:smoke:debug": "cross-env
|
|
50
|
-
"test:unit:debug": "cross-env
|
|
51
|
-
"test:integr:debug": "cross-env
|
|
49
|
+
"test:smoke:debug": "cross-env npm run test:smoke -- --isDebug=1",
|
|
50
|
+
"test:unit:debug": "cross-env npm run test:unit -- --isDebug=1",
|
|
51
|
+
"test:integr:debug": "cross-env npm run test:integr -- --isDebug=1",
|
|
52
52
|
"ci:test": "cross-env NODE_ENV=test APP_ENV=ci jest --verbose --runInBand",
|
|
53
53
|
"ci:test:smoke": "cross-env NODE_ENV=test APP_ENV=ci jest tests/smoke --verbose --runInBand",
|
|
54
54
|
"tsc": "npx tsc -p ./tsconfig.json",
|