Permalink
Browse files

feat(project): new build tasks with typings and bundled

  • Loading branch information...
doktordirk committed Jul 27, 2016
1 parent 42c04e7 commit 5b4aa116dd49f43d2170c43ec36f541f60731af2
@@ -0,0 +1,14 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# 2 space indentation
[**.*]
indent_style = space
indent_size = 2
@@ -0,0 +1,6 @@
{
"extends": "./node_modules/aurelia-tools/.eslintrc.json",
"rules": {
"consistent-return": 0
}
}
@@ -0,0 +1,3 @@
jspm_packages
bower_components
.idea
@@ -0,0 +1,24 @@
{
"output": true,
"plugins": {
"lint": {
"maximum-line-length": false,
"heading-style": "atx",
"no-duplicate-headings": false,
"no-undefined-references": false,
"no-shortcut-reference-link": false,
"no-heading-punctuation": ".,;:!",
"list-item-indent": false
}
},
"settings": {
"gfm": true,
"bullet": "*",
"closeAtx": false,
"fences": true,
"listItemIndent": "1",
"rule": "-",
"ruleRepetition": 10,
"ruleSpaces": false
}
}
@@ -0,0 +1,15 @@
language: node_js
node_js:
- '0.12'
before_install:
- npm install -g jspm
- jspm config registries.github.auth U3Bvb25YOjY2NWIxYWQ2ZTM4ZjUxZGNjMzcwNDBkYzMxYjgxZGVkZjE1M2RjYjg=
before_script:
- jspm -v
- jspm i
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
notifications:
email:
on_success: change
on_failure: change
@@ -0,0 +1,26 @@
{
"name": "aurelia-filter",
"version": "0.0.1",
"description": "A plugin for aurelia to populate search/filter criteria. Works well with aurelia-orm.",
"keywords": [
"aurelia",
"filter",
"criteria",
"spoonx"
],
"homepage": "https://github.com/SpoonX/aurelia-filter#readme",
"license": "MIT",
"author": "VMBindraban <vijay@spoonx.nl>",
"main": "dist/commonjs/aurelia-filter.js",
"moduleType": "node",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/SpoonX/aurelia-filter.git"
},
"dependencies": {
"aurelia-form": "^0.1.6",
"aurelia-framework": "^1.0.0-rc.1.0.0",
"aurelia-view-manager": "^0.0.5",
"extend": "^3.0.0"
}
}
@@ -0,0 +1,13 @@
var yargs = require('yargs');

var argv = yargs.argv,
validBumpTypes = "major|minor|patch|prerelease".split("|"),
bump = (argv.bump || 'patch').toLowerCase();

if(validBumpTypes.indexOf(bump) === -1) {
throw new Error('Unrecognized bump "' + bump + '".');
}

module.exports = {
bump: bump
};
@@ -0,0 +1,65 @@
var path = require('path');
var paths = require('./paths');

exports.base = function() {
var config = {
filename: '',
filenameRelative: '',
sourceMap: true,
sourceRoot: '',
moduleRoot: path.resolve('src').replace(/\\/g, '/'),
moduleIds: false,
comments: false,
compact: false,
code: true,
presets: [ 'es2015-loose', 'stage-1' ],
plugins: [
'syntax-flow',
'transform-decorators-legacy',
]
};
if (!paths.useTypeScriptForDTS) {
config.plugins.push(
['babel-dts-generator', {
packageName: paths.packageName,
typings: '',
suppressModulePath: true,
suppressComments: false,
memberOutputFilter: /^_.*/,
suppressAmbientDeclaration: true
}]
);
};
config.plugins.push('transform-flow-strip-types');
return config;
}

exports.commonjs = function() {
var options = exports.base();
options.plugins.push('transform-es2015-modules-commonjs');
return options;
};

exports.amd = function() {
var options = exports.base();
options.plugins.push('transform-es2015-modules-amd');
return options;
};

exports.system = function() {
var options = exports.base();
options.plugins.push('transform-es2015-modules-systemjs');
return options;
};

exports.es2015 = function() {
var options = exports.base();
options.presets = ['stage-1']
return options;
};

exports['native-modules'] = function() {
var options = exports.base();
options.presets[0] = 'es2015-loose-native-modules';
return options;
}
@@ -0,0 +1,36 @@
var path = require('path');
var fs = require('fs');

// hide warning //
var emitter = require('events');
emitter.defaultMaxListeners = 5;

var appRoot = 'src/';
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));

var paths = {
root: appRoot,
source: appRoot + '**/*.js',
style: 'styles/**/*.css',
output: 'dist/',
doc:'./doc',
test: 'test/**/*.js',
exampleSource: 'doc/example/',
exampleOutput: 'doc/example-dist/',
packageName: pkg.name,
ignore: [],
useTypeScriptForDTS: false,
importsToAdd: [], // eg. non-concated local imports in the main file as they will get removed during the build process
importsToIgnoreForDts: ['extend', 'humane-js'], // imports that are only used internally. no need to d.ts export them
jsResources: [], // js to transpile, but not be concated and keeping their relative path
resources: appRoot + '{**/*.css,**/*.html}',
sort: true,
concat: true
};

