Skip to content

Commit a4303e3

Browse files
committed
Add a publish script, ready the files for finally be done.
1 parent 17c1131 commit a4303e3

File tree

9 files changed

+108
-49
lines changed

9 files changed

+108
-49
lines changed

tools/gulp/constants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import {join} from 'path';
22

33
export const PROJECT_ROOT = join(__dirname, '../..');
4+
export const SOURCE_ROOT = join(PROJECT_ROOT, 'src');
5+
46
export const DIST_ROOT = join(PROJECT_ROOT, 'dist');
5-
export const srcDir = join(PROJECT_ROOT, 'src');
67
export const DIST_COMPONENTS_ROOT = join(DIST_ROOT, '@angular2-material');
8+
9+
10+
export const NPM_VENDOR_FILES = [
11+
'@angular', 'core-js/client', 'hammerjs', 'rxjs', 'systemjs/dist', 'zone.js/dist'
12+
];

tools/gulp/task_helpers.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,40 @@ export function sassBuildTask(dest: string, root: string, includePaths: string[]
6565

6666

6767
/** Create a Gulp task that executes a process. */
68-
export function execTask(packageName: string, executable: string[] | string, args?: string[]) {
68+
export interface ExecTaskOptions {
69+
silent?: boolean;
70+
errMessage?: string;
71+
}
72+
73+
export function execTask(binPath: string, args: string[], options: ExecTaskOptions = {}) {
74+
return (done: (err?: string) => void) => {
75+
const childProcess = child_process.spawn(binPath, args);
76+
77+
if (!options.silent) {
78+
childProcess.stdout.on('data', (data: string) => {
79+
process.stdout.write(data);
80+
});
81+
82+
childProcess.stderr.on('data', (data: string) => {
83+
process.stderr.write(data);
84+
});
85+
}
86+
87+
childProcess.on('close', (code: number) => {
88+
if (code != 0) {
89+
if (options.errMessage === undefined) {
90+
done('Process failed with code ' + code);
91+
} else {
92+
done(options.errMessage);
93+
}
94+
return;
95+
}
96+
done();
97+
});
98+
}
99+
}
100+
101+
export function execNodeTask(packageName: string, executable: string[] | string, args?: string[]) {
69102
if (!args) {
70103
args = <string[]>executable;
71104
executable = undefined;
@@ -78,22 +111,8 @@ export function execTask(packageName: string, executable: string[] | string, arg
78111
throw err;
79112
}
80113

81-
const childProcess = child_process.spawn(binPath, args);
82-
83-
childProcess.stdout.on('data', (data: string) => {
84-
process.stdout.write(data);
85-
});
86-
87-
childProcess.stderr.on('data', (data: string) => {
88-
process.stderr.write(data);
89-
});
90-
91-
childProcess.on('close', (code: number) => {
92-
if (code != 0) {
93-
throw new Error('Process failed with code ' + code);
94-
}
95-
done();
96-
});
114+
// Forward to execTask.
115+
execTask(binPath, args)(done);
97116
});
98117
}
99118
}

tools/gulp/tasks/ci.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import gulp = require('gulp');
2-
import {execTask} from '../task_helpers';
2+
import {execNodeTask} from '../task_helpers';
33

44

55
gulp.task('ci:lint', ['ci:forbidden-identifiers', 'lint']);
@@ -12,4 +12,4 @@ gulp.task('ci:forbidden-identifiers', function() {
1212
require('../../../scripts/ci/forbidden-identifiers.js');
1313
});
1414

15-
gulp.task('ci:check-circular-deps', ['build:release'], execTask('madge', ['--circular', './dist']));
15+
gulp.task('ci:check-circular-deps', ['madge']);

tools/gulp/tasks/components.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as gulp from 'gulp';
22
import * as path from 'path';
33
import gulpMerge = require('merge2');
44

