Skip to content

Commit afa7616

Browse files
committed
build - refactor
1 parent 6a3abf2 commit afa7616

File tree

15 files changed

+284
-0
lines changed

15 files changed

+284
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
build/
33
packages/
44
.buildlog
5+
node_modules
6+
packages
7+
8+
.DS_STORE
59

610
# Or the files created by dart2js.
711
*.dart.js

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "tools/js2dart"]
2+
path = tools/js2dart
3+
url = [email protected]:angular/js2dart.git
4+
[submodule "tools/rtts-assert"]
5+
path = tools/rtts-assert
6+
url = [email protected]:angular/assert.git
7+
[submodule "tools/traceur"]
8+
path = tools/traceur
9+
url = [email protected]:google/traceur-compiler.git

TODO.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Setup
2+
- use package.json's out of the individual projects
3+
4+
- auto start Chromium when start serving
5+
- auto refresh Chromium when s/t changed
6+
- transform index.html:
7+
-> use a template with flags for dart/js and a variable with all files
8+
-> remove all <script> tags, just leave main.dart!
9+
-> auto create it as well!

gulpfile.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
var gulp = require('gulp');
2+
var rename = require('gulp-rename');
3+
var watch = require('gulp-watch');
4+
var shell = require('gulp-shell');
5+
var mergeStreams = require('event-stream').merge;
6+
var connect = require('gulp-connect');
7+
var clean = require('gulp-rimraf');
8+
var runSequence = require('run-sequence');
9+
var glob = require('glob');
10+
var ejs = require('gulp-ejs');
11+
var path = require('path');
12+
13+
// import js2dart and traceur build tasks
14+
require('./tools/js2dart/gulpfile').install(gulp);
15+
16+
var traceurJsOptions = {
17+
annotations: true, // parse annotations
18+
types: true, // parse types
19+
script: false, // parse as a module
20+
modules: 'register',
21+
typeAssertionModule: 'assert',
22+
typeAssertions: true,
23+
moduleName: true,
24+
reload: true
25+
};
26+
27+
var traceur = require('./tools/js2dart/gulp-traceur');
28+
var js2dart = require('./tools/js2dart/gulp-js2dart');
29+
30+
// -----------------------
31+
// modules
32+
var sourceTypeConfigs = {
33+
dart: {
34+
compiler: function() {
35+
return js2dart({replace: true});
36+
},
37+
transpileSrc: ['modules/*/src/**/*.es6d'],
38+
htmlSrc: ['modules/*/src/**/*.html'],
39+
copySrc: ['modules/*/src/**/*.dart'],
40+
outputDir: 'build/dart',
41+
outputExt: 'dart',
42+
mimeType: 'application/dart'
43+
},
44+
js: {
45+
compiler: function() {
46+
return traceur(traceurJsOptions);
47+
},
48+
transpileSrc: ['modules/*/src/**/*.es*', 'tools/rtts-assert/src/assert.js'],
49+
htmlSrc: ['modules/*/src/**/*.html'],
50+
copySrc: ['tools/traceur/bin/traceur-runtime.js'],
51+
outputDir: 'build/js',
52+
outputExt: 'js'
53+
}
54+
};
55+
56+
gulp.task('modules/clean', function() {
57+
return gulp.src('build', {read: false})
58+
.pipe(clean());
59+
});
60+
61+
function removeSrc(path) {
62+
path.dirname = path.dirname.replace('/src', '');
63+
}
64+
65+
function createModuleTask(sourceTypeConfig, isWatch) {
66+
var start = isWatch ? watch : gulp.src.bind(gulp);
67+
return function(done) {
68+
var transpile = start(sourceTypeConfig.transpileSrc)
69+
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
70+
.pipe(rename(removeSrc))
71+
.pipe(sourceTypeConfig.compiler())
72+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
73+
var copy = start(sourceTypeConfig.copySrc)
74+
.pipe(rename(removeSrc))
75+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
76+
// TODO: provide the list of files to the template
77+
var html = start(sourceTypeConfig.htmlSrc)
78+
.pipe(rename(removeSrc))
79+
.pipe(ejs({
80+
type: sourceTypeConfig.outputExt
81+
}))
82+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
83+
84+
return mergeStreams(transpile, copy, html);
85+
};
86+
}
87+
88+
gulp.task('modules/build.dart', createModuleTask(sourceTypeConfigs.dart, false));
89+
gulp.task('modules/watch.dart', createModuleTask(sourceTypeConfigs.dart, true));
90+
gulp.task('modules/build.js', createModuleTask(sourceTypeConfigs.js, false));
91+
gulp.task('modules/watch.js', createModuleTask(sourceTypeConfigs.js, true));
92+
93+
// ------------------
94+
// WEB SERVER
95+
gulp.task('serve', connect.server({
96+
root: [__dirname+'/build'],
97+
port: 8000,
98+
livereload: false,
99+
open: false,
100+
middleware: function() {
101+
return [function(req, resp, next){
102+
if (req.url.match(/\.dart$/)) {
103+
resp.setHeader("Content-Type", "application/dart");
104+
console.log('now', req.url);
105+
}
106+
next();
107+
}];
108+
}
109+
}));
110+
111+
// --------------
112+
// general targets
113+
114+
gulp.task('clean', function(done) {
115+
return runSequence(['traceur/clean', 'modules/clean'], done);
116+
});
117+
118+
gulp.task('build', function(done) {
119+
// By using runSequence here we are decoupling the cleaning from the rest of the build tasks
120+
// Otherwise, we have to add clean as a dependency on every task to ensure that it completes
121+
// before they begin.
122+
runSequence(
123+
'js2dart/build',
124+
['modules/build.dart', 'modules/build.js'],
125+
done
126+
);
127+
});
128+
129+
gulp.task('watch', function(done) {
130+
// By using runSequence here we are decoupling the cleaning from the rest of the build tasks
131+
// Otherwise, we have to add clean as a dependency on every task to ensure that it completes
132+
// before they begin.
133+
runSequence(
134+
'build',
135+
['js2dart/watch', 'modules/watch.dart', 'modules/watch.js'],
136+
done
137+
);
138+
});

