nuxt-typo3-config
Advanced tools
Comparing version 1.0.0 to 1.1.0
module.exports = { | ||
env: { | ||
node: true, | ||
"jest/globals": true | ||
'jest/globals': true | ||
}, | ||
plugins: ['jest'], | ||
extends: ['macopedia'], | ||
@@ -7,0 +8,0 @@ rules: { |
module.exports = { | ||
presets: [['@babel/preset-env', {targets: {node: 'current'}}]], | ||
}; | ||
presets: [['@babel/preset-env', { targets: { node: 'current' } }]] | ||
} |
14
index.js
import path from 'path' | ||
import fs from 'fs' | ||
import https from 'https' | ||
import defu from 'defu' | ||
const debug = process.env.ENV_CONFIG_DEBUG | ||
@@ -12,9 +13,8 @@ | ||
*/ | ||
export default function loadConfiguration (config = 'production', dir = 'config') { | ||
export default function loadConfiguration ( | ||
config = 'production', | ||
dir = 'config' | ||
) { | ||
const envConfig = process.env.ENV_CONFIG || config | ||
const envConfigPath = path.resolve( | ||
process.cwd(), | ||
dir, | ||
`.env.${envConfig}` | ||
) | ||
const envConfigPath = path.resolve(process.cwd(), dir, `.env.${envConfig}`) | ||
@@ -89,3 +89,3 @@ const jsonConfigPath = path.resolve( | ||
return Object.assign(env, typo3Config) | ||
return defu(env, typo3Config) | ||
} | ||
@@ -92,0 +92,0 @@ |
{ | ||
"name": "nuxt-typo3-config", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -17,2 +17,3 @@ "license": "MIT", | ||
"babel-jest": "^27.1.1", | ||
"defu": "^5.0.0", | ||
"eslint": "^7.32.0", | ||
@@ -22,4 +23,5 @@ "eslint-config-macopedia": "^0.2.0", | ||
"jest": "^27.1.1", | ||
"nock": "^13.1.3", | ||
"typescript": "^4.4.2" | ||
} | ||
} |
import loadConfiguration, { getConfiguration } from '../index' | ||
import path from 'path' | ||
import './fixture/apimock' | ||
@@ -20,12 +21,27 @@ it('should get production config by default ', () => { | ||
it('should get configuration from TYPO3 API', async () => { | ||
const env = await getConfiguration(undefined, path.resolve(__dirname, 'fixture')) | ||
const env = await getConfiguration( | ||
undefined, | ||
path.resolve(__dirname, 'fixture') | ||
) | ||
expect(env.typo3.domains).toHaveLength(1) | ||
}) | ||
it('should get configuration from TYPO3 API and merge with local json file', async () => { | ||
const env = await getConfiguration( | ||
'stage', | ||
path.resolve(__dirname, 'fixture') | ||
) | ||
expect(env.typo3.domains).toHaveLength(2) | ||
}) | ||
it('should throw error when config doesnt exist', async () => { | ||
try { | ||
loadConfiguration('notexistconfiguration', path.resolve(__dirname, 'fixture')) | ||
loadConfiguration( | ||
'notexistconfiguration', | ||
path.resolve(__dirname, 'fixture') | ||
) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error); | ||
} | ||
}) | ||
expect(error).toBeInstanceOf(Error) | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8097
10
192
10