Skip to content

Commit

Permalink
refactor(all): Convert to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Aug 19, 2018
1 parent 2a8a166 commit 6b2232d
Show file tree
Hide file tree
Showing 20 changed files with 728 additions and 213 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ jspm_packages
bower_components
.idea
.DS_STORE
.rollupcache
build/reports
11 changes: 11 additions & 0 deletions build/tasks/args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = require('yargs')
.options('target', {
alias: 't',
description: 'target module dir to copy build results into (eg. "--target ../other-module" to copy build results into "../other-module/node_modules/this-module/dist/…" whenever they change)'
})
.options('format', {
alias: 'f',
array: true,
description: 'format to compile to (eg. "es2015", "commonjs", …). Can be set muliple times to compile to multiple formats. Default is all formats.'
})
.argv;
37 changes: 19 additions & 18 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
var to5 = require('gulp-babel');
var paths = require('../paths');
var compilerOptions = require('../babel-options');
var compilerTsOptions = require('../typescript-options');
var assign = Object.assign || require('object.assign');
var through2 = require('through2');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var rename = require('gulp-rename');
var tools = require('aurelia-tools');
var ts = require('gulp-typescript');
var gutil = require('gulp-util');
var gulpIgnore = require('gulp-ignore');
var merge = require('merge2');
var jsName = paths.packageName + '.js';
var compileToModules = ['es2015', 'commonjs', 'amd', 'system', 'native-modules'];
const gulp = require('gulp');
const runSequence = require('run-sequence');
const to5 = require('gulp-babel');
const paths = require('../paths');
const compilerOptions = require('../babel-options');
const compilerTsOptions = require('../typescript-options');
const assign = Object.assign || require('object.assign');
const through2 = require('through2');
const concat = require('gulp-concat');
const insert = require('gulp-insert');
const rename = require('gulp-rename');
const tools = require('aurelia-tools');
const ts = require('gulp-typescript');
const gutil = require('gulp-util');
const gulpIgnore = require('gulp-ignore');
const merge = require('merge2');
const args = require('./args');
const jsName = paths.packageName + '.js';
const compileToModules = args.format || ['es2015', 'commonjs', 'amd', 'system', 'native-modules'];

