Skip to content

Commit

Permalink
Merge branch 'master' into buildcmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Himavanth authored Dec 2, 2020
2 parents a932b88 + 972de94 commit 4bbb837
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
44 changes: 26 additions & 18 deletions src/lib/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ governing permissions and limitations under the License.
const path = require('path')
const yaml = require('js-yaml')
const fs = require('fs-extra')
const chalk = require('chalk')
const utils = require('./app-helper')
const aioConfig = require('@adobe/aio-lib-core-config')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:config-loader', { provider: 'debug' })
Expand Down Expand Up @@ -87,14 +88,21 @@ module.exports = () => {
// load aio config
aioConfig.reload()
const userConfig = aioConfig.get() || {}
userConfig.cna = userConfig.cna || {}
userConfig.app = userConfig.app || {}

// userConfig.cna deprecation warning
if (userConfig.cna !== undefined) {
aioLogger.log(chalk.redBright(chalk.bold('The config variable \'cna\' has been deprecated. Please update it with \'app\' instead in your .aio configuration file.')))
Object.assign(userConfig.app, userConfig.cna)
}

config.imsOrgId = aioConfig.get(AIO_CONFIG_IMS_ORG_ID)

// 1. paths
// 1.a defaults
const actions = path.normalize(userConfig.cna.actions || 'actions')
const dist = path.normalize(userConfig.cna.dist || 'dist')
const web = path.normalize(userConfig.cna.web || 'web-src')
const actions = path.normalize(userConfig.app.actions || 'actions')
const dist = path.normalize(userConfig.app.dist || 'dist')
const web = path.normalize(userConfig.app.web || 'web-src')
// 1.b set config paths
config.actions.src = _abs(actions) // todo this should be linked with manifest.yml paths
config.actions.dist = _abs(path.join(dist, actions))
Expand All @@ -108,13 +116,13 @@ module.exports = () => {
config.manifest.src = _abs('manifest.yml')

// set s3 creds if specified
config.s3.creds = (typeof userConfig.cna === 'object') &&
(userConfig.cna.awsaccesskeyid &&
userConfig.cna.awssecretaccesskey &&
userConfig.cna.s3bucket) && {
accessKeyId: userConfig.cna.awsaccesskeyid,
secretAccessKey: userConfig.cna.awssecretaccesskey,
params: { Bucket: userConfig.cna.s3bucket }
config.s3.creds = (typeof userConfig.app === 'object') &&
(userConfig.app.awsaccesskeyid &&
userConfig.app.awssecretaccesskey &&
userConfig.app.s3bucket) && {
accessKeyId: userConfig.app.awsaccesskeyid,
secretAccessKey: userConfig.app.awssecretaccesskey,
params: { Bucket: userConfig.app.s3bucket }
}

// set for general build artifacts
Expand All @@ -135,7 +143,7 @@ module.exports = () => {
const packagejson = JSON.parse(fs.readFileSync(_abs('package.json')))
// semver starts at 0.1.0
config.app.version = packagejson.version || '0.1.0'
config.app.name = getModuleName(packagejson) || 'unnamed-cna'
config.app.name = getModuleName(packagejson) || 'unnamed-app'

// 4. Load manifest config
if (config.app.hasBackend) {
Expand All @@ -154,14 +162,14 @@ module.exports = () => {
config.ow.apiversion = config.ow.apiversion || 'v1'
config.ow.package = `${config.app.name}-${config.app.version}`
config.s3.folder = config.ow.namespace // this becomes the root only /
config.s3.tvmUrl = userConfig.cna.tvmurl || defaultTvmUrl
config.s3.tvmUrl = userConfig.app.tvmurl || defaultTvmUrl
// only provide a hostname if it was given or if the app uses the tvm
config.app.hostname = userConfig.cna.hostname || defaultAioHostname
config.app.hostname = userConfig.app.hostname || defaultAioHostname
// cache control config
config.app.htmlCacheDuration = userConfig.cna.htmlcacheduration || defaultHTMLCacheDuration
config.app.jsCacheDuration = userConfig.cna.jscacheduration || defaultJSCacheDuration
config.app.cssCacheDuration = userConfig.cna.csscacheduration || defaultCSSCacheDuration
config.app.imageCacheDuration = userConfig.cna.imagecacheduration || defaultImageCacheDuration
config.app.htmlCacheDuration = userConfig.app.htmlcacheduration || defaultHTMLCacheDuration
config.app.jsCacheDuration = userConfig.app.jscacheduration || defaultJSCacheDuration
config.app.cssCacheDuration = userConfig.app.csscacheduration || defaultCSSCacheDuration
config.app.imageCacheDuration = userConfig.app.imagecacheduration || defaultImageCacheDuration

return config
}
Expand Down
16 changes: 13 additions & 3 deletions test/commands/lib/config-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ global.mockFs()
const loadConfig = require('../../../src/lib/config-loader')
const mockAIOConfig = require('@adobe/aio-lib-core-config')
const yaml = require('js-yaml')
const chalk = require('chalk')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:config-loader', { provider: 'debug' })
aioLogger.log = jest.fn()

describe('load config', () => {
let config
Expand All @@ -35,14 +38,21 @@ describe('load config', () => {
expect(config.imsOrgId).toBe(undefined)
})

test('show warning for .cna config', async () => {
mockAIOConfig.get.mockReturnValue({ cna: { web: 'new-web-src' } })
config = loadConfig()
expect(aioLogger.log).toBeCalledWith(chalk.redBright(chalk.bold('The config variable \'cna\' has been deprecated. Please update it with \'app\' instead in your .aio configuration file.')))
expect(config.web.src).toMatch(/new-web-src/)
})

test('with s3 creds in config', async () => {
mockAIOConfig.get.mockReturnValue(global.fakeConfig.creds)
config = loadConfig()
expect(config.s3.creds).toEqual({
accessKeyId: global.fakeConfig.creds.cna.awsaccesskeyid,
secretAccessKey: global.fakeConfig.creds.cna.awssecretaccesskey,
accessKeyId: global.fakeConfig.creds.app.awsaccesskeyid,
secretAccessKey: global.fakeConfig.creds.app.awssecretaccesskey,
params: {
Bucket: global.fakeConfig.creds.cna.s3bucket
Bucket: global.fakeConfig.creds.app.s3bucket
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ global.fakeConfig = {
namespace: 'fake_ns',
auth: 'fake:auth'
},
cna: {
app: {
s3bucket: 'customBucket',
awsaccesskeyid: 'fakeAwsKeyId',
awssecretaccesskey: 'fakeAwsSecretKey'
}
},
cna: {
app: {
htmlCacheDuration: 60,
jsCacheDuration: 604800,
cssCacheDuration: 604800,
Expand Down

0 comments on commit 4bbb837

Please sign in to comment.