Skip to content

Commit

Permalink
Merge pull request #19 from adobe/HookLoading
Browse files Browse the repository at this point in the history
cleanup hook loading, allow modern js
  • Loading branch information
purplecabbage committed Apr 26, 2023
2 parents e07b921 + f0a59bd commit ca93bf4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/index.js
Expand Up @@ -34,6 +34,24 @@ const defaults = {
EXTENSIONS_CONFIG_KEY: 'extensions'
}

const HookKeys = [
'pre-app-build',
'post-app-build',
'build-actions',
'build-static',
'pre-app-deploy',
'post-app-deploy',
'deploy-actions',
'deploy-static',
'pre-app-undeploy',
'post-app-undeploy',
'undeploy-actions',
'undeploy-static',
'pre-app-run',
'post-app-run',
'serve-static'
]

const {
getCliEnv, /* function */
STAGE_ENV /* string */
Expand Down Expand Up @@ -323,27 +341,14 @@ function loadUserConfigLegacy (commonConfig) {
if (pkgjsonscripts) {
const hooks = {}
// https://www.adobe.io/apis/experienceplatform/project-firefly/docs.html#!AdobeDocs/project-firefly/master/guides/app-hooks.md
hooks['pre-app-build'] = pkgjsonscripts['pre-app-build']
hooks['post-app-build'] = pkgjsonscripts['post-app-build']
hooks['build-actions'] = pkgjsonscripts['build-actions']
hooks['build-static'] = pkgjsonscripts['build-static']
hooks['pre-app-deploy'] = pkgjsonscripts['pre-app-deploy']
hooks['post-app-deploy'] = pkgjsonscripts['post-app-deploy']
hooks['deploy-actions'] = pkgjsonscripts['deploy-actions']
hooks['deploy-static'] = pkgjsonscripts['deploy-static']
hooks['pre-app-undeploy'] = pkgjsonscripts['pre-app-undeploy']
hooks['post-app-undeploy'] = pkgjsonscripts['post-app-undeploy']
hooks['undeploy-actions'] = pkgjsonscripts['undeploy-actions']
hooks['undeploy-static'] = pkgjsonscripts['undeploy-static']
hooks['pre-app-run'] = pkgjsonscripts['pre-app-run']
hooks['post-app-run'] = pkgjsonscripts['post-app-run']
hooks['serve-static'] = pkgjsonscripts['serve-static']
// remove undefined hooks
Object.entries(hooks).forEach(([k, v]) => {
if (!hooks[k]) {
delete hooks[k]

HookKeys.forEach(hookKey => {
if (pkgjsonscripts[hookKey]) {
hooks[hookKey] = pkgjsonscripts[hookKey]
includeIndex[`${defaults.APPLICATION_CONFIG_KEY}.hooks.${hookKey}`] = { file: 'package.json', key: `scripts.${hookKey}` }
}
})

// todo: new val usingLegacyHooks:Boolean
if (Object.keys(hooks).length > 0) {
aioLogger.error('hooks in \'package.json\' are deprecated. Please move your hooks to \'app.config.yaml\' under the \'hooks\' key')
Expand Down
4 changes: 4 additions & 0 deletions test/.eslintrc.json
Expand Up @@ -7,5 +7,9 @@
},
"rules": {
"node/no-unpublished-require": 0
},
"extends": ["@adobe/eslint-config-aio-lib-config"],
"parserOptions": {
"ecmaVersion": "2020"
}
}

0 comments on commit ca93bf4

Please sign in to comment.