function cleanGeneratedCode() {
return through2.obj(function(file, enc, callback) {
Expand Down
79 changes: 77 additions & 2 deletions build/tasks/dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
var gulp = require('gulp');
var tools = require('aurelia-tools');
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const tools = require('aurelia-tools');
const glob = require('glob');
const paths = require('../paths');
const args = require('./args');
const watch = require('gulp-watch');
const runSequence = require('run-sequence');
const compileToModules = args.format || ['es2015', 'commonjs', 'amd', 'system', 'native-modules'];
// const gulpCopy = require('gulp-copy');

gulp.task('update-own-deps', function(){
tools.updateOwnDependenciesFromLocalRepositories();
Expand All @@ -8,3 +17,69 @@ gulp.task('update-own-deps', function(){
gulp.task('build-dev-env', function () {
tools.buildDevEnv();
});

gulp.task('dev', ['build'], (callback) => {
let rebuildTO;
watch(paths.source, () => {
// gulp.start('build');
clearTimeout(rebuildTO);
rebuildTO = setTimeout(() => {
runSequence(
'build-index',
compileToModules
.map(function(moduleType) { return 'build-babel-' + moduleType })
.concat(paths.useTypeScriptForDTS ? ['build-dts'] : []),

);
}, 50);
});
// gulp.watch(paths.files, ['build']);
if (args.target) {
const projectName = require('../../package.json').name;
const targetNPMPath = path.join(args.target, 'node_modules', projectName);
fs.stat(targetNPMPath, (err, stats) => {
console.log(err, stats.isDirectory());
if (!err && stats.isDirectory()) {
const targetNPMDistPath = path.join(targetNPMPath, paths.output);
watchAndCopy(paths.output, targetNPMDistPath);
}
});
const targetJSPMGlob = path.join(args.target, 'jspm_packages', 'npm', projectName + '@*/');
glob(targetJSPMGlob, (err, files) => {
if (!err && files.length === 1) {
const targetJSPMPath = files[0];
const amdPath = path.join(paths.output, 'amd');
watchAndCopy(amdPath, targetJSPMPath);
}
});
}
});
function watchAndCopy(basePath, targetPath) {
const filnalPath = path.join(basePath, '**', '*');
// console.log('Watching:', filnalPath);
watch(filnalPath, vinyl => {
// console.log('dist in source changed', vinyl.event);
if (vinyl.event === 'unlink') {
return;
}
// console.log('Path changed:', vinyl.path);
const relativePath = path.relative(basePath, vinyl.path);
const destPath = path.join(targetPath, relativePath);
fs.createReadStream(vinyl.path).pipe(fs.createWriteStream(destPath));
});
// gulp.watch(path.join(basePath, '**', '*'), (event) => {
// if (event.type === 'deleted') {
// return;
// }
// const relativePath = path.relative(basePath, event.path);
// const destPath = path.join(targetPath, relativePath);
// fs.createReadStream(event.path).pipe(fs.createWriteStream(destPath));
// });
}

// function copy(changePath, basePath, targetPath) {

// const relativePath = path.relative(basePath, changePath);
// const destPath = path.join(targetPath, relativePath);
// // fs.createReadStream(vinyl.path).pipe(fs.createWriteStream(destPath));
// }
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"license": "MIT",
"author": "Rob Eisenberg <rob@bluespire.com> (http://robeisenberg.com/)",
"main": "dist/commonjs/aurelia-router.js",
"typings": "dist/aurelia-router.d.ts",
"typings": "dist/types/aurelia-router.d.ts",
"repository": {
"type": "git",
"url": "http://github.com/aurelia/router"
},
"scripts": {
"test": "gulp test",
"ci": "gulp ci"
"ci": "gulp ci",
"build": "rollup -c --environment NODE_ENV:production"
},
"jspm": {
"registry": "npm",
Expand Down Expand Up @@ -59,9 +60,12 @@
"aurelia-history": "^1.1.0",
"aurelia-logging": "^1.0.0",
"aurelia-path": "^1.0.0",
"aurelia-route-recognizer": "^1.2.0"
"aurelia-route-recognizer": "^1.2.0",
"rollup": "^0.64.1",
"rollup-plugin-typescript2": "^0.16.1"
},
"devDependencies": {
"aurelia-templating": "^1.8.2",
"aurelia-tools": "0.2.4",
"babel-dts-generator": "^0.6.1",
"babel-eslint": "^6.1.2",
Expand All @@ -76,11 +80,13 @@
"babel-preset-es2015-loose-native-modules": "^1.0.0",
"babel-preset-stage-1": "^6.5.0",
"del": "^2.2.1",
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-bump": "^2.2.0",
"gulp-concat": "^2.6.0",
"gulp-conventional-changelog": "^1.1.0",
"gulp-copy": "^1.1.0",
"gulp-coveralls": "0.1.4",
"gulp-eslint": "^3.0.1",
"gulp-ignore": "^2.0.1",
Expand All @@ -90,6 +96,7 @@
"gulp-typedoc-extractor": "^0.0.8",
"gulp-typescript": "^2.13.6",
"gulp-util": "^3.0.7",
"gulp-watch": "^5.0.1",
"isparta": "4.0.0",
"istanbul": "github:gotwarlost/istanbul#source-map",
"jasmine-core": "^2.4.1",
Expand All @@ -106,7 +113,7 @@
"run-sequence": "^1.2.2",
"through2": "^2.0.1",
"typedoc": "^0.4.4",
"typescript": "^1.9.0-dev.20160622-1.0",
"typescript": "^3.0.1",
"vinyl": "^1.1.1",
"vinyl-paths": "^2.1.0",
"yargs": "^4.8.1"
Expand Down
49 changes: 49 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import typescript from 'rollup-plugin-typescript2';

const isProduction = process.env.NODE_ENV === 'production';

export default [{
input: 'src/index.ts',
output: {
file: 'dist/es2015/index.js',
format: 'es'
},
external: 'tslib',
plugins: [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
target: 'es2015',
declarationDir: 'dist/types',
importHelpers: true
}
},
cacheRoot: '.rollupcache'
})
]
}].concat(!isProduction
? []
: [{
input: 'src/index.ts',
output: [
{ file: 'dist/commonjs/index.js', format: 'cjs' },
{ file: 'dist/amd/index.js', format: 'amd', amd: { id: 'aurelia-router' } },
{ file: 'dist/native-modules/index.js', format: 'es' }
],
external: 'tslib',
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: 'es5',
declaration: false,
declarationDir: null,
importHelpers: true
}
},
cacheRoot: '.rollupcache',
})
]
}]
);
Loading

0 comments on commit 6b2232d

Please sign in to comment.