// files to be traspiled (and concated if selected)
paths.mainSource = [paths.source].concat(paths.jsResources.map(function(resource) {return '!' + resource;}));
// files to be linted
paths.lintSource = paths.source;

module.exports = paths;
@@ -0,0 +1,184 @@
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 clean = require('gulp-clean');
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'];

function cleanGeneratedCode() {
return through2.obj(function(file, enc, callback) {
file.contents = new Buffer(tools.cleanGeneratedCode(file.contents.toString('utf8')));
this.push(file);
return callback();
});
}

gulp.task('build-index', ['build-resources-index'], function() {
var importsToAdd = paths.importsToAdd.slice();

var src = gulp.src(paths.mainSource);

if (paths.sort) {
src = src.pipe(tools.sortFiles());
}

if (paths.ignore) {
paths.ignore.forEach(function(filename){
src = src.pipe(gulpIgnore.exclude(filename));
});
}

if (!paths.concat) {
return src.pipe(gulp.dest(paths.output));
}

return src
.pipe(through2.obj(function(file, enc, callback) {
if (!file) return callback();
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(jsName))
.pipe(insert.transform(function(contents) {
return tools.createImportBlock(importsToAdd) + contents;
}))
.pipe(gulp.dest(paths.output));
});

gulp.task('build-resources-index', ['copy-resources'], function() {
var src = gulp.src(paths.jsResources, {base: paths.root});

if (paths.ignore) {
paths.ignore.forEach(function(filename){
src = src.pipe(gulpIgnore.exclude(filename));
});
}

return src.pipe(gulp.dest(paths.output));
});

gulp.task('copy-resources', function() {
return gulp.src(paths.resources)
.pipe(gulp.dest(paths.output));
});

function gulpFileFromString(filename, string) {
var src = require('stream').Readable({ objectMode: true });
src._read = function() {
this.push(new gutil.File({ cwd: paths.appRoot, base: paths.output, path: filename, contents: new Buffer(string) }))
this.push(null)
}
return src;
}

function srcForBabel() {
return merge(
gulp.src(paths.output + '**/*.js'),
gulpFileFromString(paths.output + 'index.js', "export * from './" + paths.packageName + "';")
);
}

function srcForTypeScript() {
return gulp
.src(paths.output + paths.packageName + '.js')
.pipe(rename(function (path) {
if (path.extname == '.js') {
path.extname = '.ts';
}
}));
}

compileToModules.forEach(function(moduleType){
gulp.task('build-babel-' + moduleType, function () {
gulp.src(paths.root + '{**/*.css,**/*.html}')
.pipe(gulp.dest(paths.output + moduleType));

return srcForBabel()
.pipe(to5(assign({}, compilerOptions[moduleType]())))
.pipe(cleanGeneratedCode())
.pipe(gulp.dest(paths.output + moduleType));
});

if (moduleType === 'native-modules') return; // typescript doesn't support the combination of: es5 + native modules

gulp.task('build-ts-' + moduleType, function () {
var tsProject = ts.createProject(
compilerTsOptions({ module: moduleType, target: moduleType == 'es2015' ? 'es2015' : 'es5' }), ts.reporter.defaultReporter());
var tsResult = srcForTypeScript().pipe(ts(tsProject));
return tsResult.js
.pipe(gulp.dest(paths.output + moduleType));
});
});

gulp.task('build-dts', function(){
return gulp.src(paths.root + paths.packageName + '.d.ts')
.pipe(gulp.dest(paths.output));
});

gulp.task('fixup-dts', function(){
var importsToAdd = [];
return gulp.src([paths.output + '**/*.d.ts', '!' + paths.output + 'index.d.ts'])
.pipe(through2.obj(function(file, enc, callback) {
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(paths.packageName + '.d.ts'))
.pipe(insert.transform(function(contents) {
importsToAdd = importsToAdd.filter(function(line) {
return !paths.importsToIgnoreForDts.some(function(plugin) {
return line.search(plugin) !== -1;
});
});
return tools.createImportBlock(importsToAdd) + contents;
}))
.pipe(gulp.dest(paths.output));
});

gulp.task('clean-dts', function() {
return gulp.src([
paths.output + '**/*.d.ts',
'!' + paths.output + '{index,' + paths.packageName + '}.d.ts'
], {read: false})
.pipe(clean({force: true}));
});

gulp.task('build', function(callback) {
return runSequence(
'clean',
'build-index',
compileToModules
.map(function(moduleType) { return 'build-babel-' + moduleType })
.concat(['build-dts']),
'fixup-dts',
'clean-dts',
callback
);
});

gulp.task('build-ts', function(callback) {
return runSequence(
'clean',
'build-index',
'build-babel-native-modules',
compileToModules
.filter(function(moduleType) { return moduleType !== 'native-modules' })
.map(function(moduleType) { return 'build-ts-' + moduleType })
.concat(paths.useTypeScriptForDTS ? ['build-dts'] : []),
callback
);
});
Oops, something went wrong.

0 comments on commit 5b4aa11

Please sign in to comment.