Skip to content

Commit ec8e4f1

Browse files
committed
Moved all configuration logic into createConfig.mjs, which validate and returns config. Note:
1. I added config file validation using a combination of ts-json-schema-generator (to generate a JSON schema from the ConfigFile type) and ajv (to validate that the config file matches it). This way we don’t need to include a bunch of custom validation logic for each config property. One trade-off here is that SmartDialerConfig isn’t based on the underlying Go code, so it could fall out of sync. If we convert all the scripts to TypeScript we can replace this with e.g. zod or ts-pattern (which I’m familiar with) by starting with a pattern and deriving both a type and validator function, rather than starting with the type and deriving a validator function. 2. To simplify things I made a decision to only accept two CLI arguments: config (for passing in custom config locations) and platform (to choose build platform without creating redundant platform-specific configs). This sidesteps the issues with e.g. passing in additionalDomains (do we accept a comma-separated list?) and smartDialerConfig (do we accept a JSON string then parse it?). 3. There are still two types: Config and ConfigFile. ConfigFile (used for config file validation) is based on Config, but with derived properties (entryDomain, domainList, and smartDialerConfigBase64) removed, and the remaining properties other than entryUrl optional. I don’t see any way to avoid this unless we require that the config file contains all config properties (including the derived properties). Also note that I renamed these from "BuildConfig*" to "Config*". I think "Config" conveys "app maker config" given the name of the project, and having "build" or "make" in the type name might be more confusing since both could be read as a verb. 4. I tried replacing the derived properties with getters as suggested in [1], but to be compatible with the Handlebars template compilation [2] I think we would need to add a custom toJSON method to the class for the derived properties, which was making the class increasingly harder to read and understand vs. just outputting a config object including the derived properties as I did. IMO this is an acceptable trade-off given the config object isn’t really a user-facing thing, but let me know if there’s a better way here. [1]: #8 (comment) [2]: https://github.com/Jigsaw-Code/outline-app-maker/blob/7fa63ea3539a105e66d8ee43791166ed21c5bef9/wrapper_app_project/scripts/build.mjs#L107-L114
1 parent 7fa63ea commit ec8e4f1

File tree

10 files changed

+370
-272
lines changed

10 files changed

+370
-272
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.vscode/
3+
config.yaml
34
output/
45
node_modules/
56
tsconfig.tsbuildinfo

config-sample.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
additionalDomains:
2+
- medium.com
3+
appName: 'Jigsaw'
4+
entryUrl: 'https://jigsaw.google.com'
5+
smartDialerConfig:
6+
dns:
7+
- https:
8+
name: 9.9.9.9
9+
tls:
10+
- ''
11+
- split:1
12+
- split:2
13+
- tlsfrag:1

config.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

package-lock.json

Lines changed: 131 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"name": "outline-app-maker",
33
"dependencies": {
44
"@ngrok/ngrok": "1.4.1",
5+
"ajv": "^8.17.1",
56
"archiver": "^7.0.1",
67
"chalk": "^5.4.1",
78
"http-proxy": "^1.18.1",
89
"minimist": "^1.2.8",
910
"serve-handler": "6.1.6",
11+
"ts-json-schema-generator": "^2.4.0",
1012
"yaml": "^2.7.1"
1113
},
1214
"devDependencies": {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// We only use TSC for checking .mjs files
1111
"noEmit": true
1212
},
13-
"include": ["**/*.cjs", "**/*.mjs", "**/*.js"],
13+
"include": ["**/*.cjs", "**/*.mjs", "**/*.js", "**/*.ts"],
1414
"exclude": [
1515
"basic_navigator_example", // TODO: Remove this exclusion?
1616
"node_modules",

0 commit comments

Comments
 (0)