adapt-authoring-config 0.0.1 → 1.0.0
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/.eslintignore +1 -1
- package/.eslintrc +14 -14
- package/.github/ISSUE_TEMPLATE/bug_report.yml +55 -55
- package/.github/ISSUE_TEMPLATE/feature_request.yml +22 -22
- package/.github/dependabot.yml +11 -11
- package/.github/pull_request_template.md +25 -25
- package/.github/workflows/labelled_prs.yml +16 -16
- package/.github/workflows/new.yml +19 -19
- package/.github/workflows/releases.yml +25 -0
- package/README.md +1 -1
- package/adapt-authoring.json +12 -12
- package/artillery.yml +4 -4
- package/bin/confgen.js +132 -132
- package/docs/configure-environment.md +52 -52
- package/docs/defining-config.md +62 -62
- package/docs/plugins/configuration.js +70 -70
- package/docs/plugins/configuration.md +14 -14
- package/errors/errors.json +13 -13
- package/index.js +5 -5
- package/lib/ConfigModule.js +236 -236
- package/package.json +60 -25
- package/tests/configModule.spec.js +61 -61
- package/tests/configUtils.spec.js +34 -34
- package/tests/data/conf/config.schema.js +10 -10
- package/tests/data/incorrecttype/conf/config.schema.js +7 -7
- package/tests/data/invalid/conf/config.schema.js +8 -8
- package/tests/data/required/conf/config.schema.js +8 -8
- package/tests/data/testfile.json +3 -3
package/.eslintignore
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
node_modules
|
|
1
|
+
node_modules
|
package/.eslintrc
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": false,
|
|
4
|
-
"node": true,
|
|
5
|
-
"commonjs": false,
|
|
6
|
-
"es2020": true
|
|
7
|
-
},
|
|
8
|
-
"extends": [
|
|
9
|
-
"standard"
|
|
10
|
-
],
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": 2020
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": false,
|
|
4
|
+
"node": true,
|
|
5
|
+
"commonjs": false,
|
|
6
|
+
"es2020": true
|
|
7
|
+
},
|
|
8
|
+
"extends": [
|
|
9
|
+
"standard"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"ecmaVersion": 2020
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
name: Bug Report
|
|
2
|
-
description: File a bug report
|
|
3
|
-
labels: ["bug"]
|
|
4
|
-
body:
|
|
5
|
-
- type: markdown
|
|
6
|
-
attributes:
|
|
7
|
-
value: |
|
|
8
|
-
Thanks for taking the time to fill out this bug report!
|
|
9
|
-
- type: textarea
|
|
10
|
-
id: description
|
|
11
|
-
attributes:
|
|
12
|
-
label: What happened?
|
|
13
|
-
description: Please describe the issue
|
|
14
|
-
validations:
|
|
15
|
-
required: true
|
|
16
|
-
- type: textarea
|
|
17
|
-
id: expected
|
|
18
|
-
attributes:
|
|
19
|
-
label: Expected behaviour
|
|
20
|
-
description: Tell us what should have happened
|
|
21
|
-
- type: textarea
|
|
22
|
-
id: repro-steps
|
|
23
|
-
attributes:
|
|
24
|
-
label: Steps to reproduce
|
|
25
|
-
description: Tell us how to reproduce the issue
|
|
26
|
-
validations:
|
|
27
|
-
required: true
|
|
28
|
-
- type: input
|
|
29
|
-
id: aat-version
|
|
30
|
-
attributes:
|
|
31
|
-
label: Authoring tool version
|
|
32
|
-
description: What version of the Adapt authoring tool are you running?
|
|
33
|
-
validations:
|
|
34
|
-
required: true
|
|
35
|
-
- type: input
|
|
36
|
-
id: fw-version
|
|
37
|
-
attributes:
|
|
38
|
-
label: Framework version
|
|
39
|
-
description: What version of the Adapt framework are you running?
|
|
40
|
-
- type: dropdown
|
|
41
|
-
id: browsers
|
|
42
|
-
attributes:
|
|
43
|
-
label: What browsers are you seeing the problem on?
|
|
44
|
-
multiple: true
|
|
45
|
-
options:
|
|
46
|
-
- Firefox
|
|
47
|
-
- Chrome
|
|
48
|
-
- Safari
|
|
49
|
-
- Microsoft Edge
|
|
50
|
-
- type: textarea
|
|
51
|
-
id: logs
|
|
52
|
-
attributes:
|
|
53
|
-
label: Relevant log output
|
|
54
|
-
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
|
55
|
-
render: sh
|
|
1
|
+
name: Bug Report
|
|
2
|
+
description: File a bug report
|
|
3
|
+
labels: ["bug"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
Thanks for taking the time to fill out this bug report!
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: description
|
|
11
|
+
attributes:
|
|
12
|
+
label: What happened?
|
|
13
|
+
description: Please describe the issue
|
|
14
|
+
validations:
|
|
15
|
+
required: true
|
|
16
|
+
- type: textarea
|
|
17
|
+
id: expected
|
|
18
|
+
attributes:
|
|
19
|
+
label: Expected behaviour
|
|
20
|
+
description: Tell us what should have happened
|
|
21
|
+
- type: textarea
|
|
22
|
+
id: repro-steps
|
|
23
|
+
attributes:
|
|
24
|
+
label: Steps to reproduce
|
|
25
|
+
description: Tell us how to reproduce the issue
|
|
26
|
+
validations:
|
|
27
|
+
required: true
|
|
28
|
+
- type: input
|
|
29
|
+
id: aat-version
|
|
30
|
+
attributes:
|
|
31
|
+
label: Authoring tool version
|
|
32
|
+
description: What version of the Adapt authoring tool are you running?
|
|
33
|
+
validations:
|
|
34
|
+
required: true
|
|
35
|
+
- type: input
|
|
36
|
+
id: fw-version
|
|
37
|
+
attributes:
|
|
38
|
+
label: Framework version
|
|
39
|
+
description: What version of the Adapt framework are you running?
|
|
40
|
+
- type: dropdown
|
|
41
|
+
id: browsers
|
|
42
|
+
attributes:
|
|
43
|
+
label: What browsers are you seeing the problem on?
|
|
44
|
+
multiple: true
|
|
45
|
+
options:
|
|
46
|
+
- Firefox
|
|
47
|
+
- Chrome
|
|
48
|
+
- Safari
|
|
49
|
+
- Microsoft Edge
|
|
50
|
+
- type: textarea
|
|
51
|
+
id: logs
|
|
52
|
+
attributes:
|
|
53
|
+
label: Relevant log output
|
|
54
|
+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
|
55
|
+
render: sh
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
name: Feature request
|
|
2
|
-
description: Request a new feature
|
|
3
|
-
labels: ["enhancement"]
|
|
4
|
-
body:
|
|
5
|
-
- type: markdown
|
|
6
|
-
attributes:
|
|
7
|
-
value: |
|
|
8
|
-
Thanks for taking the time to request a new feature in the Adapt authoring tool! The Adapt team will consider all new feature requests, but unfortunately cannot commit to every one.
|
|
9
|
-
- type: textarea
|
|
10
|
-
id: description
|
|
11
|
-
attributes:
|
|
12
|
-
label: Feature description
|
|
13
|
-
description: Please describe your feature request
|
|
14
|
-
validations:
|
|
15
|
-
required: true
|
|
16
|
-
- type: checkboxes
|
|
17
|
-
id: contribute
|
|
18
|
-
attributes:
|
|
19
|
-
label: Can you work on this feature?
|
|
20
|
-
description: If you are able to commit your own time to work on this feature, it will greatly increase the liklihood of it being implemented by the core dev team. Otherwise, it will be triaged and prioritised alongside the core team's current priorities.
|
|
21
|
-
options:
|
|
22
|
-
- label: I can contribute
|
|
1
|
+
name: Feature request
|
|
2
|
+
description: Request a new feature
|
|
3
|
+
labels: ["enhancement"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
Thanks for taking the time to request a new feature in the Adapt authoring tool! The Adapt team will consider all new feature requests, but unfortunately cannot commit to every one.
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: description
|
|
11
|
+
attributes:
|
|
12
|
+
label: Feature description
|
|
13
|
+
description: Please describe your feature request
|
|
14
|
+
validations:
|
|
15
|
+
required: true
|
|
16
|
+
- type: checkboxes
|
|
17
|
+
id: contribute
|
|
18
|
+
attributes:
|
|
19
|
+
label: Can you work on this feature?
|
|
20
|
+
description: If you are able to commit your own time to work on this feature, it will greatly increase the liklihood of it being implemented by the core dev team. Otherwise, it will be triaged and prioritised alongside the core team's current priorities.
|
|
21
|
+
options:
|
|
22
|
+
- label: I can contribute
|
package/.github/dependabot.yml
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
-
# package ecosystems to update and where the package manifests are located.
|
|
3
|
-
# Please see the documentation for all configuration options:
|
|
4
|
-
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
-
|
|
6
|
-
version: 2
|
|
7
|
-
updates:
|
|
8
|
-
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
-
directory: "/" # Location of package manifests
|
|
10
|
-
schedule:
|
|
11
|
-
interval: "weekly"
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
[//]: # (Please title your PR according to eslint commit conventions)
|
|
2
|
-
[//]: # (See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint#eslint-convention for details)
|
|
3
|
-
|
|
4
|
-
[//]: # (Add a link to the original issue)
|
|
5
|
-
|
|
6
|
-
[//]: # (Delete as appropriate)
|
|
7
|
-
### Fix
|
|
8
|
-
* A sentence describing each fix
|
|
9
|
-
|
|
10
|
-
### Update
|
|
11
|
-
* A sentence describing each udpate
|
|
12
|
-
|
|
13
|
-
### New
|
|
14
|
-
* A sentence describing each new feature
|
|
15
|
-
|
|
16
|
-
### Breaking
|
|
17
|
-
* A sentence describing each breaking change
|
|
18
|
-
|
|
19
|
-
[//]: # (List appropriate steps for testing if needed)
|
|
20
|
-
### Testing
|
|
21
|
-
1. Steps for testing
|
|
22
|
-
|
|
23
|
-
[//]: # (Mention any other dependencies)
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
[//]: # (Please title your PR according to eslint commit conventions)
|
|
2
|
+
[//]: # (See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint#eslint-convention for details)
|
|
3
|
+
|
|
4
|
+
[//]: # (Add a link to the original issue)
|
|
5
|
+
|
|
6
|
+
[//]: # (Delete as appropriate)
|
|
7
|
+
### Fix
|
|
8
|
+
* A sentence describing each fix
|
|
9
|
+
|
|
10
|
+
### Update
|
|
11
|
+
* A sentence describing each udpate
|
|
12
|
+
|
|
13
|
+
### New
|
|
14
|
+
* A sentence describing each new feature
|
|
15
|
+
|
|
16
|
+
### Breaking
|
|
17
|
+
* A sentence describing each breaking change
|
|
18
|
+
|
|
19
|
+
[//]: # (List appropriate steps for testing if needed)
|
|
20
|
+
### Testing
|
|
21
|
+
1. Steps for testing
|
|
22
|
+
|
|
23
|
+
[//]: # (Mention any other dependencies)
|
|
24
|
+
|
|
25
|
+
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
name: Add labelled PRs to project
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
types: [ labeled ]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
add-to-project:
|
|
9
|
-
if: ${{ github.event.label.name == 'dependencies' }}
|
|
10
|
-
name: Add to main project
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/add-to-project@v0.1.0
|
|
14
|
-
with:
|
|
15
|
-
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
16
|
-
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
1
|
+
name: Add labelled PRs to project
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [ labeled ]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
add-to-project:
|
|
9
|
+
if: ${{ github.event.label.name == 'dependencies' }}
|
|
10
|
+
name: Add to main project
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/add-to-project@v0.1.0
|
|
14
|
+
with:
|
|
15
|
+
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
16
|
+
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
name: Add to main project
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
issues:
|
|
5
|
-
types:
|
|
6
|
-
- opened
|
|
7
|
-
pull_request:
|
|
8
|
-
types:
|
|
9
|
-
- opened
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
add-to-project:
|
|
13
|
-
name: Add to main project
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/add-to-project@v0.1.0
|
|
17
|
-
with:
|
|
18
|
-
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
19
|
-
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
1
|
+
name: Add to main project
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types:
|
|
6
|
+
- opened
|
|
7
|
+
pull_request:
|
|
8
|
+
types:
|
|
9
|
+
- opened
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
add-to-project:
|
|
13
|
+
name: Add to main project
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/add-to-project@v0.1.0
|
|
17
|
+
with:
|
|
18
|
+
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
19
|
+
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
jobs:
|
|
7
|
+
release:
|
|
8
|
+
name: Release
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout
|
|
12
|
+
uses: actions/checkout@v3
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
- name: Setup Node.js
|
|
16
|
+
uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 'lts/*'
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: npm ci
|
|
21
|
+
- name: Release
|
|
22
|
+
env:
|
|
23
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
24
|
+
NPM_TOKEN: ${{ secrets.AAT_NPM_TOKEN }}
|
|
25
|
+
run: npx semantic-release
|
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
adapt-authoring-config
|
|
1
|
+
adapt-authoring-config
|
package/adapt-authoring.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"essentialType": "config",
|
|
3
|
-
"documentation": {
|
|
4
|
-
"enable": true,
|
|
5
|
-
"manualPlugins": ["docs/plugins/configuration.js"],
|
|
6
|
-
"manualPages": {
|
|
7
|
-
"configuration.md": "reference",
|
|
8
|
-
"configure-environment.md": "getting-started",
|
|
9
|
-
"defining-config.md": "basics"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"essentialType": "config",
|
|
3
|
+
"documentation": {
|
|
4
|
+
"enable": true,
|
|
5
|
+
"manualPlugins": ["docs/plugins/configuration.js"],
|
|
6
|
+
"manualPages": {
|
|
7
|
+
"configuration.md": "reference",
|
|
8
|
+
"configure-environment.md": "getting-started",
|
|
9
|
+
"defining-config.md": "basics"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
package/artillery.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
scenarios:
|
|
2
|
-
- flow:
|
|
3
|
-
- get:
|
|
4
|
-
url: "/config"
|
|
1
|
+
scenarios:
|
|
2
|
+
- flow:
|
|
3
|
+
- get:
|
|
4
|
+
url: "/config"
|
package/bin/confgen.js
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Generates a template config file which can be populated with required values.
|
|
4
|
-
* @param {String} [environment] The enviroment to write the config for
|
|
5
|
-
* @param {String} --defaults Will include default values
|
|
6
|
-
* @param {String} --replace Will override any existing values
|
|
7
|
-
* @param {String} --update Will update existing configuration with any missing values
|
|
8
|
-
*/
|
|
9
|
-
import fs from 'fs/promises'
|
|
10
|
-
import { globSync } from 'glob'
|
|
11
|
-
import path from 'path'
|
|
12
|
-
import { pathToFileURL } from 'url'
|
|
13
|
-
import { Utils } from 'adapt-authoring-core'
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
defaults: useDefaults,
|
|
17
|
-
params: [env],
|
|
18
|
-
replace: replaceExisting,
|
|
19
|
-
update: updateExisting
|
|
20
|
-
} = Utils.getArgs()
|
|
21
|
-
const NODE_ENV = env || process.env.NODE_ENV
|
|
22
|
-
const confDir = path.resolve(path.join(process.cwd(), 'conf'))
|
|
23
|
-
const outpath = path.join(confDir, `${NODE_ENV}.config.js`)
|
|
24
|
-
const configJson = {}
|
|
25
|
-
|
|
26
|
-
async function init () {
|
|
27
|
-
if (!NODE_ENV) {
|
|
28
|
-
return console.log('ERROR: NODE_ENV must be specified\n')
|
|
29
|
-
}
|
|
30
|
-
if (replaceExisting && updateExisting) {
|
|
31
|
-
return console.log('ERROR: --update and --replace cannot both be specified, please choose one and run the utility again')
|
|
32
|
-
}
|
|
33
|
-
if (useDefaults) {
|
|
34
|
-
console.log('Default values will be included')
|
|
35
|
-
}
|
|
36
|
-
let isExistingConfig = false
|
|
37
|
-
let existingConfig
|
|
38
|
-
try {
|
|
39
|
-
existingConfig = (await import(pathToFileURL(outpath))).default
|
|
40
|
-
isExistingConfig = true
|
|
41
|
-
} catch (e) {
|
|
42
|
-
console.log(`No config found for NODE_ENV '${NODE_ENV}'. File will be written to ${outpath}\n`)
|
|
43
|
-
}
|
|
44
|
-
if (isExistingConfig) {
|
|
45
|
-
const msg = `Config already exists for NODE_ENV '${NODE_ENV}'. `
|
|
46
|
-
if (replaceExisting) {
|
|
47
|
-
console.log(`${msg}All existing values will be replaced.`)
|
|
48
|
-
} else if (updateExisting) {
|
|
49
|
-
console.log(`${msg}Any missing values will be added.`)
|
|
50
|
-
Object.assign(configJson, existingConfig)
|
|
51
|
-
} else {
|
|
52
|
-
return console.log(`${msg}Must specifiy --replace or --update to make changes.`)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
await generateConfig()
|
|
57
|
-
try {
|
|
58
|
-
await fs.mkdir(confDir, { recursive: true })
|
|
59
|
-
} catch (e) {
|
|
60
|
-
if (e.code !== 'EEXIST') throw e
|
|
61
|
-
}
|
|
62
|
-
await fs.writeFile(outpath, `export default ${JSON.stringify(configJson, null, 2)};`)
|
|
63
|
-
|
|
64
|
-
console.log(`Config file written successfully to ${outpath}.\n`)
|
|
65
|
-
|
|
66
|
-
logRequired()
|
|
67
|
-
} catch (e) {
|
|
68
|
-
console.log(`ERROR: Failed to write ${outpath}\n${e}`)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function logRequired () {
|
|
73
|
-
const requiredAttrs = []
|
|
74
|
-
Object.entries(configJson).forEach(([name, config]) => {
|
|
75
|
-
Object.entries(config).forEach(([key, value]) => value === null && requiredAttrs.push(`${name}.${key}`))
|
|
76
|
-
})
|
|
77
|
-
if (requiredAttrs.length) {
|
|
78
|
-
console.log('Note: the following required attributes have been given a value of null and must be set for the application to run:\n')
|
|
79
|
-
console.log(requiredAttrs.join('\n'))
|
|
80
|
-
console.log('')
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function getDeps () {
|
|
85
|
-
try {
|
|
86
|
-
const depRoot = `${process.cwd()}/node_modules/`.replaceAll(path.sep, path.posix.sep)
|
|
87
|
-
return globSync(`${depRoot}**/adapt-authoring.json`).map(f => {
|
|
88
|
-
const dirname = path.dirname(f)
|
|
89
|
-
return [dirname.replace(depRoot, ''), dirname]
|
|
90
|
-
})
|
|
91
|
-
} catch (e) {
|
|
92
|
-
console.log('Failed to load package', e)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function generateConfig () {
|
|
97
|
-
await Promise.all((await getDeps()).map(async ([name, dir]) => {
|
|
98
|
-
let schema
|
|
99
|
-
try {
|
|
100
|
-
schema = schema = JSON.parse(await fs.readFile(path.resolve(dir, 'conf/config.schema.json')))
|
|
101
|
-
} catch (e) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
if (!configJson[name]) {
|
|
105
|
-
configJson[name] = {}
|
|
106
|
-
}
|
|
107
|
-
storeDefaults(schema, configJson[name])
|
|
108
|
-
// remove any empty objects
|
|
109
|
-
Object.entries(configJson).forEach(([key, config]) => !Object.keys(config).length && delete configJson[key])
|
|
110
|
-
}))
|
|
111
|
-
}
|
|
112
|
-
function storeDefaults (schema, defaults = {}) {
|
|
113
|
-
return Object.entries(schema.properties).reduce((memo, [attr, config]) => {
|
|
114
|
-
if (config.type === 'object' && config.properties) {
|
|
115
|
-
return { ...memo, [attr]: storeDefaults(config, memo) }
|
|
116
|
-
}
|
|
117
|
-
config.required = schema?.required?.includes(attr) ?? false
|
|
118
|
-
const shouldUpdate = replaceExisting || !Object.prototype.hasOwnProperty.call(memo, attr)
|
|
119
|
-
const useDefault = useDefaults && Object.prototype.hasOwnProperty.call(config, 'default')
|
|
120
|
-
if (shouldUpdate && (useDefault || config.required)) {
|
|
121
|
-
memo[attr] = getValueForAttr(config)
|
|
122
|
-
}
|
|
123
|
-
return memo
|
|
124
|
-
}, defaults)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function getValueForAttr (config) {
|
|
128
|
-
if (config.required) return null
|
|
129
|
-
if (Object.prototype.hasOwnProperty.call(config, 'default')) return config.default
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
init()
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Generates a template config file which can be populated with required values.
|
|
4
|
+
* @param {String} [environment] The enviroment to write the config for
|
|
5
|
+
* @param {String} --defaults Will include default values
|
|
6
|
+
* @param {String} --replace Will override any existing values
|
|
7
|
+
* @param {String} --update Will update existing configuration with any missing values
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'fs/promises'
|
|
10
|
+
import { globSync } from 'glob'
|
|
11
|
+
import path from 'path'
|
|
12
|
+
import { pathToFileURL } from 'url'
|
|
13
|
+
import { Utils } from 'adapt-authoring-core'
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
defaults: useDefaults,
|
|
17
|
+
params: [env],
|
|
18
|
+
replace: replaceExisting,
|
|
19
|
+
update: updateExisting
|
|
20
|
+
} = Utils.getArgs()
|
|
21
|
+
const NODE_ENV = env || process.env.NODE_ENV
|
|
22
|
+
const confDir = path.resolve(path.join(process.cwd(), 'conf'))
|
|
23
|
+
const outpath = path.join(confDir, `${NODE_ENV}.config.js`)
|
|
24
|
+
const configJson = {}
|
|
25
|
+
|
|
26
|
+
async function init () {
|
|
27
|
+
if (!NODE_ENV) {
|
|
28
|
+
return console.log('ERROR: NODE_ENV must be specified\n')
|
|
29
|
+
}
|
|
30
|
+
if (replaceExisting && updateExisting) {
|
|
31
|
+
return console.log('ERROR: --update and --replace cannot both be specified, please choose one and run the utility again')
|
|
32
|
+
}
|
|
33
|
+
if (useDefaults) {
|
|
34
|
+
console.log('Default values will be included')
|
|
35
|
+
}
|
|
36
|
+
let isExistingConfig = false
|
|
37
|
+
let existingConfig
|
|
38
|
+
try {
|
|
39
|
+
existingConfig = (await import(pathToFileURL(outpath))).default
|
|
40
|
+
isExistingConfig = true
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.log(`No config found for NODE_ENV '${NODE_ENV}'. File will be written to ${outpath}\n`)
|
|
43
|
+
}
|
|
44
|
+
if (isExistingConfig) {
|
|
45
|
+
const msg = `Config already exists for NODE_ENV '${NODE_ENV}'. `
|
|
46
|
+
if (replaceExisting) {
|
|
47
|
+
console.log(`${msg}All existing values will be replaced.`)
|
|
48
|
+
} else if (updateExisting) {
|
|
49
|
+
console.log(`${msg}Any missing values will be added.`)
|
|
50
|
+
Object.assign(configJson, existingConfig)
|
|
51
|
+
} else {
|
|
52
|
+
return console.log(`${msg}Must specifiy --replace or --update to make changes.`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await generateConfig()
|
|
57
|
+
try {
|
|
58
|
+
await fs.mkdir(confDir, { recursive: true })
|
|
59
|
+
} catch (e) {
|
|
60
|
+
if (e.code !== 'EEXIST') throw e
|
|
61
|
+
}
|
|
62
|
+
await fs.writeFile(outpath, `export default ${JSON.stringify(configJson, null, 2)};`)
|
|
63
|
+
|
|
64
|
+
console.log(`Config file written successfully to ${outpath}.\n`)
|
|
65
|
+
|
|
66
|
+
logRequired()
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.log(`ERROR: Failed to write ${outpath}\n${e}`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function logRequired () {
|
|
73
|
+
const requiredAttrs = []
|
|
74
|
+
Object.entries(configJson).forEach(([name, config]) => {
|
|
75
|
+
Object.entries(config).forEach(([key, value]) => value === null && requiredAttrs.push(`${name}.${key}`))
|
|
76
|
+
})
|
|
77
|
+
if (requiredAttrs.length) {
|
|
78
|
+
console.log('Note: the following required attributes have been given a value of null and must be set for the application to run:\n')
|
|
79
|
+
console.log(requiredAttrs.join('\n'))
|
|
80
|
+
console.log('')
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function getDeps () {
|
|
85
|
+
try {
|
|
86
|
+
const depRoot = `${process.cwd()}/node_modules/`.replaceAll(path.sep, path.posix.sep)
|
|
87
|
+
return globSync(`${depRoot}**/adapt-authoring.json`).map(f => {
|
|
88
|
+
const dirname = path.dirname(f)
|
|
89
|
+
return [dirname.replace(depRoot, ''), dirname]
|
|
90
|
+
})
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.log('Failed to load package', e)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function generateConfig () {
|
|
97
|
+
await Promise.all((await getDeps()).map(async ([name, dir]) => {
|
|
98
|
+
let schema
|
|
99
|
+
try {
|
|
100
|
+
schema = schema = JSON.parse(await fs.readFile(path.resolve(dir, 'conf/config.schema.json')))
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
if (!configJson[name]) {
|
|
105
|
+
configJson[name] = {}
|
|
106
|
+
}
|
|
107
|
+
storeDefaults(schema, configJson[name])
|
|
108
|
+
// remove any empty objects
|
|
109
|
+
Object.entries(configJson).forEach(([key, config]) => !Object.keys(config).length && delete configJson[key])
|
|
110
|
+
}))
|
|
111
|
+
}
|
|
112
|
+
function storeDefaults (schema, defaults = {}) {
|
|
113
|
+
return Object.entries(schema.properties).reduce((memo, [attr, config]) => {
|
|
114
|
+
if (config.type === 'object' && config.properties) {
|
|
115
|
+
return { ...memo, [attr]: storeDefaults(config, memo) }
|
|
116
|
+
}
|
|
117
|
+
config.required = schema?.required?.includes(attr) ?? false
|
|
118
|
+
const shouldUpdate = replaceExisting || !Object.prototype.hasOwnProperty.call(memo, attr)
|
|
119
|
+
const useDefault = useDefaults && Object.prototype.hasOwnProperty.call(config, 'default')
|
|
120
|
+
if (shouldUpdate && (useDefault || config.required)) {
|
|
121
|
+
memo[attr] = getValueForAttr(config)
|
|
122
|
+
}
|
|
123
|
+
return memo
|
|
124
|
+
}, defaults)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getValueForAttr (config) {
|
|
128
|
+
if (config.required) return null
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(config, 'default')) return config.default
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
init()
|