From 15c2a93f1481c286c6df8a1788c388b28339c4d1 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 22 Jan 2018 14:42:59 +0200 Subject: [PATCH] build(aio): check for obsolete `plnkr.json` and missing `main` files (#20165) Also, remove `plnkr.json` for `service-worker-getting-started` guide, since it is not used and ServiceWorker cannot work correctly in plnkr/stackblitz anyway (e.g. no build step to re-compute hashes). A zipper might be useful and can be added in a subsequent PR, but it is currently broken (e.g. no dependency on `@angular/service-worker`). PR Close #20165 --- .../{plnkr.json => stackblitz.json} | 3 +- .../{plnkr.json => stackblitz.json} | 3 +- .../{plnkr.json => stackblitz.json} | 3 +- .../ngmodule-faq/contact.1b.plnkr.json | 25 ----------- .../contact.1b.stackblitz.json | 0 .../ngmodule-faq/contact.2.plnkr.json | 27 ------------ .../contact.2.stackblitz.json | 0 .../ngmodule-faq/minimal.0.plnkr.json | 13 ------ .../minimal.0.stackblitz.json | 0 aio/content/examples/ngmodule-faq/plnkr.json | 41 ------------------- .../ngmodule-faq/pre-shared.3.plnkr.json | 41 ------------------- .../pre-shared.3.stackblitz.json | 0 .../stackblitz.json | 0 .../ngmodules/{plnkr.json => stackblitz.json} | 3 +- .../providers/{plnkr.json => stackblitz.json} | 3 +- aio/content/examples/quickstart/plnkr.json | 12 ------ .../examples/quickstart/stackblitz.json | 11 +++++ .../examples/reactive-forms/final.plnkr.json | 25 ----------- .../reactive-forms/final.stackblitz.json | 12 ++++-- .../service-worker-getting-started/plnkr.json | 5 --- aio/content/examples/setup/plnkr.json | 13 ------ .../setup/quickstart-specs.plnkr.json | 13 ------ .../setup/quickstart-specs.stackblitz.json | 12 ++++++ aio/content/examples/setup/stackblitz.json | 12 ++++++ aio/tools/stackblitz-builder/builder.js | 32 +++++++++++++-- 25 files changed, 77 insertions(+), 232 deletions(-) rename aio/content/examples/bootstrapping/{plnkr.json => stackblitz.json} (70%) rename aio/content/examples/feature-modules/{plnkr.json => stackblitz.json} (71%) rename aio/content/examples/lazy-loading-ngmodules/{plnkr.json => stackblitz.json} (73%) delete mode 100644 aio/content/examples/ngmodule-faq/contact.1b.plnkr.json rename aio/content/examples/{ngmodule => ngmodule-faq}/contact.1b.stackblitz.json (100%) delete mode 100644 aio/content/examples/ngmodule-faq/contact.2.plnkr.json rename aio/content/examples/{ngmodule => ngmodule-faq}/contact.2.stackblitz.json (100%) delete mode 100644 aio/content/examples/ngmodule-faq/minimal.0.plnkr.json rename aio/content/examples/{ngmodule => ngmodule-faq}/minimal.0.stackblitz.json (100%) delete mode 100644 aio/content/examples/ngmodule-faq/plnkr.json delete mode 100644 aio/content/examples/ngmodule-faq/pre-shared.3.plnkr.json rename aio/content/examples/{ngmodule => ngmodule-faq}/pre-shared.3.stackblitz.json (100%) rename aio/content/examples/{ngmodule => ngmodule-faq}/stackblitz.json (100%) rename aio/content/examples/ngmodules/{plnkr.json => stackblitz.json} (69%) rename aio/content/examples/providers/{plnkr.json => stackblitz.json} (69%) delete mode 100644 aio/content/examples/quickstart/plnkr.json create mode 100644 aio/content/examples/quickstart/stackblitz.json delete mode 100644 aio/content/examples/reactive-forms/final.plnkr.json delete mode 100644 aio/content/examples/service-worker-getting-started/plnkr.json delete mode 100644 aio/content/examples/setup/plnkr.json delete mode 100644 aio/content/examples/setup/quickstart-specs.plnkr.json create mode 100644 aio/content/examples/setup/quickstart-specs.stackblitz.json create mode 100644 aio/content/examples/setup/stackblitz.json diff --git a/aio/content/examples/bootstrapping/plnkr.json b/aio/content/examples/bootstrapping/stackblitz.json similarity index 70% rename from aio/content/examples/bootstrapping/plnkr.json rename to aio/content/examples/bootstrapping/stackblitz.json index 7beff22ef4..3167ca8387 100644 --- a/aio/content/examples/bootstrapping/plnkr.json +++ b/aio/content/examples/bootstrapping/stackblitz.json @@ -1,11 +1,10 @@ { "description": "Bootstrapping", - "basePath": "src/", "files": [ "!**/*.d.ts", "!**/*.js", "!**/*.[1,2].*" ], - "open": "app/app.component.ts", + "file": "src/app/app.component.ts", "tags": ["ngmodules"] } diff --git a/aio/content/examples/feature-modules/plnkr.json b/aio/content/examples/feature-modules/stackblitz.json similarity index 71% rename from aio/content/examples/feature-modules/plnkr.json rename to aio/content/examples/feature-modules/stackblitz.json index 595bd3f23a..e0cbd2e29d 100644 --- a/aio/content/examples/feature-modules/plnkr.json +++ b/aio/content/examples/feature-modules/stackblitz.json @@ -1,11 +1,10 @@ { "description": "Feature Modules", - "basePath": "src/", "files": [ "!**/*.d.ts", "!**/*.js", "!**/*.[1,2].*" ], - "open": "app/app.component.ts", + "file": "src/app/app.component.ts", "tags": ["feature modules"] } diff --git a/aio/content/examples/lazy-loading-ngmodules/plnkr.json b/aio/content/examples/lazy-loading-ngmodules/stackblitz.json similarity index 73% rename from aio/content/examples/lazy-loading-ngmodules/plnkr.json rename to aio/content/examples/lazy-loading-ngmodules/stackblitz.json index 1aea3da633..e6ee97e1cf 100644 --- a/aio/content/examples/lazy-loading-ngmodules/plnkr.json +++ b/aio/content/examples/lazy-loading-ngmodules/stackblitz.json @@ -1,11 +1,10 @@ { "description": "Lazy Loading Feature Modules", - "basePath": "src/", "files": [ "!**/*.d.ts", "!**/*.js", "!**/*.[1,2].*" ], - "open": "app/app.component.ts", + "file": "src/app/app.component.ts", "tags": ["lazy loading"] } diff --git a/aio/content/examples/ngmodule-faq/contact.1b.plnkr.json b/aio/content/examples/ngmodule-faq/contact.1b.plnkr.json deleted file mode 100644 index 1f2122de63..0000000000 --- a/aio/content/examples/ngmodule-faq/contact.1b.plnkr.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "description": "Contact NgModule v.1", - "basePath": "src/", - "files": [ - "app/app.component.1b.ts", - "app/app.module.1b.ts", - "app/highlight.directive.ts", - "app/title.component.html", - "app/title.component.ts", - "app/user.service.ts", - - "app/contact/awesome.pipe.ts", - "app/contact/contact.component.css", - "app/contact/contact.component.html", - "app/contact/contact.component.3.ts", - "app/contact/contact.service.ts", - "app/contact/contact-highlight.directive.ts", - - "main.1b.ts", - "styles.css", - "index.1b.html" - ], - "main": "index.1b.html", - "tags": ["NgModule"] -} diff --git a/aio/content/examples/ngmodule/contact.1b.stackblitz.json b/aio/content/examples/ngmodule-faq/contact.1b.stackblitz.json similarity index 100% rename from aio/content/examples/ngmodule/contact.1b.stackblitz.json rename to aio/content/examples/ngmodule-faq/contact.1b.stackblitz.json diff --git a/aio/content/examples/ngmodule-faq/contact.2.plnkr.json b/aio/content/examples/ngmodule-faq/contact.2.plnkr.json deleted file mode 100644 index 9c844831c7..0000000000 --- a/aio/content/examples/ngmodule-faq/contact.2.plnkr.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "description": "Contact NgModule v.2", - "basePath": "src/", - "files": [ - "app/app.component.2.ts", - "app/app.module.2.ts", - "app/highlight.directive.ts", - "app/title.component.html", - "app/title.component.ts", - "app/user.service.ts", - - "app/contact/contact.component.css", - "app/contact/contact.component.html", - "app/contact/contact.service.ts", - - "app/contact/awesome.pipe.ts", - "app/contact/contact.component.3.ts", - "app/contact/contact.module.2.ts", - "app/contact/contact-highlight.directive.ts", - - "main.2.ts", - "styles.css", - "index.2.html" - ], - "main": "index.2.html", - "tags": ["NgModule"] -} diff --git a/aio/content/examples/ngmodule/contact.2.stackblitz.json b/aio/content/examples/ngmodule-faq/contact.2.stackblitz.json similarity index 100% rename from aio/content/examples/ngmodule/contact.2.stackblitz.json rename to aio/content/examples/ngmodule-faq/contact.2.stackblitz.json diff --git a/aio/content/examples/ngmodule-faq/minimal.0.plnkr.json b/aio/content/examples/ngmodule-faq/minimal.0.plnkr.json deleted file mode 100644 index e5e37ac4ee..0000000000 --- a/aio/content/examples/ngmodule-faq/minimal.0.plnkr.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "description": "Minimal NgModule", - "basePath": "src/", - "files": [ - "app/app.component.0.ts", - "app/app.module.0.ts", - "main.0.ts", - "styles.css", - "index.0.html" - ], - "main": "index.0.html", - "tags": ["NgModule"] -} diff --git a/aio/content/examples/ngmodule/minimal.0.stackblitz.json b/aio/content/examples/ngmodule-faq/minimal.0.stackblitz.json similarity index 100% rename from aio/content/examples/ngmodule/minimal.0.stackblitz.json rename to aio/content/examples/ngmodule-faq/minimal.0.stackblitz.json diff --git a/aio/content/examples/ngmodule-faq/plnkr.json b/aio/content/examples/ngmodule-faq/plnkr.json deleted file mode 100644 index 4d9d2ec20b..0000000000 --- a/aio/content/examples/ngmodule-faq/plnkr.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "description": "NgModule Final", - "basePath": "src/", - "files": [ - "app/app.component.ts", - "app/app.module.ts", - "app/app-routing.module.ts", - - "app/contact/contact.component.css", - "app/contact/contact.component.html", - "app/contact/contact.service.ts", - - "app/contact/contact.component.ts", - "app/contact/contact.module.ts", - "app/contact/contact-routing.module.ts", - - "app/crisis/*.ts", - - "app/hero/hero-detail.component.ts", - "app/hero/hero-list.component.ts", - "app/hero/hero.service.ts", - - "app/hero/hero.component.ts", - "app/hero/hero.module.ts", - "app/hero/hero-routing.module.ts", - - "app/core/*.css", - "app/core/*.html", - "app/core/*.ts", - - "app/shared/*.css", - "app/shared/*.html", - "app/shared/*.ts", - - "main.ts", - "styles.css", - "index.html" - ], - "main": "index.html", - "tags": ["NgModule"] -} diff --git a/aio/content/examples/ngmodule-faq/pre-shared.3.plnkr.json b/aio/content/examples/ngmodule-faq/pre-shared.3.plnkr.json deleted file mode 100644 index 97bdd8dfd9..0000000000 --- a/aio/content/examples/ngmodule-faq/pre-shared.3.plnkr.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "description": "NgModule v.3", - "basePath": "src/", - "files": [ - "app/app.component.3.ts", - "app/app.module.3.ts", - "app/app-routing.module.3.ts", - - "app/highlight.directive.ts", - "app/title.component.html", - "app/title.component.ts", - "app/user.service.ts", - - "app/contact/contact.component.css", - "app/contact/contact.component.html", - "app/contact/contact.service.ts", - - "app/contact/awesome.pipe.ts", - "app/contact/contact.component.3.ts", - "app/contact/contact.module.3.ts", - "app/contact/contact-routing.module.3.ts", - "app/contact/contact-highlight.directive.ts", - - "app/crisis/*.ts", - - "app/hero/hero-detail.component.ts", - "app/hero/hero-list.component.ts", - "app/hero/hero.service.ts", - - "app/hero/hero.component.3.ts", - "app/hero/hero.module.3.ts", - "app/hero/hero-routing.module.3.ts", - "app/hero/highlight.directive.ts", - - "main.3.ts", - "styles.css", - "index.3.html" - ], - "main": "index.3.html", - "tags": ["NgModule"] -} diff --git a/aio/content/examples/ngmodule/pre-shared.3.stackblitz.json b/aio/content/examples/ngmodule-faq/pre-shared.3.stackblitz.json similarity index 100% rename from aio/content/examples/ngmodule/pre-shared.3.stackblitz.json rename to aio/content/examples/ngmodule-faq/pre-shared.3.stackblitz.json diff --git a/aio/content/examples/ngmodule/stackblitz.json b/aio/content/examples/ngmodule-faq/stackblitz.json similarity index 100% rename from aio/content/examples/ngmodule/stackblitz.json rename to aio/content/examples/ngmodule-faq/stackblitz.json diff --git a/aio/content/examples/ngmodules/plnkr.json b/aio/content/examples/ngmodules/stackblitz.json similarity index 69% rename from aio/content/examples/ngmodules/plnkr.json rename to aio/content/examples/ngmodules/stackblitz.json index f6a974e08d..6bc4252b82 100644 --- a/aio/content/examples/ngmodules/plnkr.json +++ b/aio/content/examples/ngmodules/stackblitz.json @@ -1,11 +1,10 @@ { "description": "NgModules", - "basePath": "src/", "files": [ "!**/*.d.ts", "!**/*.js", "!**/*.[1,2].*" ], - "open": "app/app.component.ts", + "file": "src/app/app.component.ts", "tags": ["NgModules"] } diff --git a/aio/content/examples/providers/plnkr.json b/aio/content/examples/providers/stackblitz.json similarity index 69% rename from aio/content/examples/providers/plnkr.json rename to aio/content/examples/providers/stackblitz.json index 516f516685..68593b9051 100644 --- a/aio/content/examples/providers/plnkr.json +++ b/aio/content/examples/providers/stackblitz.json @@ -1,11 +1,10 @@ { "description": "Providers", - "basePath": "src/", "files": [ "!**/*.d.ts", "!**/*.js", "!**/*.[1,2].*" ], - "open": "app/app.component.ts", + "file": "src/app/app.component.ts", "tags": ["providers"] } diff --git a/aio/content/examples/quickstart/plnkr.json b/aio/content/examples/quickstart/plnkr.json deleted file mode 100644 index 8edf7c25ea..0000000000 --- a/aio/content/examples/quickstart/plnkr.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "QuickStart", - "basePath": "src/", - "files": [ - "app/app.component.ts", - "app/app.module.ts", - "main.ts", - "index.html" - ], - "open": "app/app.component.ts", - "tags": ["quickstart"] -} diff --git a/aio/content/examples/quickstart/stackblitz.json b/aio/content/examples/quickstart/stackblitz.json new file mode 100644 index 0000000000..fd606e2ab9 --- /dev/null +++ b/aio/content/examples/quickstart/stackblitz.json @@ -0,0 +1,11 @@ +{ + "description": "QuickStart", + "files": [ + "src/app/app.component.ts", + "src/app/app.module.ts", + "src/main.ts", + "src/index.html" + ], + "file": "src/app/app.component.ts", + "tags": ["quickstart"] +} diff --git a/aio/content/examples/reactive-forms/final.plnkr.json b/aio/content/examples/reactive-forms/final.plnkr.json deleted file mode 100644 index 28e756ded5..0000000000 --- a/aio/content/examples/reactive-forms/final.plnkr.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "description": "Angular Reactive Forms (final)", - "basePath": "src/", - "files":[ - "styles.css", - - "app/app.component.ts", - "app/app.component.html", - "app/app.component.css", - "app/app.module.ts", - "app/data-model.ts", - "app/hero.service.ts", - "app/hero-detail/hero-detail.component.html", - "app/hero-detail/hero-detail.component.ts", - "app/hero-detail/hero-detail.component.css", - "app/hero-list/hero-list.component.html", - "app/hero-list/hero-list.component.ts", - "app/hero-list/hero-list.component.css", - - "main-final.ts", - "index-final.html" - ], - "main": "index-final.html", - "tags": ["reactive", "forms"] -} diff --git a/aio/content/examples/reactive-forms/final.stackblitz.json b/aio/content/examples/reactive-forms/final.stackblitz.json index 1f8d069787..f789236245 100644 --- a/aio/content/examples/reactive-forms/final.stackblitz.json +++ b/aio/content/examples/reactive-forms/final.stackblitz.json @@ -4,13 +4,17 @@ "src/styles.css", "src/app/app.component.ts", + "src/app/app.component.html", + "src/app/app.component.css", "src/app/app.module.ts", "src/app/data-model.ts", "src/app/hero.service.ts", - "src/app/hero-detail.component.html", - "src/app/hero-detail.component.ts", - "src/app/hero-list.component.html", - "src/app/hero-list.component.ts", + "src/app/hero-detail/hero-detail.component.html", + "src/app/hero-detail/hero-detail.component.ts", + "src/app/hero-detail/hero-detail.component.css", + "src/app/hero-list/hero-list.component.html", + "src/app/hero-list/hero-list.component.ts", + "src/app/hero-list/hero-list.component.css", "src/main-final.ts", "src/index-final.html" diff --git a/aio/content/examples/service-worker-getting-started/plnkr.json b/aio/content/examples/service-worker-getting-started/plnkr.json deleted file mode 100644 index 661824d258..0000000000 --- a/aio/content/examples/service-worker-getting-started/plnkr.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "description": "Service Worker", - "basePath": "src/", - "tags": ["service worker"] - } \ No newline at end of file diff --git a/aio/content/examples/setup/plnkr.json b/aio/content/examples/setup/plnkr.json deleted file mode 100644 index 22b528eec5..0000000000 --- a/aio/content/examples/setup/plnkr.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "description": "QuickStart Setup", - "basePath": "src/", - "files": [ - "app/app.component.ts", - "app/app.module.ts", - "index.html", - "main.ts", - "styles.css" - ], - "open": "app/app.component.ts", - "tags": ["quickstart", "setup", "seed"] -} diff --git a/aio/content/examples/setup/quickstart-specs.plnkr.json b/aio/content/examples/setup/quickstart-specs.plnkr.json deleted file mode 100644 index a7dfedb595..0000000000 --- a/aio/content/examples/setup/quickstart-specs.plnkr.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "description": "Quickstart AppComponent Testing", - "basePath": "src/", - "files":[ - "browser-test-shim.js", - "app/app.component.ts", - "app/app.component.spec.ts", - "quickstart-specs.html" - ], - "main": "quickstart-specs.html", - "open": "app/app.component.spec.ts", - "tags": ["quickstart", "setup", "testing"] -} diff --git a/aio/content/examples/setup/quickstart-specs.stackblitz.json b/aio/content/examples/setup/quickstart-specs.stackblitz.json new file mode 100644 index 0000000000..44d7ab73f7 --- /dev/null +++ b/aio/content/examples/setup/quickstart-specs.stackblitz.json @@ -0,0 +1,12 @@ +{ + "description": "Quickstart AppComponent Testing", + "files":[ + "src/browser-test-shim.js", + "src/app/app.component.ts", + "src/app/app.component.spec.ts", + "src/quickstart-specs.html" + ], + "main": "src/quickstart-specs.html", + "file": "src/app/app.component.spec.ts", + "tags": ["quickstart", "setup", "testing"] +} diff --git a/aio/content/examples/setup/stackblitz.json b/aio/content/examples/setup/stackblitz.json new file mode 100644 index 0000000000..2fd0130fd8 --- /dev/null +++ b/aio/content/examples/setup/stackblitz.json @@ -0,0 +1,12 @@ +{ + "description": "QuickStart Setup", + "files": [ + "src/app/app.component.ts", + "src/app/app.module.ts", + "src/index.html", + "src/main.ts", + "src/styles.css" + ], + "file": "src/app/app.component.ts", + "tags": ["quickstart", "setup", "seed"] +} diff --git a/aio/tools/stackblitz-builder/builder.js b/aio/tools/stackblitz-builder/builder.js index 71801cb791..13d614ac18 100644 --- a/aio/tools/stackblitz-builder/builder.js +++ b/aio/tools/stackblitz-builder/builder.js @@ -29,6 +29,8 @@ class StackblitzBuilder { } build() { + this._checkForOutdatedConfig(); + // When testing it sometimes helps to look a just one example directory like so: // var stackblitzPaths = path.join(this.basePath, '**/testing/*stackblitz.json'); var stackblitzPaths = path.join(this.basePath, '**/*stackblitz.json'); @@ -62,7 +64,7 @@ class StackblitzBuilder { // description: string - description of this stackblitz - defaults to the title in the index.html page. // tags: string[] - optional array of stackblitz tags (for searchability) // main: string - name of file that will become index.html in the stackblitz - defaults to index.html - // file: string - name of file to display within the stackblitz as in "open": "app/app.module.ts" + // file: string - name of file to display within the stackblitz (e.g. `"file": "app/app.module.ts"`) _buildStackblitzFrom(configFileName) { // replace ending 'stackblitz.json' with 'stackblitz.no-link.html' to create output file name; var outputFileName = `stackblitz.no-link.html`; @@ -74,7 +76,7 @@ class StackblitzBuilder { } try { var config = this._initConfigAndCollectFileNames(configFileName); - var postData = this._createPostData(config); + var postData = this._createPostData(config, configFileName); this._addDependencies(postData); var html = this._createStackblitzHtml(config, postData); fs.writeFileSync(outputFileName, html, 'utf-8'); @@ -95,6 +97,24 @@ class StackblitzBuilder { } } + _checkForOutdatedConfig() { + // Ensure that nobody is trying to use the old config filenames (i.e. `plnkr.json`). + var plunkerPaths = path.join(this.basePath, '**/*plnkr.json'); + var fileNames = globby.sync(plunkerPaths, { ignore: ['**/node_modules/**'] }); + + if (fileNames.length) { + const readmePath = path.join(__dirname, 'README.md'); + const errorMessage = + 'One or more examples are still trying to use \'plnkr.json\' files for configuring ' + + 'live examples. This is not supported any more. \'stackblitz.json\' should be used ' + + 'instead.\n' + + `(Slight modifications may be required. See '${readmePath}' for more info.\n\n` + + fileNames.map(name => `- ${name}`).join('\n'); + + throw Error(errorMessage); + } + } + _createBaseStackblitzHtml(config) { var file = ''; @@ -122,8 +142,14 @@ class StackblitzBuilder { return html; } - _createPostData(config) { + _createPostData(config, configFileName) { var postData = {}; + + // If `config.main` is specified, ensure that it points to an existing file. + if (config.main && !this._existsSync(path.join(config.basePath, config.main))) { + throw Error(`The main file ('${config.main}') specified in '${configFileName}' does not exist.`); + } + config.fileNames.forEach((fileName) => { var content; var extn = path.extname(fileName);