5-
import {srcDir, DIST_COMPONENTS_ROOT, PROJECT_ROOT} from '../constants';
6-
import {sassBuildTask, tsBuildTask, execTask, copyTask} from '../task_helpers';
5+
import {SOURCE_ROOT, DIST_COMPONENTS_ROOT, PROJECT_ROOT} from '../constants';
6+
import {sassBuildTask, tsBuildTask, execNodeTask, copyTask} from '../task_helpers';
77

88
// No typings for this.
99
const inlineResources = require('../../../scripts/release/inline-resources');
1010

11-
const componentsDir = path.join(srcDir, 'lib');
11+
const componentsDir = path.join(SOURCE_ROOT, 'lib');
1212

1313

1414
export function watchComponents() {
@@ -35,6 +35,6 @@ gulp.task('build:components', [
3535
inlineResources([DIST_COMPONENTS_ROOT]);
3636
});
3737

38-
gulp.task(':build:components:ngc', ['build:components'], execTask(
38+
gulp.task(':build:components:ngc', ['build:components'], execNodeTask(
3939
'@angular/compiler-cli', 'ngc', ['-p', path.relative(PROJECT_ROOT, componentsDir)]
4040
));

tools/gulp/tasks/default.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ task('default', ['help']);
55

66
task('help', function() {
77
const taskList = Object.keys(gulp.tasks)
8-
.filter(x => !x.startsWith(':'))
9-
.filter(x => !x.startsWith('ci:'))
10-
.filter(x => x != 'default')
8+
.filter(taskName => !taskName.startsWith(':'))
9+
.filter(taskName => !taskName.startsWith('ci:'))
10+
.filter(taskName => taskName != 'default')
1111
.sort();
1212

1313
console.log(`\nHere's a list of supported tasks:\n `, taskList.join('\n '));

tools/gulp/tasks/development.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import * as path from 'path';
44
import gulpMerge = require('merge2');
55
const gulpServer = require('gulp-server-livereload');
66

7+
import {DIST_ROOT, NPM_VENDOR_FILES, SOURCE_ROOT} from '../constants';
78
import {sassBuildTask, tsBuildTask, copyTask, buildAppTask} from '../task_helpers';
8-
import {DIST_ROOT, srcDir} from '../constants';
99
import {watchComponents} from './components';
1010

11-
const appDir = path.join(srcDir, 'demo-app');
11+
12+
const appDir = path.join(SOURCE_ROOT, 'demo-app');
1213
const outDir = DIST_ROOT;
1314

1415

@@ -20,12 +21,8 @@ export function watchDevelopmentApp() {
2021

2122

2223
gulp.task(':build:devapp:vendor', function() {
23-
const npmVendorFiles = [
24-
'@angular', 'core-js/client', 'hammerjs', 'rxjs', 'systemjs/dist', 'zone.js/dist'
25-
];
26-
2724
return gulpMerge(
28-
npmVendorFiles.map(function(root) {
25+
NPM_VENDOR_FILES.map(function(root) {
2926
const glob = path.join(root, '**/*.+(js|js.map)');
3027
return gulp.src(path.join('node_modules', glob))
3128
.pipe(gulp.dest(path.join('dist/vendor', root)));

tools/gulp/tasks/e2e.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import * as path from 'path';
33
import gulpMerge = require('merge2');
44
import gulpRunSequence = require('run-sequence');
55

6-
import {srcDir, DIST_ROOT, PROJECT_ROOT} from '../constants';
7-
import {tsBuildTask, sassBuildTask, copyTask, buildAppTask, execTask} from '../task_helpers';
6+
import {SOURCE_ROOT, DIST_ROOT, PROJECT_ROOT, NPM_VENDOR_FILES} from '../constants';
7+
import {tsBuildTask, sassBuildTask, copyTask, buildAppTask, execNodeTask} from '../task_helpers';
88
import {watchComponents} from './components';
99

1010
const gulpServer = require('gulp-server-livereload');
1111

1212

13-
const appDir = path.join(srcDir, 'e2e-app');
13+
const appDir = path.join(SOURCE_ROOT, 'e2e-app');
1414
const outDir = DIST_ROOT;
1515

1616

@@ -21,12 +21,8 @@ export function watchE2eApp() {
2121
}
2222

2323
gulp.task(':build:e2eapp:vendor', function() {
24-
const npmVendorFiles = [
25-
'@angular', 'core-js/client', 'hammerjs', 'rxjs', 'systemjs/dist', 'zone.js/dist'
26-
];
27-
2824
return gulpMerge(
29-
npmVendorFiles.map(function(root) {
25+
NPM_VENDOR_FILES.map(function(root) {
3026
const glob = path.join(root, '**/*.+(js|js.map)');
3127
return gulp.src(path.join('node_modules', glob))
3228
.pipe(gulp.dest(path.join('dist/vendor', root)));
@@ -62,9 +58,9 @@ gulp.task(':serve:e2eapp:stop', function() {
6258
}
6359
});
6460

65-
gulp.task(':test:protractor:setup', execTask('protractor', 'webdriver-manager', ['update']));
61+
gulp.task(':test:protractor:setup', execNodeTask('protractor', 'webdriver-manager', ['update']));
6662

67-
gulp.task(':test:protractor', execTask(
63+
gulp.task(':test:protractor', execNodeTask(
6864
'protractor', [path.join(PROJECT_ROOT, 'test/protractor.conf.js')]
6965
));
7066

tools/gulp/tasks/lint.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import gulp = require('gulp');
2-
import {execTask} from '../task_helpers';
2+
import {execNodeTask} from '../task_helpers';
33

44

55
gulp.task('lint', ['tslint', 'stylelint']);
6-
7-
gulp.task('tslint', execTask('tslint', ['-c', 'tslint.json', 'src/**/*.ts']));
8-
9-
gulp.task('stylelint', execTask(
6+
gulp.task('madge', ['build:release'], execNodeTask('madge', ['--circular', './dist']));
7+
gulp.task('stylelint', execNodeTask(
108
'stylelint', ['src/**/*.scss', '--config', 'stylelint-config.json', '--syntax', 'scss']
119
));
10+
gulp.task('tslint', execNodeTask('tslint', ['-c', 'tslint.json', 'src/**/*.ts']));

tools/gulp/tasks/release.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import child_process = require('child_process');
2+
import fs = require('fs');
13
import gulp = require('gulp');
24
import gulpRunSequence = require('run-sequence');
5+
import path = require('path');
6+
7+
import {execTask} from '../task_helpers';
8+
import {DIST_COMPONENTS_ROOT} from '../constants';
39

410

511
gulp.task('build:release', function(done: () => void) {
@@ -11,3 +17,39 @@ gulp.task('build:release', function(done: () => void) {
1117
done
1218
);
1319
});
20+
21+
22+
/** Make sure we're logged in. */
23+
gulp.task(':publish:whoami', execTask('npm', ['whoami'], {
24+
silent: true,
25+
errMessage: 'You must be logged in to publish.'
26+
}));
27+
gulp.task(':publish:logout', execTask('npm', ['logout']));
28+
gulp.task(':publish', function(done: () => void) {
29+
const exec: any = child_process.execSync;
30+
const currentDir = process.cwd();
31+
32+
fs.readdirSync(DIST_COMPONENTS_ROOT)
33+
.forEach(dirName => {
34+
const componentPath = path.join(DIST_COMPONENTS_ROOT, dirName);
35+
const stat = fs.statSync(componentPath);
36+
37+
if (!stat.isDirectory()) {
38+
return;
39+
}
40+
41+
process.chdir(componentPath);
42+
exec('npm publish');
43+
});
44+
process.chdir(currentDir);
45+
});
46+
47+
gulp.task('publish', function(done: () => void) {
48+
gulpRunSequence(
49+
':publish:whoami',
50+
'build:release',
51+
':publish',
52+
':publish:logout',
53+
done
54+
);
55+
});

0 commit comments

Comments
 (0)