Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 296b501

Browse files
jtrabandwardbell
authored andcommitted
chore(devguide-tooling): add enforce-example-boilerplate gulp task
closes #485 and 479 removal all package.json from _example subdirs and add an example-config.json to each. Update add-example-symlinks to use new fns updated gitignore, package.json add tests to QuickStart
1 parent 393987b commit 296b501

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+124
-409
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public/docs/xref-*.*
1818
_zip-output
1919
www
2020
/npm-debug.log
21+
npm-debug.log.*
2122
*.plnkr.html
2223
plnkr.html
2324
*plnkr.no-link.html

gulpfile.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ var _excludeMatchers = _excludePatterns.map(function(excludePattern){
5454
return new Minimatch(excludePattern)
5555
});
5656

57-
58-
57+
var _exampleBoilerplateFiles = ['package.json', 'tsconfig.json', 'karma.conf.js', 'karma-test-shim.js' ]
5958

6059
// Public tasks
6160

@@ -69,21 +68,29 @@ gulp.task('help', taskListing.withFilters(function(taskName) {
6968
return shouldRemove;
7069
}));
7170

72-
gulp.task('add-example-symlinks', function() {
71+
// requires admin access
72+
gulp.task('add-example-boilerplate', function() {
7373
var realPath = path.join(EXAMPLES_PATH, '/node_modules');
7474
var nodeModulesPaths = getNodeModulesPaths(EXAMPLES_PATH);
7575

7676
nodeModulesPaths.forEach(function(linkPath) {
7777
gutil.log("symlinking " + linkPath + ' -> ' + realPath)
7878
fsUtils.addSymlink(realPath, linkPath);
7979
});
80+
var sourceFiles = _exampleBoilerplateFiles.map(function(fn) {
81+
return path.join(EXAMPLES_PATH, fn);
82+
});
83+
var examplePaths = getExamplePaths(EXAMPLES_PATH);
84+
return copyFiles(sourceFiles, examplePaths );
8085
});
8186

82-
gulp.task('remove-example-symlinks', function() {
87+
gulp.task('remove-example-boilerplate', function() {
8388
var nodeModulesPaths = getNodeModulesPaths(EXAMPLES_PATH);
8489
nodeModulesPaths.forEach(function(linkPath) {
8590
fsUtils.removeSymlink(linkPath);
8691
});
92+
var examplePaths = getExamplePaths(EXAMPLES_PATH);
93+
return deleteFiles(_exampleBoilerplateFiles, examplePaths );
8794
});
8895

8996
gulp.task('serve-and-sync', ['build-docs'], function (cb) {
@@ -230,15 +237,51 @@ gulp.task('_zip-examples', function() {
230237

231238
// Helper functions
232239

233-
function getNodeModulesPaths(basePath) {
234-
var jsonPattern = path.join(basePath, "**/package.json");
235-
var exceptJsonPattern = "!" + path.join(basePath, "/package.json");
240+
// returns a promise
241+
function copyFiles(fileNames, destPaths) {
242+
var copy = Q.denodeify(fsExtra.copy);
243+
var copyPromises = [];
244+
destPaths.forEach(function(destPath) {
245+
fileNames.forEach(function(fileName) {
246+
var baseName = path.basename(fileName);
247+
var destName = path.join(destPath, baseName);
248+
var p = copy(fileName, destName, { clobber: true});
249+
copyPromises.push(p);
250+
});
251+
});
252+
return Q.all(copyPromises);
253+
}
254+
255+
function deleteFiles(baseFileNames, destPaths) {
256+
var remove = Q.denodeify(fsExtra.remove);
257+
var delPromises = [];
258+
destPaths.forEach(function(destPath) {
259+
baseFileNames.forEach(function(baseFileName) {
260+
var destFileName = path.join(destPath, baseFileName);
261+
var p = remove(destFileName);
262+
delPromises.push(p);
263+
});
264+
});
265+
return Q.all(delPromises);
266+
}
267+
268+
function getExamplePaths(basePath) {
269+
var jsonPattern = path.join(basePath, "**/example-config.json");
270+
// ignore (skip) the top level version.
271+
var exceptJsonPattern = "!" + path.join(basePath, "/example-config.json");
236272
var nmPattern = path.join(basePath, "**/node_modules/**");
237273
var fileNames = globby.sync( [ jsonPattern, exceptJsonPattern ], { ignore: [nmPattern] } );
238274
// same as above but perf can differ.
239275
// var fileNames = globby.sync( [jsonPattern, "!" + nmPattern]);
240276
var paths = fileNames.map(function(fileName) {
241-
return path.join(path.dirname(fileName), "/node_modules");
277+
return path.dirname(fileName);
278+
});
279+
return paths;
280+
}
281+
282+
function getNodeModulesPaths(basePath) {
283+
var paths = getExamplePaths(basePath).map(function(examplePath) {
284+
return path.join(examplePath, "/node_modules");
242285
});
243286
return paths;
244287
}

public/docs/_examples/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
typings
2-
*.js.map
2+
*.js.map
3+
package.json
4+
karma.conf.js
5+
karma-test-shim.js
6+
tsconfig.json

public/docs/_examples/architecture/ts/example-config.json

Whitespace-only changes.

public/docs/_examples/architecture/ts/npm-debug.log.77ba9bb88f1c7e91ec20f862c16decc7

Lines changed: 0 additions & 40 deletions
This file was deleted.

public/docs/_examples/architecture/ts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/architecture/ts/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

public/docs/_examples/attribute-directives/ts/example-config.json

Whitespace-only changes.

public/docs/_examples/attribute-directives/ts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/attribute-directives/ts/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

public/docs/_examples/displaying-data/ts/example-config.json

Whitespace-only changes.

public/docs/_examples/displaying-data/ts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/displaying-data/ts/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

public/docs/_examples/example-config.json

Whitespace-only changes.

public/docs/_examples/forms/ts/example-config.json

Whitespace-only changes.

public/docs/_examples/forms/ts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/forms/ts/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

public/docs/_examples/hierarchical-dependency-injection/ts/example-config.json

Whitespace-only changes.

public/docs/_examples/hierarchical-dependency-injection/ts/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/hierarchical-dependency-injection/ts/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

public/docs/_examples/intro/ts/example-config.json

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// PLACEHOLDER UNTIL JAY PROVIDES THE REAL ONE

0 commit comments

Comments
 (0)