@@ -2,50 +2,82 @@ import {Injectable} from '@angular/core';
22import { Http } from '@angular/http' ;
33import { ExampleData } from '@angular/material-examples' ;
44import 'rxjs/add/operator/toPromise' ;
5+ import { VERSION } from '@angular/material' ;
56
6- const PLUNKER_URL = 'https://plnkr.co/edit/?p=preview ' ;
7+ const STACKBLITZ_URL = 'https://run.stackblitz.com/api/angular/v1/ ' ;
78
89const COPYRIGHT =
910 `Copyright 2017 Google Inc. All Rights Reserved.
1011 Use of this source code is governed by an MIT-style license that
1112 can be found in the LICENSE file at http://angular.io/license` ;
1213
13- const TEMPLATE_PATH = '/assets/plunker/' ;
14- const TEMPLATE_FILES = [ 'index.html' , 'systemjs.config.js' , 'main.ts' ] ;
14+ const TEMPLATE_PATH = '/assets/stackblitz/' ;
15+ const TEMPLATE_FILES = [
16+ 'index.html' ,
17+ 'styles.scss' ,
18+ 'polyfills.ts' ,
19+ '.angular-cli.json' ,
20+ 'main.ts'
21+ ] ;
1522
1623const TAGS : string [ ] = [ 'angular' , 'material' , 'example' ] ;
24+ const angularVersion = '^5.0.0' ;
25+ const materialVersion = '^5.0.0-rc.1' ;
26+
27+ const dependencies = {
28+ '@angular/cdk' : materialVersion ,
29+ '@angular/material' : materialVersion ,
30+ '@angular/animations' : angularVersion ,
31+ '@angular/common' : angularVersion ,
32+ '@angular/compiler' : angularVersion ,
33+ '@angular/core' : angularVersion ,
34+ '@angular/forms' : angularVersion ,
35+ '@angular/http' : angularVersion ,
36+ '@angular/platform-browser' : angularVersion ,
37+ '@angular/platform-browser-dynamic' : angularVersion ,
38+ '@angular/router' : angularVersion ,
39+ 'angular-in-memory-web-api' : '~0.5.0' ,
40+ 'core-js' : '^2.4.1' ,
41+ 'rxjs' : '^5.5.2' ,
42+ 'web-animations-js' : '^2.3.1' ,
43+ 'zone.js' : '^0.8.14' ,
44+ 'hammerjs' : '^2.0.8'
45+ } ;
1746
1847/**
19- * Plunker writer, write example files to Plunker
48+ * Stackblitz writer, write example files to stackblitz
2049 *
21- * Plunker API
22- * URL: http ://plnkr.co/edit/?p=preview
50+ * StackBlitz API
51+ * URL: https ://run.stackblitz.com/api/aio/v1/
2352 * data: {
2453 * // File name, directory and content of files
2554 * files[file-name1]: file-content1,
2655 * files[directory-name/file-name2]: file-content2,
2756 * // Can add multiple tags
2857 * tags[0]: tag-0,
29- * // Description of plunker
58+ * // Description of stackblitz
3059 * description: description,
3160 * // Private or not
3261 * private: true
62+ * // Dependencies
63+ * dependencies: dependencies
3364 * }
3465 */
3566@Injectable ( )
36- export class PlunkerWriter {
67+ export class StackblitzWriter {
3768 constructor ( private _http : Http ) { }
3869
3970 /**
40- * Returns an HTMLFormElement that will open a new plunker template with the example data when
71+ * Returns an HTMLFormElement that will open a new stackblitz template with the example data when
4172 * called with submit().
4273 */
43- constructPlunkerForm ( data : ExampleData ) : Promise < HTMLFormElement > {
74+ constructStackblitzForm ( data : ExampleData ) : Promise < HTMLFormElement > {
4475 let form = this . _createFormElement ( ) ;
4576
4677 TAGS . forEach ( ( tag , i ) => this . _appendFormInput ( form , `tags[${ i } ]` , tag ) ) ;
4778 this . _appendFormInput ( form , 'private' , 'true' ) ;
4879 this . _appendFormInput ( form , 'description' , data . description ) ;
80+ this . _appendFormInput ( form , 'dependencies' , JSON . stringify ( dependencies ) ) ;
4981
5082 return new Promise ( resolve => {
5183 let templateContents = TEMPLATE_FILES
@@ -65,10 +97,10 @@ export class PlunkerWriter {
6597 } ) ;
6698 }
6799
68- /** Constructs a new form element that will navigate to the plunker url. */
100+ /** Constructs a new form element that will navigate to the stackblitz url. */
69101 _createFormElement ( ) : HTMLFormElement {
70102 const form = document . createElement ( 'form' ) ;
71- form . action = PLUNKER_URL ;
103+ form . action = STACKBLITZ_URL ;
72104 form . method = 'post' ;
73105 form . target = '_blank' ;
74106 return form ;
@@ -98,12 +130,14 @@ export class PlunkerWriter {
98130 path : string ) {
99131 if ( path == TEMPLATE_PATH ) {
100132 content = this . _replaceExamplePlaceholderNames ( data , filename , content ) ;
133+ } else {
134+ filename = 'app/' + filename ;
101135 }
102136 this . _appendFormInput ( form , `files[${ filename } ]` , this . _appendCopyright ( filename , content ) ) ;
103137 }
104138
105139 /**
106- * The Plunker template assets contain placeholder names for the examples:
140+ * The stackblitz template assets contain placeholder names for the examples:
107141 * "<material-docs-example>" and "MaterialDocsExample".
108142 * This will replace those placeholders with the names from the example metadata,
109143 * e.g. "<basic-button-example>" and "BasicButtonExample"
@@ -116,6 +150,7 @@ export class PlunkerWriter {
116150 // For example, <material-docs-example></material-docs-example> will be replaced as
117151 // <button-demo></button-demo>
118152 fileContent = fileContent . replace ( / m a t e r i a l - d o c s - e x a m p l e / g, data . selectorName ) ;
153+ fileContent = fileContent . replace ( / { { version} } / g, VERSION . full ) ;
119154 } else if ( fileName == 'main.ts' ) {
120155 // Replace the component name in `main.ts`.
121156 // For example, `import {MaterialDocsExample} from 'material-docs-example'`
0 commit comments