modules/examples/src/todo/app.es6d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {DOM} from './dom';
2+
export class App {
3+
constructor() {
4+
this.input = null;
5+
this.list = null;
6+
}
7+
run() {
8+
this.input = DOM.query('input');
9+
this.list = DOM.query('ul');
10+
DOM.on(this.input, 'change', (evt) => this.add(evt));
11+
}
12+
add(evt) {
13+
var html = DOM.getInnerHTML(this.list);
14+
html += '<li>'+this.input.value+'</li>';
15+
DOM.setInnerHTML(this.list, html);
16+
}
17+
}

modules/examples/src/todo/dom.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library dom;
2+
3+
import 'dart:html';
4+
5+
class DOM {
6+
static query(selector) {
7+
return document.query(selector);
8+
}
9+
static on(element, event, callback) {
10+
element.addEventListener(event, callback);
11+
}
12+
static getInnerHTML(el) {
13+
return el.innerHtml;
14+
}
15+
static setInnerHTML(el, value) {
16+
el.innerHtml = value;
17+
}
18+
}

modules/examples/src/todo/dom.es6

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class DOM {
2+
static query(selector) {
3+
return document.querySelector(selector);
4+
}
5+
static on(el, evt, listener) {
6+
el.addEventListener(evt, listener, false);
7+
}
8+
static getInnerHTML(el) {
9+
return el.innerHTML;
10+
}
11+
static setInnerHTML(el, value) {
12+
el.innerHTML = value;
13+
}
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<input type="test">
5+
<ul></ul>
6+
7+
8+
<% if(type === 'dart') { %>
9+
<script src="main.dart" type="application/dart"></script>
10+
<% } else { %>
11+
<script src="../../traceur-runtime.js" type="text/javascript"></script>
12+
<script src="../../assert.js" type="text/javascript"></script>
13+
<script src="app.js" type="text/javascript"></script>
14+
<script src="dom.js" type="text/javascript"></script>
15+
<script>
16+
new (System.get("examples/todo/app").App)().run();
17+
</script>
18+
<% } %>
19+
</body>
20+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'app.dart' show App;
2+
3+
main() {
4+
new App().run();
5+
}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "angular",
3+
"version": "0.0.0",
4+
"description": "Angular",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"postinstall": "./postinstall.sh"
8+
},
9+
"author": "Tobias Bosch <[email protected]>",
10+
"license": "MIT",
11+
"dependencies": {
12+
"gulp": "^3.8.8",
13+
"gulp-rename": "^1.2.0",
14+
"gulp-shell": "^0.2.9",
15+
"gulp-watch": "^1.0.3",
16+
"q": "^1.0.1",
17+
"through2": "^0.6.1",
18+
"event-stream": "^3.1.5",
19+
"gulp-connect": "~1.0.5",
20+
"gulp-rimraf": "^0.1.0",
21+
"run-sequence": "^0.3.6",
22+
"glob": "^4.0.6",
23+
"gulp-ejs": "^0.3.1"
24+
}
25+
}

0 commit comments

Comments
 (0)