Skip to content

Commit 74848c8

Browse files
committed
Improve the way to apply public-dir
1 parent a58ae3c commit 74848c8

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Diff for: src/init-app.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const defaultOptions: AppOptions = {
1717
'public-dir': undefined,
1818
'static-dir': undefined,
1919
spa: undefined,
20-
'not-found-page': (options) => {
21-
return options['public-dir'] + '/404.html';
22-
},
20+
'not-found-page': '[public-dir]/404.html',
2321
'auto-index': [ 'index.html', 'index.htm' ],
2422
'auto-ext': [ '.html', '.htm' ],
2523
author: '[email protected]',
@@ -42,6 +40,13 @@ function pickKeys(keys: string[], object: Record<string, any>): Record<string, a
4240

4341
}
4442

43+
function applyPublicDir(optionValue: string | null | undefined, publicDir: string) {
44+
if(optionValue == null) {
45+
return optionValue;
46+
}
47+
return optionValue.replace('[public-dir]', publicDir);
48+
}
49+
4550
export function initApp(commandLineValues: CommandLineOptions) {
4651

4752
let options: AppOptions = defaultOptions;
@@ -75,11 +80,6 @@ export function initApp(commandLineValues: CommandLineOptions) {
7580
...pickKeys(['public-dir', 'static-dir', 'spa', 'not-found-page', 'auto-index', 'auto-ext', 'author', 'name', 'description', 'service-id'], commandLineValues)
7681
};
7782

78-
if(typeof options['not-found-page'] === 'function') {
79-
// Apply function for this one
80-
options['not-found-page'] = options['not-found-page'](options);
81-
}
82-
8383
if(preset != null) {
8484
if(!preset.check(packageJson, options)) {
8585
console.log("Failed preset check.");
@@ -98,11 +98,11 @@ export function initApp(commandLineValues: CommandLineOptions) {
9898
}
9999
const publicDir = path.resolve(PUBLIC_DIR);
100100

101-
const BUILD_STATIC_DIR = options['static-dir'];
101+
const BUILD_STATIC_DIR = applyPublicDir(options['static-dir'], PUBLIC_DIR);
102102
const buildStaticDir = BUILD_STATIC_DIR != null ? path.resolve(BUILD_STATIC_DIR) : null;
103103

104-
const spa = options['spa'];
105-
const notFoundPage = options['not-found-page'];
104+
const spa = applyPublicDir(options['spa'], PUBLIC_DIR);
105+
const notFoundPage = applyPublicDir(options['not-found-page'], PUBLIC_DIR);
106106

107107
const autoIndex = options['auto-index'];
108108
const autoExt = options['auto-ext'];

Diff for: src/presets/implementations/create-react-app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class CreateReactAppPreset implements IPresetBase {
44
name = 'Create React App';
55
defaultOptions = {
66
'public-dir': './build',
7-
'static-dir': './build/static',
7+
'static-dir': '[public-dir]/static',
88
name: 'my-create-react-app',
99
description: 'Compute@Edge static site from create-react-app',
1010
};

Diff for: src/presets/preset-base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type AppOptions = {
22
'public-dir': string | undefined,
33
'static-dir': string | undefined,
44
spa: string | null | undefined,
5-
'not-found-page': string | null | ((options: AppOptions) => string | undefined) | undefined,
5+
'not-found-page': string | null | undefined,
66
'auto-index': string[] | null | undefined,
77
'auto-ext': string[] | null | undefined,
88
name: string,

0 commit comments

Comments
 (0)