Skip to content

Commit 04b98fd

Browse files
committed
Allow specifying a Fastly Service ID
1 parent e7ac6d6 commit 04b98fd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const optionDefinitions: OptionDefinition[] = [
6363
{ name: 'name', type: String, },
6464
{ name: 'author', type: String, },
6565
{ name: 'description', type: String, },
66+
67+
// Fastly Service ID to be added to the fastly.toml that is generated.
68+
{ name: 'service-id', type: String },
6669
];
6770

6871
const commandLineValues = commandLineArgs(optionDefinitions);

src/init-app.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type AppOptions = {
2020
name: string,
2121
author: string,
2222
description: string,
23+
'service-id': string | undefined,
2324
};
2425

2526
type Preset = {
@@ -108,6 +109,7 @@ const defaultOptions: AppOptions = {
108109
author: '[email protected]',
109110
name: 'compute-js-static-site',
110111
description: 'Compute@Edge static site',
112+
'service-id': undefined,
111113
};
112114

113115
function pickKeys(keys: string[], object: Record<string, any>): Record<string, any> {
@@ -158,7 +160,7 @@ export function initApp(commandLineValues: CommandLineOptions) {
158160
options = {
159161
...options,
160162
...pickKeys(['author', 'name', 'description'], packageJson ?? {}),
161-
...pickKeys(['public-dir', 'static-dir', 'spa', 'not-found-page', 'auto-index', 'auto-ext', 'author', 'name', 'description'], commandLineValues)
163+
...pickKeys(['public-dir', 'static-dir', 'spa', 'not-found-page', 'auto-index', 'auto-ext', 'author', 'name', 'description', 'service-id'], commandLineValues)
162164
};
163165

164166
if(typeof options['not-found-page'] === 'function') {
@@ -241,6 +243,7 @@ export function initApp(commandLineValues: CommandLineOptions) {
241243
const author = options['author'];
242244
const name = options['name'];
243245
const description = options['description'];
246+
const fastlyServiceId = options['service-id'] as string | undefined;
244247

245248
let spaRel: string | null = spaFilename != null ? path.relative(path.resolve(), spaFilename) : null;
246249
if(spaRel != null && !spaRel.startsWith('..')) {
@@ -262,6 +265,7 @@ export function initApp(commandLineValues: CommandLineOptions) {
262265
console.log('name :', name);
263266
console.log('author :', author);
264267
console.log('description :', description);
268+
console.log('Service ID :', fastlyServiceId);
265269
console.log('');
266270

267271
console.log("Initializing Compute@Edge Application in " + computeJsDir + "...");
@@ -324,7 +328,7 @@ description = "${description}"
324328
language = "javascript"
325329
manifest_version = 2
326330
name = "${name}"
327-
service_id = ""
331+
service_id = "${fastlyServiceId}"
328332
`;
329333

330334
const fastlyTomlPath = path.resolve(computeJsDir, 'fastly.toml');

0 commit comments

Comments
 (0)