@dbpath/environments
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -7,4 +7,4 @@ import { ColumnDefn, ErrorsAnd, NameAnd, NameAndValidator } from "@dbpath/utils"; | ||
} | ||
export declare function currentEnvName(cwd: string, env: string | undefined): ErrorsAnd<string>; | ||
export declare function saveEnvName(cwd: string, env: string): ErrorsAnd<void>; | ||
export declare function currentEnvName(cwd: string, marker: string, env: string | undefined, cleanE: NameAnd<CleanEnvironment>): ErrorsAnd<string>; | ||
export declare function saveEnvName(cwd: string, marker: string, env: string): ErrorsAnd<void>; | ||
export interface EnvAndName { | ||
@@ -14,3 +14,3 @@ env: CleanEnvironment; | ||
} | ||
export declare function currentEnvironment(cwd: string, envs: NameAnd<CleanEnvironment>, env: string | undefined): ErrorsAnd<EnvAndName>; | ||
export declare function currentEnvironment(cwd: string, marker: string, envs: NameAnd<CleanEnvironment>, env: string | undefined): ErrorsAnd<EnvAndName>; | ||
export interface CleanEnvironment extends Required<Environment> { | ||
@@ -17,0 +17,0 @@ name: string; |
@@ -41,26 +41,17 @@ "use strict"; | ||
const fs = __importStar(require("fs")); | ||
const stateFileName = '.db-auto.state.json'; | ||
function currentEnvName(cwd, env) { | ||
const stateFileName = '.dbpath.state.json'; | ||
function currentEnvName(cwd, marker, env, cleanE) { | ||
if (env) | ||
return env; | ||
const dir = (0, files_1.findDirectoryHoldingFileOrError)(cwd, 'db-auto.json'); | ||
if ((0, utils_1.hasErrors)(dir)) | ||
return dir; | ||
const envFile = Path.join(dir, stateFileName); | ||
try { | ||
const contents = fs.readFileSync(envFile).toString('utf-8'); | ||
try { | ||
return JSON.parse(contents).currentEnvironment; | ||
} | ||
catch (e) { | ||
return [`Error parsing ${envFile}: ${e.message}`]; | ||
} | ||
} | ||
catch (e) { | ||
const contents = (0, files_1.loadFileInDirectory)(cwd, marker, stateFileName); | ||
if ((0, utils_1.hasErrors)(contents)) | ||
return 'dev'; | ||
} | ||
const foundEnv = contents.currentEnvironment; | ||
if (cleanE[foundEnv]) | ||
return foundEnv; | ||
return [`Environment ${foundEnv} not found. Legal values are ${Object.keys(cleanE).sort().join(', ')}`]; | ||
} | ||
exports.currentEnvName = currentEnvName; | ||
function saveEnvName(cwd, env) { | ||
const dir = (0, files_1.findDirectoryHoldingFileOrError)(cwd, 'db-auto.json'); | ||
function saveEnvName(cwd, marker, env) { | ||
const dir = (0, files_1.findDirectoryHoldingFileOrError)(cwd, marker); | ||
if ((0, utils_1.hasErrors)(dir)) | ||
@@ -78,4 +69,4 @@ return dir; | ||
exports.saveEnvName = saveEnvName; | ||
function currentEnvironment(cwd, envs, env) { | ||
return (0, utils_1.mapErrors)(currentEnvName(cwd, env), (envName) => { | ||
function currentEnvironment(cwd, marker, envs, env) { | ||
return (0, utils_1.mapErrors)(currentEnvName(cwd, marker, env, envs), (envName) => { | ||
const env = envs[envName]; | ||
@@ -82,0 +73,0 @@ if (env) |
{ | ||
"name": "@dbpath/environments", | ||
"description": "", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"main": "dist/index", | ||
@@ -20,6 +20,7 @@ "types": "dist/index", | ||
"dependencies": { | ||
"@dbpath/utils": "0.1.1", | ||
"@dbpath/postgres": "0.1.1", | ||
"@dbpath/mysql": "0.1.1", | ||
"@dbpath/oracle": "0.1.1" | ||
"@dbpath/utils": "0.2.0", | ||
"@dbpath/files": "0.2.0", | ||
"@dbpath/postgres": "0.2.0", | ||
"@dbpath/mysql": "0.2.0", | ||
"@dbpath/oracle": "0.2.0" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15105
5
270
+ Added@dbpath/files@0.2.0
+ Added@dbpath/config@0.2.0(transitive)
+ Added@dbpath/dal@0.2.0(transitive)
+ Added@dbpath/files@0.2.0(transitive)
+ Added@dbpath/mysql@0.2.0(transitive)
+ Added@dbpath/oracle@0.2.0(transitive)
+ Added@dbpath/postgres@0.2.0(transitive)
+ Added@dbpath/utils@0.2.0(transitive)
- Removed@dbpath/config@0.1.1(transitive)
- Removed@dbpath/dal@0.1.1(transitive)
- Removed@dbpath/mysql@0.1.1(transitive)
- Removed@dbpath/oracle@0.1.1(transitive)
- Removed@dbpath/postgres@0.1.1(transitive)
- Removed@dbpath/utils@0.1.1(transitive)
Updated@dbpath/mysql@0.2.0
Updated@dbpath/oracle@0.2.0
Updated@dbpath/postgres@0.2.0
Updated@dbpath/utils@0.2.0