From 77c53559d067b55038ed32ac85511453c79b07b7 Mon Sep 17 00:00:00 2001 From: Sonu Kapoor Date: Thu, 9 Jan 2020 21:54:14 -0500 Subject: [PATCH] build(docs-infra): specify more relevant landing files for StackBlitz projects (#34553) The StackBlitz API (which we use to generate StackBlitz projects on the fly, when a user clicks on a live example link in the docs) allows specifying the file to open in the editor by passing a query param. If no file is specified, StackBlitz opens a default one. This commit specifies relevant landing files for some of the examples to make it easier to engage with the examples more quickly, and to see what the example is attempting to demonstrate. Fixes #22357. PR Close #34553 --- aio/tools/stackblitz-builder/builder.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/aio/tools/stackblitz-builder/builder.js b/aio/tools/stackblitz-builder/builder.js index b32f29b6e9..a804fa6ba7 100644 --- a/aio/tools/stackblitz-builder/builder.js +++ b/aio/tools/stackblitz-builder/builder.js @@ -116,13 +116,26 @@ class StackblitzBuilder { } } - _createBaseStackblitzHtml(config) { - var file = ''; - - // TODO: Doesn't work properly yet + _getPrimaryFile(config) { if (config.file) { - file = `?file=${config.file}`; + if (!this._existsSync(path.join(config.basePath, config.file))) { + throw new Error(`The specified primary file (${config.file}) does not exist in '${config.basePath}'.`); + } + return config.file; + } else { + const defaultPrimaryFiles = ['src/app/app.component.html', 'src/app/app.component.ts', 'src/app/main.ts']; + const primaryFile = defaultPrimaryFiles.find(fileName => this._existsSync(path.join(config.basePath, fileName))); + + if (!primaryFile) { + throw new Error(`None of the default primary files (${defaultPrimaryFiles.join(', ')}) exists in '${config.basePath}'.`); + } + + return primaryFile; } + } + + _createBaseStackblitzHtml(config) { + var file = `?file=${this._getPrimaryFile(config)}`; var action = `https://run.stackblitz.com/api/angular/v1${file}`; var html = `