@teambit/config-store 0.0.1 → 0.0.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/config-getter.ts +23 -1
- package/config-store.main.runtime.ts +18 -4
- package/dist/config-getter.d.ts +10 -1
- package/dist/config-getter.js +28 -5
- package/dist/config-getter.js.map +1 -1
- package/dist/config-store.main.runtime.d.ts +6 -1
- package/dist/config-store.main.runtime.js +25 -7
- package/dist/config-store.main.runtime.js.map +1 -1
- package/dist/global-config.d.ts +11 -0
- package/dist/global-config.js +92 -0
- package/dist/global-config.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/global-config.ts +69 -0
- package/index.ts +1 -1
- package/package.json +8 -6
- /package/dist/{preview-1739503157162.js → preview-1739848706199.js} +0 -0
package/config-getter.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import gitconfig from '@teambit/gitconfig';
|
2
2
|
import { isNil } from 'lodash';
|
3
|
-
import { GlobalConfig } from '
|
3
|
+
import { getGlobalConfigPath, GlobalConfig } from './global-config';
|
4
4
|
|
5
5
|
export const ENV_VARIABLE_CONFIG_PREFIX = 'BIT_CONFIG_';
|
6
6
|
|
@@ -9,6 +9,7 @@ export interface Store {
|
|
9
9
|
set(key: string, value: string): void;
|
10
10
|
del(key: string): void;
|
11
11
|
write(): Promise<void>;
|
12
|
+
getPath(): string;
|
12
13
|
invalidateCache(): Promise<void>;
|
13
14
|
}
|
14
15
|
|
@@ -101,6 +102,7 @@ export class ConfigGetter {
|
|
101
102
|
del: (key: string) => this.globalConfig.delete(key),
|
102
103
|
write: async () => this.globalConfig.write(),
|
103
104
|
invalidateCache: async () => this._globalConfig = undefined,
|
105
|
+
getPath: () => getGlobalConfigPath(),
|
104
106
|
};
|
105
107
|
}
|
106
108
|
}
|
@@ -116,6 +118,26 @@ export function getNumberFromConfig(key: string): number | undefined {
|
|
116
118
|
export function listConfig(): Record<string, string> {
|
117
119
|
return configGetter.listConfig();
|
118
120
|
}
|
121
|
+
/**
|
122
|
+
* @deprecated use setConfig from the ConfigStore aspect instance
|
123
|
+
*/
|
124
|
+
export function setGlobalConfig(key: string, val: string) {
|
125
|
+
const globalStore = configGetter.getGlobalStore();
|
126
|
+
globalStore.set(key, val);
|
127
|
+
configGetter.globalConfig.writeSync();
|
128
|
+
globalStore.invalidateCache().catch(() => {});
|
129
|
+
configGetter.invalidateCache();
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* @deprecated use delConfig from the ConfigStore aspect instance
|
133
|
+
*/
|
134
|
+
export function delGlobalConfig(key: string) {
|
135
|
+
const globalStore = configGetter.getGlobalStore();
|
136
|
+
globalStore.del(key);
|
137
|
+
configGetter.globalConfig.writeSync();
|
138
|
+
globalStore.invalidateCache().catch(() => {});
|
139
|
+
configGetter.invalidateCache();
|
140
|
+
}
|
119
141
|
|
120
142
|
function toEnvVariableName(configName: string): string {
|
121
143
|
return `${ENV_VARIABLE_CONFIG_PREFIX}${configName.replace(/\./g, '_').toUpperCase()}`;
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import CLIAspect,
|
1
|
+
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
2
|
+
import { compact } from 'lodash';
|
2
3
|
import { ConfigStoreAspect } from './config-store.aspect';
|
3
4
|
import { configGetter, Store } from './config-getter';
|
4
5
|
import { ConfigCmd } from './config-cmd';
|
@@ -19,10 +20,23 @@ export class ConfigStoreMain {
|
|
19
20
|
this.stores[origin] = store;
|
20
21
|
configGetter.addStore(store);
|
21
22
|
}
|
22
|
-
|
23
|
+
/**
|
24
|
+
* "global" must be first. the rest doesn't matter. can be scope or workspace.
|
25
|
+
*/
|
26
|
+
getStoresOrdered(): Store[] {
|
27
|
+
return compact([this.stores.global, this.stores.workspace, this.stores.scope].filter(Boolean)) as Store[];
|
28
|
+
}
|
29
|
+
invalidateCache() {
|
30
|
+
configGetter.invalidateCache();
|
31
|
+
const stores = this.getStoresOrdered();
|
32
|
+
stores.forEach((store) => {
|
33
|
+
configGetter.addStore(store);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
async invalidateAllStoresCaches() {
|
23
37
|
configGetter.invalidateCache();
|
24
|
-
|
25
|
-
|
38
|
+
const stores = this.getStoresOrdered();
|
39
|
+
for await (const store of stores) {
|
26
40
|
await store.invalidateCache();
|
27
41
|
configGetter.addStore(store);
|
28
42
|
};
|
package/dist/config-getter.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
import { GlobalConfig } from '
|
1
|
+
import { GlobalConfig } from './global-config';
|
2
2
|
export declare const ENV_VARIABLE_CONFIG_PREFIX = "BIT_CONFIG_";
|
3
3
|
export interface Store {
|
4
4
|
list(): Record<string, string>;
|
5
5
|
set(key: string, value: string): void;
|
6
6
|
del(key: string): void;
|
7
7
|
write(): Promise<void>;
|
8
|
+
getPath(): string;
|
8
9
|
invalidateCache(): Promise<void>;
|
9
10
|
}
|
10
11
|
/**
|
@@ -31,3 +32,11 @@ export declare const configGetter: ConfigGetter;
|
|
31
32
|
export declare function getConfig(key: string): string | undefined;
|
32
33
|
export declare function getNumberFromConfig(key: string): number | undefined;
|
33
34
|
export declare function listConfig(): Record<string, string>;
|
35
|
+
/**
|
36
|
+
* @deprecated use setConfig from the ConfigStore aspect instance
|
37
|
+
*/
|
38
|
+
export declare function setGlobalConfig(key: string, val: string): void;
|
39
|
+
/**
|
40
|
+
* @deprecated use delConfig from the ConfigStore aspect instance
|
41
|
+
*/
|
42
|
+
export declare function delGlobalConfig(key: string): void;
|
package/dist/config-getter.js
CHANGED
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.configGetter = exports.ENV_VARIABLE_CONFIG_PREFIX = exports.ConfigGetter = void 0;
|
7
|
+
exports.delGlobalConfig = delGlobalConfig;
|
7
8
|
exports.getConfig = getConfig;
|
8
9
|
exports.getNumberFromConfig = getNumberFromConfig;
|
9
10
|
exports.listConfig = listConfig;
|
11
|
+
exports.setGlobalConfig = setGlobalConfig;
|
10
12
|
function _gitconfig() {
|
11
13
|
const data = _interopRequireDefault(require("@teambit/gitconfig"));
|
12
14
|
_gitconfig = function () {
|
@@ -21,9 +23,9 @@ function _lodash() {
|
|
21
23
|
};
|
22
24
|
return data;
|
23
25
|
}
|
24
|
-
function
|
25
|
-
const data = require("
|
26
|
-
|
26
|
+
function _globalConfig() {
|
27
|
+
const data = require("./global-config");
|
28
|
+
_globalConfig = function () {
|
27
29
|
return data;
|
28
30
|
};
|
29
31
|
return data;
|
@@ -46,7 +48,7 @@ class ConfigGetter {
|
|
46
48
|
}
|
47
49
|
get globalConfig() {
|
48
50
|
if (!this._globalConfig) {
|
49
|
-
this._globalConfig =
|
51
|
+
this._globalConfig = _globalConfig().GlobalConfig.loadSync();
|
50
52
|
}
|
51
53
|
return this._globalConfig;
|
52
54
|
}
|
@@ -119,7 +121,8 @@ class ConfigGetter {
|
|
119
121
|
set: (key, value) => this.globalConfig.set(key, value),
|
120
122
|
del: key => this.globalConfig.delete(key),
|
121
123
|
write: async () => this.globalConfig.write(),
|
122
|
-
invalidateCache: async () => this._globalConfig = undefined
|
124
|
+
invalidateCache: async () => this._globalConfig = undefined,
|
125
|
+
getPath: () => (0, _globalConfig().getGlobalConfigPath)()
|
123
126
|
};
|
124
127
|
}
|
125
128
|
}
|
@@ -134,6 +137,26 @@ function getNumberFromConfig(key) {
|
|
134
137
|
function listConfig() {
|
135
138
|
return configGetter.listConfig();
|
136
139
|
}
|
140
|
+
/**
|
141
|
+
* @deprecated use setConfig from the ConfigStore aspect instance
|
142
|
+
*/
|
143
|
+
function setGlobalConfig(key, val) {
|
144
|
+
const globalStore = configGetter.getGlobalStore();
|
145
|
+
globalStore.set(key, val);
|
146
|
+
configGetter.globalConfig.writeSync();
|
147
|
+
globalStore.invalidateCache().catch(() => {});
|
148
|
+
configGetter.invalidateCache();
|
149
|
+
}
|
150
|
+
/**
|
151
|
+
* @deprecated use delConfig from the ConfigStore aspect instance
|
152
|
+
*/
|
153
|
+
function delGlobalConfig(key) {
|
154
|
+
const globalStore = configGetter.getGlobalStore();
|
155
|
+
globalStore.del(key);
|
156
|
+
configGetter.globalConfig.writeSync();
|
157
|
+
globalStore.invalidateCache().catch(() => {});
|
158
|
+
configGetter.invalidateCache();
|
159
|
+
}
|
137
160
|
function toEnvVariableName(configName) {
|
138
161
|
return `${ENV_VARIABLE_CONFIG_PREFIX}${configName.replace(/\./g, '_').toUpperCase()}`;
|
139
162
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_gitconfig","data","_interopRequireDefault","require","_lodash","_legacy","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ENV_VARIABLE_CONFIG_PREFIX","exports","ConfigGetter","constructor","globalConfig","_globalConfig","GlobalConfig","loadSync","store","_store","toPlainObject","addStore","currentStore","list","getConfig","key","undefined","envVarName","toEnvVariableName","process","env","val","isNil","gitStore","gitVal","gitconfig","get","sync","getConfigNumeric","fromConfig","num","isNaN","Error","getConfigBoolean","result","listConfig","invalidateCache","getGlobalStore","set","del","delete","write","configGetter","getNumberFromConfig","configName","replace","toUpperCase"],"sources":["config-getter.ts"],"sourcesContent":["import gitconfig from '@teambit/gitconfig';\nimport { isNil } from 'lodash';\nimport { GlobalConfig } from '@teambit/legacy.global-config';\n\nexport const ENV_VARIABLE_CONFIG_PREFIX = 'BIT_CONFIG_';\n\nexport interface Store {\n list(): Record<string, string>;\n set(key: string, value: string): void;\n del(key: string): void;\n write(): Promise<void>;\n invalidateCache(): Promise<void>;\n}\n\n/**\n * Singleton cache for the config object. so it can be used everywhere even by non-aspects components.\n */\nexport class ConfigGetter {\n private _store: Record<string, string> | undefined;\n private _globalConfig: GlobalConfig | undefined;\n private gitStore: Record<string, string | undefined> = {};\n\n get globalConfig() {\n if (!this._globalConfig) {\n this._globalConfig = GlobalConfig.loadSync();\n }\n return this._globalConfig;\n }\n\n get store() {\n if (!this._store) {\n this._store = this.globalConfig.toPlainObject();\n }\n return this._store;\n }\n\n /**\n * in case a config-key exists in both, the new one (the given store) wins.\n */\n addStore(store: Store) {\n const currentStore = this.store;\n this._store = { ...currentStore, ...store.list() };\n }\n\n getConfig(key: string): string | undefined {\n if (!key) {\n return undefined;\n }\n\n const envVarName = toEnvVariableName(key);\n if (process.env[envVarName]) {\n return process.env[envVarName];\n }\n\n const store = this.store;\n const val = store[key];\n if (!isNil(val)) {\n return val;\n }\n\n if (key in this.gitStore) {\n return this.gitStore[key];\n }\n try {\n const gitVal = gitconfig.get.sync(key);\n this.gitStore[key] = gitVal;\n } catch {\n // Ignore error from git config get\n this.gitStore[key] = undefined;\n }\n return this.gitStore[key];\n }\n getConfigNumeric(key: string): number | undefined {\n const fromConfig = this.getConfig(key);\n if (isNil(fromConfig)) return undefined;\n const num = Number(fromConfig);\n if (Number.isNaN(num)) {\n throw new Error(`config of \"${key}\" is invalid. Expected number, got \"${fromConfig}\"`);\n }\n return num;\n }\n getConfigBoolean(key: string): boolean | undefined {\n const result = this.getConfig(key);\n if (isNil(result)) return undefined;\n if (typeof result === 'boolean') return result;\n if (result === 'true') return true;\n if (result === 'false') return false;\n throw new Error(`the configuration \"${key}\" has an invalid value \"${result}\". it should be boolean`);\n }\n listConfig() {\n const store = this.store;\n return store;\n }\n invalidateCache() {\n this._store = undefined;\n }\n getGlobalStore(): Store {\n return {\n list: () => this.globalConfig.toPlainObject(),\n set: (key: string, value: string) => this.globalConfig.set(key, value),\n del: (key: string) => this.globalConfig.delete(key),\n write: async () => this.globalConfig.write(),\n invalidateCache: async () => this._globalConfig = undefined,\n };\n }\n}\n\nexport const configGetter = new ConfigGetter();\n\nexport function getConfig(key: string): string | undefined {\n return configGetter.getConfig(key);\n}\nexport function getNumberFromConfig(key: string): number | undefined {\n return configGetter.getConfigNumeric(key);\n}\nexport function listConfig(): Record<string, string> {\n return configGetter.listConfig();\n}\n\nfunction toEnvVariableName(configName: string): string {\n return `${ENV_VARIABLE_CONFIG_PREFIX}${configName.replace(/\\./g, '_').toUpperCase()}`;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,WAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,UAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6D,SAAAC,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,QAAAH,CAAA,EAAAI,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAP,CAAA,OAAAM,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAR,CAAA,GAAAI,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAX,CAAA,EAAAI,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAf,CAAA,aAAAI,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,E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ACxB,OAAOA,KAAK;EACd;EACA4B,eAAeA,CAAA,EAAG;IAChB,IAAI,CAAC3B,MAAM,GAAGO,SAAS;EACzB;EACAqB,cAAcA,CAAA,EAAU;IACtB,OAAO;MACLxB,IAAI,EAAEA,CAAA,KAAM,IAAI,CAACT,YAAY,CAACM,aAAa,CAAC,CAAC;MAC7C4B,GAAG,EAAEA,CAACvB,GAAW,EAAE1B,KAAa,KAAK,IAAI,CAACe,YAAY,CAACkC,GAAG,CAACvB,GAAG,EAAE1B,KAAK,CAAC;MACtEkD,GAAG,EAAGxB,GAAW,IAAK,IAAI,CAACX,YAAY,CAACoC,MAAM,CAACzB,GAAG,CAAC;MACnD0B,KAAK,EAAE,MAAAA,CAAA,KAAY,IAAI,CAACrC,YAAY,CAACqC,KAAK,CAAC,CAAC;MAC5CL,eAAe,EAAE,MAAAA,CAAA,KAAY,IAAI,CAAC/B,aAAa,GAAGW;IACpD,CAAC;EACH;AACF;AAACf,OAAA,CAAAC,YAAA,GAAAA,YAAA;AAEM,MAAMwC,YAAY,GAAAzC,OAAA,CAAAyC,YAAA,GAAG,IAAIxC,YAAY,CAAC,CAAC;AAEvC,SAASY,SAASA,CAACC,GAAW,EAAsB;EACzD,OAAO2B,YAAY,CAAC5B,SAAS,CAACC,GAAG,CAAC;AACpC;AACO,SAAS4B,mBAAmBA,CAAC5B,GAAW,EAAsB;EACnE,OAAO2B,YAAY,CAACd,gBAAgB,CAACb,GAAG,CAAC;AAC3C;AACO,SAASoB,UAAUA,CAAA,EAA2B;EACnD,OAAOO,YAAY,CAACP,UAAU,CAAC,CAAC;AAClC;AAEA,SAASjB,iBAAiBA,CAAC0B,UAAkB,EAAU;EACrD,OAAO,GAAG5C,0BAA0B,GAAG4C,UAAU,CAACC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACC,WAAW,CAAC,CAAC,EAAE;AACvF","ignoreList":[]}
|
1
|
+
{"version":3,"names":["_gitconfig","data","_interopRequireDefault","require","_lodash","_globalConfig","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ENV_VARIABLE_CONFIG_PREFIX","exports","ConfigGetter","constructor","globalConfig","GlobalConfig","loadSync","store","_store","toPlainObject","addStore","currentStore","list","getConfig","key","undefined","envVarName","toEnvVariableName","process","env","val","isNil","gitStore","gitVal","gitconfig","get","sync","getConfigNumeric","fromConfig","num","isNaN","Error","getConfigBoolean","result","listConfig","invalidateCache","getGlobalStore","set","del","delete","write","getPath","getGlobalConfigPath","configGetter","getNumberFromConfig","setGlobalConfig","globalStore","writeSync","catch","delGlobalConfig","configName","replace","toUpperCase"],"sources":["config-getter.ts"],"sourcesContent":["import gitconfig from '@teambit/gitconfig';\nimport { isNil } from 'lodash';\nimport { getGlobalConfigPath, GlobalConfig } from './global-config';\n\nexport const ENV_VARIABLE_CONFIG_PREFIX = 'BIT_CONFIG_';\n\nexport interface Store {\n list(): Record<string, string>;\n set(key: string, value: string): void;\n del(key: string): void;\n write(): Promise<void>;\n getPath(): string;\n invalidateCache(): Promise<void>;\n}\n\n/**\n * Singleton cache for the config object. so it can be used everywhere even by non-aspects components.\n */\nexport class ConfigGetter {\n private _store: Record<string, string> | undefined;\n private _globalConfig: GlobalConfig | undefined;\n private gitStore: Record<string, string | undefined> = {};\n\n get globalConfig() {\n if (!this._globalConfig) {\n this._globalConfig = GlobalConfig.loadSync();\n }\n return this._globalConfig;\n }\n\n get store() {\n if (!this._store) {\n this._store = this.globalConfig.toPlainObject();\n }\n return this._store;\n }\n\n /**\n * in case a config-key exists in both, the new one (the given store) wins.\n */\n addStore(store: Store) {\n const currentStore = this.store;\n this._store = { ...currentStore, ...store.list() };\n }\n\n getConfig(key: string): string | undefined {\n if (!key) {\n return undefined;\n }\n\n const envVarName = toEnvVariableName(key);\n if (process.env[envVarName]) {\n return process.env[envVarName];\n }\n\n const store = this.store;\n const val = store[key];\n if (!isNil(val)) {\n return val;\n }\n\n if (key in this.gitStore) {\n return this.gitStore[key];\n }\n try {\n const gitVal = gitconfig.get.sync(key);\n this.gitStore[key] = gitVal;\n } catch {\n // Ignore error from git config get\n this.gitStore[key] = undefined;\n }\n return this.gitStore[key];\n }\n getConfigNumeric(key: string): number | undefined {\n const fromConfig = this.getConfig(key);\n if (isNil(fromConfig)) return undefined;\n const num = Number(fromConfig);\n if (Number.isNaN(num)) {\n throw new Error(`config of \"${key}\" is invalid. Expected number, got \"${fromConfig}\"`);\n }\n return num;\n }\n getConfigBoolean(key: string): boolean | undefined {\n const result = this.getConfig(key);\n if (isNil(result)) return undefined;\n if (typeof result === 'boolean') return result;\n if (result === 'true') return true;\n if (result === 'false') return false;\n throw new Error(`the configuration \"${key}\" has an invalid value \"${result}\". it should be boolean`);\n }\n listConfig() {\n const store = this.store;\n return store;\n }\n invalidateCache() {\n this._store = undefined;\n }\n getGlobalStore(): Store {\n return {\n list: () => this.globalConfig.toPlainObject(),\n set: (key: string, value: string) => this.globalConfig.set(key, value),\n del: (key: string) => this.globalConfig.delete(key),\n write: async () => this.globalConfig.write(),\n invalidateCache: async () => this._globalConfig = undefined,\n getPath: () => getGlobalConfigPath(),\n };\n }\n}\n\nexport const configGetter = new ConfigGetter();\n\nexport function getConfig(key: string): string | undefined {\n return configGetter.getConfig(key);\n}\nexport function getNumberFromConfig(key: string): number | undefined {\n return configGetter.getConfigNumeric(key);\n}\nexport function listConfig(): Record<string, string> {\n return configGetter.listConfig();\n}\n/**\n * @deprecated use setConfig from the ConfigStore aspect instance\n */\nexport function setGlobalConfig(key: string, val: string) {\n const globalStore = configGetter.getGlobalStore();\n globalStore.set(key, val);\n configGetter.globalConfig.writeSync();\n globalStore.invalidateCache().catch(() => {});\n configGetter.invalidateCache();\n}\n/**\n * @deprecated use delConfig from the ConfigStore aspect instance\n */\nexport function delGlobalConfig(key: string) {\n const globalStore = configGetter.getGlobalStore();\n globalStore.del(key);\n configGetter.globalConfig.writeSync();\n globalStore.invalidateCache().catch(() => {});\n configGetter.invalidateCache();\n}\n\nfunction toEnvVariableName(configName: string): string {\n return `${ENV_VARIABLE_CONFIG_PREFIX}${configName.replace(/\\./g, '_').toUpperCase()}`;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAAA,WAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,UAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,cAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,aAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAoE,SAAAC,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,QAAAH,CAAA,EAAAI,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAP,CAAA,OAAAM,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAR,CAAA,GAAAI,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAX,CAAA,EAAAI,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAf,CAAA,aAAAI,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EA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EM,GAAG,CAAC;EACzBuB,YAAY,CAACvC,YAAY,CAAC2C,SAAS,CAAC,CAAC;EACrCD,WAAW,CAACX,eAAe,CAAC,CAAC,CAACa,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;EAC7CL,YAAY,CAACR,eAAe,CAAC,CAAC;AAChC;AACA;AACA;AACA;AACO,SAASc,eAAeA,CAACnC,GAAW,EAAE;EAC3C,MAAMgC,WAAW,GAAGH,YAAY,CAACP,cAAc,CAAC,CAAC;EACjDU,WAAW,CAACR,GAAG,CAACxB,GAAG,CAAC;EACpB6B,YAAY,CAACvC,YAAY,CAAC2C,SAAS,CAAC,CAAC;EACrCD,WAAW,CAACX,eAAe,CAAC,CAAC,CAACa,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;EAC7CL,YAAY,CAACR,eAAe,CAAC,CAAC;AAChC;AAEA,SAASlB,iBAAiBA,CAACiC,UAAkB,EAAU;EACrD,OAAO,GAAGlD,0BAA0B,GAAGkD,UAAU,CAACC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACC,WAAW,CAAC,CAAC,EAAE;AACvF","ignoreList":[]}
|
@@ -7,7 +7,12 @@ export declare class ConfigStoreMain {
|
|
7
7
|
[origin: string]: Store;
|
8
8
|
};
|
9
9
|
addStore(origin: StoreOrigin, store: Store): void;
|
10
|
-
|
10
|
+
/**
|
11
|
+
* "global" must be first. the rest doesn't matter. can be scope or workspace.
|
12
|
+
*/
|
13
|
+
getStoresOrdered(): Store[];
|
14
|
+
invalidateCache(): void;
|
15
|
+
invalidateAllStoresCaches(): Promise<void>;
|
11
16
|
setConfig(key: string, value: string, origin?: StoreOrigin): Promise<void>;
|
12
17
|
getConfig(key: string): string | undefined;
|
13
18
|
getConfigBoolean(key: string): boolean | undefined;
|
@@ -5,12 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = exports.ConfigStoreMain = void 0;
|
7
7
|
function _cli() {
|
8
|
-
const data =
|
8
|
+
const data = require("@teambit/cli");
|
9
9
|
_cli = function () {
|
10
10
|
return data;
|
11
11
|
};
|
12
12
|
return data;
|
13
13
|
}
|
14
|
+
function _lodash() {
|
15
|
+
const data = require("lodash");
|
16
|
+
_lodash = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
14
21
|
function _configStore() {
|
15
22
|
const data = require("./config-store.aspect");
|
16
23
|
_configStore = function () {
|
@@ -32,8 +39,6 @@ function _configCmd() {
|
|
32
39
|
};
|
33
40
|
return data;
|
34
41
|
}
|
35
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
36
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
37
42
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
38
43
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
39
44
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
@@ -53,10 +58,23 @@ class ConfigStoreMain {
|
|
53
58
|
this.stores[origin] = store;
|
54
59
|
_configGetter().configGetter.addStore(store);
|
55
60
|
}
|
56
|
-
|
61
|
+
/**
|
62
|
+
* "global" must be first. the rest doesn't matter. can be scope or workspace.
|
63
|
+
*/
|
64
|
+
getStoresOrdered() {
|
65
|
+
return (0, _lodash().compact)([this.stores.global, this.stores.workspace, this.stores.scope].filter(Boolean));
|
66
|
+
}
|
67
|
+
invalidateCache() {
|
68
|
+
_configGetter().configGetter.invalidateCache();
|
69
|
+
const stores = this.getStoresOrdered();
|
70
|
+
stores.forEach(store => {
|
71
|
+
_configGetter().configGetter.addStore(store);
|
72
|
+
});
|
73
|
+
}
|
74
|
+
async invalidateAllStoresCaches() {
|
57
75
|
_configGetter().configGetter.invalidateCache();
|
58
|
-
|
59
|
-
|
76
|
+
const stores = this.getStoresOrdered();
|
77
|
+
for await (const store of stores) {
|
60
78
|
await store.invalidateCache();
|
61
79
|
_configGetter().configGetter.addStore(store);
|
62
80
|
}
|
@@ -101,7 +119,7 @@ class ConfigStoreMain {
|
|
101
119
|
}
|
102
120
|
exports.ConfigStoreMain = ConfigStoreMain;
|
103
121
|
_defineProperty(ConfigStoreMain, "slots", []);
|
104
|
-
_defineProperty(ConfigStoreMain, "dependencies", [_cli().
|
122
|
+
_defineProperty(ConfigStoreMain, "dependencies", [_cli().CLIAspect]);
|
105
123
|
_defineProperty(ConfigStoreMain, "runtime", _cli().MainRuntime);
|
106
124
|
_configStore().ConfigStoreAspect.addRuntime(ConfigStoreMain);
|
107
125
|
var _default = exports.default = ConfigStoreMain;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_cli","data","
|
1
|
+
{"version":3,"names":["_cli","data","require","_lodash","_configStore","_configGetter","_configCmd","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ConfigStoreMain","constructor","stores","_stores","global","configGetter","getGlobalStore","addStore","origin","store","getStoresOrdered","compact","workspace","scope","filter","Boolean","invalidateCache","forEach","invalidateAllStoresCaches","setConfig","key","Error","set","write","getConfig","getConfigBoolean","getConfigNumeric","delConfig","getOrigin","keys","find","originName","list","foundOrigin","del","listConfig","provider","cli","configStore","register","ConfigCmd","exports","CLIAspect","MainRuntime","ConfigStoreAspect","addRuntime","_default","default"],"sources":["config-store.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { compact } from 'lodash';\nimport { ConfigStoreAspect } from './config-store.aspect';\nimport { configGetter, Store } from './config-getter';\nimport { ConfigCmd } from './config-cmd';\n\nexport type StoreOrigin = 'scope' | 'workspace' | 'global';\n\nexport class ConfigStoreMain {\n private _stores: { [origin: string]: Store } | undefined;\n get stores (): { [origin: string]: Store } {\n if (!this._stores) {\n this._stores = {\n global: configGetter.getGlobalStore()\n };\n }\n return this._stores;\n }\n addStore(origin: StoreOrigin, store: Store) {\n this.stores[origin] = store;\n configGetter.addStore(store);\n }\n /**\n * \"global\" must be first. the rest doesn't matter. can be scope or workspace.\n */\n getStoresOrdered(): Store[] {\n return compact([this.stores.global, this.stores.workspace, this.stores.scope].filter(Boolean)) as Store[];\n }\n invalidateCache() {\n configGetter.invalidateCache();\n const stores = this.getStoresOrdered();\n stores.forEach((store) => {\n configGetter.addStore(store);\n });\n }\n async invalidateAllStoresCaches() {\n configGetter.invalidateCache();\n const stores = this.getStoresOrdered();\n for await (const store of stores) {\n await store.invalidateCache();\n configGetter.addStore(store);\n };\n }\n async setConfig(key: string, value: string, origin: StoreOrigin = 'global') {\n const store = this.stores[origin];\n if (!store) throw new Error(`unable to set config, \"${origin}\" origin is missing`);\n store.set(key, value);\n await store.write();\n await this.invalidateCache();\n }\n getConfig(key: string): string | undefined {\n return configGetter.getConfig(key);\n }\n getConfigBoolean(key: string): boolean | undefined {\n return configGetter.getConfigBoolean(key);\n }\n getConfigNumeric(key: string): number | undefined {\n return configGetter.getConfigNumeric(key);\n }\n async delConfig(key: string, origin?: StoreOrigin) {\n const getOrigin = () => {\n if (origin) return origin;\n return Object.keys(this.stores).find(originName => key in this.stores[originName].list());\n }\n const foundOrigin = getOrigin();\n if (!foundOrigin) return; // if the key is not found in any store (or given store), nothing to do.\n const store = this.stores[foundOrigin];\n store.del(key);\n await store.write();\n await this.invalidateCache();\n }\n listConfig() {\n return configGetter.listConfig();\n }\n\n static slots = [];\n static dependencies = [CLIAspect];\n static runtime = MainRuntime;\n static async provider([cli]: [CLIMain]) {\n const configStore = new ConfigStoreMain();\n cli.register(new ConfigCmd(configStore));\n return configStore;\n\n }\n}\n\nConfigStoreAspect.addRuntime(ConfigStoreMain);\n\nexport default ConfigStoreMain;\n"],"mappings":";;;;;;AAAA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,cAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,aAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAyC,SAAAM,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAA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,MAAM,EAAE,OAAOA,MAAM;MACzB,OAAOtB,MAAM,CAAC2C,IAAI,CAAC,IAAI,CAAC3B,MAAM,CAAC,CAAC4B,IAAI,CAACC,UAAU,IAAIX,GAAG,IAAI,IAAI,CAAClB,MAAM,CAAC6B,UAAU,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;IACD,MAAMC,WAAW,GAAGL,SAAS,CAAC,CAAC;IAC/B,IAAI,CAACK,WAAW,EAAE,OAAO,CAAC;IAC1B,MAAMxB,KAAK,GAAG,IAAI,CAACP,MAAM,CAAC+B,WAAW,CAAC;IACtCxB,KAAK,CAACyB,GAAG,CAACd,GAAG,CAAC;IACd,MAAMX,KAAK,CAACc,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAACP,eAAe,CAAC,CAAC;EAC9B;EACAmB,UAAUA,CAAA,EAAG;IACX,OAAO9B,4BAAY,CAAC8B,UAAU,CAAC,CAAC;EAClC;EAKA,aAAaC,QAAQA,CAAC,CAACC,GAAG,CAAY,EAAE;IACtC,MAAMC,WAAW,GAAG,IAAItC,eAAe,CAAC,CAAC;IACzCqC,GAAG,CAACE,QAAQ,CAAC,KAAIC,sBAAS,EAACF,WAAW,CAAC,CAAC;IACxC,OAAOA,WAAW;EAEpB;AACF;AAACG,OAAA,CAAAzC,eAAA,GAAAA,eAAA;AAAAnB,eAAA,CA5EYmB,eAAe,WAmEX,EAAE;AAAAnB,eAAA,CAnENmB,eAAe,kBAoEJ,CAAC0C,gBAAS,CAAC;AAAA7D,eAAA,CApEtBmB,eAAe,aAqET2C,kBAAW;AAS9BC,gCAAiB,CAACC,UAAU,CAAC7C,eAAe,CAAC;AAAC,IAAA8C,QAAA,GAAAL,OAAA,CAAAM,OAAA,GAE/B/C,eAAe","ignoreList":[]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare function getGlobalConfigPath(): string;
|
2
|
+
export declare class GlobalConfig extends Map<string, string> {
|
3
|
+
toPlainObject(): {
|
4
|
+
[key: string]: any;
|
5
|
+
};
|
6
|
+
toJson(): string;
|
7
|
+
write(): Promise<void>;
|
8
|
+
writeSync(): void;
|
9
|
+
static loadSync(): GlobalConfig;
|
10
|
+
static load(): Promise<GlobalConfig>;
|
11
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.GlobalConfig = void 0;
|
7
|
+
exports.getGlobalConfigPath = getGlobalConfigPath;
|
8
|
+
function _fsExtra() {
|
9
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
10
|
+
_fsExtra = function () {
|
11
|
+
return data;
|
12
|
+
};
|
13
|
+
return data;
|
14
|
+
}
|
15
|
+
function path() {
|
16
|
+
const data = _interopRequireWildcard(require("path"));
|
17
|
+
path = function () {
|
18
|
+
return data;
|
19
|
+
};
|
20
|
+
return data;
|
21
|
+
}
|
22
|
+
function _legacy() {
|
23
|
+
const data = require("@teambit/legacy.constants");
|
24
|
+
_legacy = function () {
|
25
|
+
return data;
|
26
|
+
};
|
27
|
+
return data;
|
28
|
+
}
|
29
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
30
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
31
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
32
|
+
function getGlobalConfigPath() {
|
33
|
+
return path().join(_legacy().GLOBAL_CONFIG, _legacy().GLOBAL_CONFIG_FILE);
|
34
|
+
}
|
35
|
+
class GlobalConfig extends Map {
|
36
|
+
toPlainObject() {
|
37
|
+
return mapToObject(this);
|
38
|
+
}
|
39
|
+
toJson() {
|
40
|
+
return JSON.stringify(this.toPlainObject(), null, 2);
|
41
|
+
}
|
42
|
+
write() {
|
43
|
+
return _fsExtra().default.outputFile(getGlobalConfigPath(), this.toJson());
|
44
|
+
}
|
45
|
+
writeSync() {
|
46
|
+
return _fsExtra().default.outputFileSync(getGlobalConfigPath(), this.toJson());
|
47
|
+
}
|
48
|
+
static loadSync() {
|
49
|
+
const configPath = getGlobalConfigPath();
|
50
|
+
if (!_fsExtra().default.existsSync(configPath)) {
|
51
|
+
const config = new GlobalConfig([]);
|
52
|
+
config.writeSync();
|
53
|
+
return config;
|
54
|
+
}
|
55
|
+
const contents = _fsExtra().default.readFileSync(configPath);
|
56
|
+
return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));
|
57
|
+
}
|
58
|
+
static async load() {
|
59
|
+
const configPath = getGlobalConfigPath();
|
60
|
+
const exists = await _fsExtra().default.pathExists(configPath);
|
61
|
+
if (!exists) {
|
62
|
+
const config = new GlobalConfig([]);
|
63
|
+
await config.write();
|
64
|
+
return config;
|
65
|
+
}
|
66
|
+
const contents = await _fsExtra().default.readFile(configPath);
|
67
|
+
return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Cast a `Map` to a plain object.
|
73
|
+
* Keys are being casted by invoking `toString` on each key.
|
74
|
+
* @name mapToObject
|
75
|
+
* @param {Map} map to cast
|
76
|
+
* @returns {*} plain object
|
77
|
+
* @example
|
78
|
+
* ```js
|
79
|
+
* mapToObject(new Map([['key', 'val'], ['foo', 'bar']]));
|
80
|
+
* // => { key: 'val', foo: 'bar' }
|
81
|
+
* ```
|
82
|
+
*/
|
83
|
+
exports.GlobalConfig = GlobalConfig;
|
84
|
+
function mapToObject(map) {
|
85
|
+
const object = {};
|
86
|
+
map.forEach((val, key) => {
|
87
|
+
object[key.toString()] = val;
|
88
|
+
});
|
89
|
+
return object;
|
90
|
+
}
|
91
|
+
|
92
|
+
//# sourceMappingURL=global-config.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","path","_interopRequireWildcard","_legacy","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getGlobalConfigPath","join","GLOBAL_CONFIG","GLOBAL_CONFIG_FILE","GlobalConfig","Map","toPlainObject","mapToObject","toJson","JSON","stringify","write","fs","outputFile","writeSync","outputFileSync","loadSync","configPath","existsSync","config","contents","readFileSync","entries","parse","toString","load","exists","pathExists","readFile","exports","map","object","forEach","val","key"],"sources":["global-config.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport * as path from 'path';\n\nimport { GLOBAL_CONFIG, GLOBAL_CONFIG_FILE } from '@teambit/legacy.constants';\n\nexport function getGlobalConfigPath() {\n return path.join(GLOBAL_CONFIG, GLOBAL_CONFIG_FILE);\n}\n\nexport class GlobalConfig extends Map<string, string> {\n toPlainObject() {\n return mapToObject(this);\n }\n\n toJson() {\n return JSON.stringify(this.toPlainObject(), null, 2);\n }\n\n write() {\n return fs.outputFile(getGlobalConfigPath(), this.toJson());\n }\n\n writeSync() {\n return fs.outputFileSync(getGlobalConfigPath(), this.toJson());\n }\n\n static loadSync(): GlobalConfig {\n const configPath = getGlobalConfigPath();\n if (!fs.existsSync(configPath)) {\n const config = new GlobalConfig([]);\n config.writeSync();\n return config;\n }\n const contents = fs.readFileSync(configPath);\n return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));\n }\n\n static async load(): Promise<GlobalConfig> {\n const configPath = getGlobalConfigPath();\n const exists = await fs.pathExists(configPath);\n if (!exists) {\n const config = new GlobalConfig([]);\n await config.write();\n return config;\n }\n const contents = await fs.readFile(configPath);\n return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));\n }\n}\n\n/**\n * Cast a `Map` to a plain object.\n * Keys are being casted by invoking `toString` on each key.\n * @name mapToObject\n * @param {Map} map to cast\n * @returns {*} plain object\n * @example\n * ```js\n * mapToObject(new Map([['key', 'val'], ['foo', 'bar']]));\n * // => { key: 'val', foo: 'bar' }\n * ```\n */\nfunction mapToObject(map: Map<any, any>): { [key: string]: any } {\n const object = {};\n map.forEach((val, key) => {\n object[key.toString()] = val;\n });\n return object;\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,C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OAAA,CAAAzB,YAAA,GAAAA,YAAA;AAYA,SAASG,WAAWA,CAACuB,GAAkB,EAA0B;EAC/D,MAAMC,MAAM,GAAG,CAAC,CAAC;EACjBD,GAAG,CAACE,OAAO,CAAC,CAACC,GAAG,EAAEC,GAAG,KAAK;IACxBH,MAAM,CAACG,GAAG,CAACV,QAAQ,CAAC,CAAC,CAAC,GAAGS,GAAG;EAC9B,CAAC,CAAC;EACF,OAAOF,MAAM;AACf","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
@@ -2,4 +2,4 @@ import { ConfigStoreAspect } from './config-store.aspect';
|
|
2
2
|
export type { ConfigStoreMain } from './config-store.main.runtime';
|
3
3
|
export default ConfigStoreAspect;
|
4
4
|
export { ConfigStoreAspect };
|
5
|
-
export { getConfig, getNumberFromConfig, listConfig, Store } from './config-getter';
|
5
|
+
export { getConfig, getNumberFromConfig, listConfig, Store, setGlobalConfig, delGlobalConfig } from './config-getter';
|
package/dist/index.js
CHANGED
@@ -16,6 +16,12 @@ Object.defineProperty(exports, "Store", {
|
|
16
16
|
}
|
17
17
|
});
|
18
18
|
exports.default = void 0;
|
19
|
+
Object.defineProperty(exports, "delGlobalConfig", {
|
20
|
+
enumerable: true,
|
21
|
+
get: function () {
|
22
|
+
return _configGetter().delGlobalConfig;
|
23
|
+
}
|
24
|
+
});
|
19
25
|
Object.defineProperty(exports, "getConfig", {
|
20
26
|
enumerable: true,
|
21
27
|
get: function () {
|
@@ -34,6 +40,12 @@ Object.defineProperty(exports, "listConfig", {
|
|
34
40
|
return _configGetter().listConfig;
|
35
41
|
}
|
36
42
|
});
|
43
|
+
Object.defineProperty(exports, "setGlobalConfig", {
|
44
|
+
enumerable: true,
|
45
|
+
get: function () {
|
46
|
+
return _configGetter().setGlobalConfig;
|
47
|
+
}
|
48
|
+
});
|
37
49
|
function _configStore() {
|
38
50
|
const data = require("./config-store.aspect");
|
39
51
|
_configStore = function () {
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_configStore","data","require","_configGetter","_default","exports","default","ConfigStoreAspect"],"sources":["index.ts"],"sourcesContent":["import { ConfigStoreAspect } from './config-store.aspect';\n\nexport type { ConfigStoreMain } from './config-store.main.runtime';\nexport default ConfigStoreAspect;\nexport { ConfigStoreAspect };\nexport { getConfig, getNumberFromConfig, listConfig, Store } from './config-getter';"],"mappings":"
|
1
|
+
{"version":3,"names":["_configStore","data","require","_configGetter","_default","exports","default","ConfigStoreAspect"],"sources":["index.ts"],"sourcesContent":["import { ConfigStoreAspect } from './config-store.aspect';\n\nexport type { ConfigStoreMain } from './config-store.main.runtime';\nexport default ConfigStoreAspect;\nexport { ConfigStoreAspect };\nexport { getConfig, getNumberFromConfig, listConfig, Store, setGlobalConfig, delGlobalConfig } from './config-getter';"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,aAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,YAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAE,cAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,aAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsH,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAFvGC,gCAAiB","ignoreList":[]}
|
package/global-config.ts
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
import fs from 'fs-extra';
|
2
|
+
import * as path from 'path';
|
3
|
+
|
4
|
+
import { GLOBAL_CONFIG, GLOBAL_CONFIG_FILE } from '@teambit/legacy.constants';
|
5
|
+
|
6
|
+
export function getGlobalConfigPath() {
|
7
|
+
return path.join(GLOBAL_CONFIG, GLOBAL_CONFIG_FILE);
|
8
|
+
}
|
9
|
+
|
10
|
+
export class GlobalConfig extends Map<string, string> {
|
11
|
+
toPlainObject() {
|
12
|
+
return mapToObject(this);
|
13
|
+
}
|
14
|
+
|
15
|
+
toJson() {
|
16
|
+
return JSON.stringify(this.toPlainObject(), null, 2);
|
17
|
+
}
|
18
|
+
|
19
|
+
write() {
|
20
|
+
return fs.outputFile(getGlobalConfigPath(), this.toJson());
|
21
|
+
}
|
22
|
+
|
23
|
+
writeSync() {
|
24
|
+
return fs.outputFileSync(getGlobalConfigPath(), this.toJson());
|
25
|
+
}
|
26
|
+
|
27
|
+
static loadSync(): GlobalConfig {
|
28
|
+
const configPath = getGlobalConfigPath();
|
29
|
+
if (!fs.existsSync(configPath)) {
|
30
|
+
const config = new GlobalConfig([]);
|
31
|
+
config.writeSync();
|
32
|
+
return config;
|
33
|
+
}
|
34
|
+
const contents = fs.readFileSync(configPath);
|
35
|
+
return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));
|
36
|
+
}
|
37
|
+
|
38
|
+
static async load(): Promise<GlobalConfig> {
|
39
|
+
const configPath = getGlobalConfigPath();
|
40
|
+
const exists = await fs.pathExists(configPath);
|
41
|
+
if (!exists) {
|
42
|
+
const config = new GlobalConfig([]);
|
43
|
+
await config.write();
|
44
|
+
return config;
|
45
|
+
}
|
46
|
+
const contents = await fs.readFile(configPath);
|
47
|
+
return new GlobalConfig(Object.entries(JSON.parse(contents.toString())));
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Cast a `Map` to a plain object.
|
53
|
+
* Keys are being casted by invoking `toString` on each key.
|
54
|
+
* @name mapToObject
|
55
|
+
* @param {Map} map to cast
|
56
|
+
* @returns {*} plain object
|
57
|
+
* @example
|
58
|
+
* ```js
|
59
|
+
* mapToObject(new Map([['key', 'val'], ['foo', 'bar']]));
|
60
|
+
* // => { key: 'val', foo: 'bar' }
|
61
|
+
* ```
|
62
|
+
*/
|
63
|
+
function mapToObject(map: Map<any, any>): { [key: string]: any } {
|
64
|
+
const object = {};
|
65
|
+
map.forEach((val, key) => {
|
66
|
+
object[key.toString()] = val;
|
67
|
+
});
|
68
|
+
return object;
|
69
|
+
}
|
package/index.ts
CHANGED
@@ -3,4 +3,4 @@ import { ConfigStoreAspect } from './config-store.aspect';
|
|
3
3
|
export type { ConfigStoreMain } from './config-store.main.runtime';
|
4
4
|
export default ConfigStoreAspect;
|
5
5
|
export { ConfigStoreAspect };
|
6
|
-
export { getConfig, getNumberFromConfig, listConfig, Store } from './config-getter';
|
6
|
+
export { getConfig, getNumberFromConfig, listConfig, Store, setGlobalConfig, delGlobalConfig } from './config-getter';
|
package/package.json
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/config-store",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
|
+
"homepage": "https://bit.cloud/teambit/harmony/config-store",
|
4
5
|
"main": "dist/index.js",
|
5
6
|
"componentId": {
|
7
|
+
"scope": "teambit.harmony",
|
6
8
|
"name": "config-store",
|
7
|
-
"version": "0.0.
|
8
|
-
"scope": "teambit.harmony"
|
9
|
+
"version": "0.0.3"
|
9
10
|
},
|
10
11
|
"dependencies": {
|
11
12
|
"chalk": "2.4.2",
|
12
13
|
"pad-right": "0.2.2",
|
13
14
|
"@teambit/gitconfig": "2.0.10",
|
14
15
|
"lodash": "4.17.21",
|
16
|
+
"fs-extra": "10.0.0",
|
15
17
|
"core-js": "^3.0.0",
|
16
18
|
"@babel/runtime": "7.20.0",
|
17
19
|
"@teambit/harmony": "0.4.6",
|
18
|
-
"@teambit/cli": "0.0.
|
19
|
-
"@teambit/legacy.constants": "0.0.11"
|
20
|
-
"@teambit/legacy.global-config": "0.0.11"
|
20
|
+
"@teambit/cli": "0.0.1123",
|
21
|
+
"@teambit/legacy.constants": "0.0.11"
|
21
22
|
},
|
22
23
|
"devDependencies": {
|
23
24
|
"@types/lodash": "4.14.165",
|
25
|
+
"@types/fs-extra": "9.0.7",
|
24
26
|
"@types/node": "12.20.4",
|
25
27
|
"@types/react": "^17.0.8",
|
26
28
|
"@types/react-dom": "^17.0.5",
|
File without changes
|