Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate grunt-dojo2 and redo distributions #80

Merged
merged 14 commits into from
May 18, 2016
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!/*.js
!tests/**/*.js
!tasks/**/*.js
/typings
dist
_build
node_modules
Expand Down
13 changes: 10 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/_build
/support
/tests
/typings
.editorconfig
.gitattributes
.gitignore
.npmignore
.sublimets
.travis.yml
tests/
Gruntfile.js
coverage-final.lcov
coverage-unmapped.json
tsconfig.json
tslint.json
*.ts
320 changes: 14 additions & 306 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,345 +1,53 @@
/* jshint node:true */

function mixin(destination) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
destination[key] = source[key];
}
}
return destination;
}

module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-tslint');
grunt.loadNpmTasks('dts-generator');
grunt.loadNpmTasks('intern');
grunt.loadNpmTasks('remap-istanbul');

grunt.loadTasks('tasks');

var tsconfigContent = grunt.file.read('tsconfig.json');
var tsconfig = JSON.parse(tsconfigContent);
var tsOptions = mixin({}, tsconfig.compilerOptions, {
failOnTypeErrors: true,
fast: 'never'
});
tsconfig.filesGlob = tsconfig.filesGlob.map(function (glob) {
if (/^\.\//.test(glob)) {
// Remove the leading './' from the glob because grunt-ts
// sees it and thinks it needs to create a .baseDir.ts which
// messes up the "dist" compilation
return glob.slice(2);
}
return glob;
});
var packageJson = grunt.file.readJSON('package.json');

grunt.initConfig({
name: packageJson.name,
version: packageJson.version,
tsconfig: tsconfig,
tsconfigContent: tsconfigContent,
packageJson: packageJson,
all: [ '<%= tsconfig.filesGlob %>' ],
skipTests: [ '<%= all %>' , '!tests/**/*.ts' ],
staticTestFiles: 'tests/**/*.{html,css,js}',
devDirectory: '<%= tsconfig.compilerOptions.outDir %>',
istanbulIgnoreNext: '/* istanbul ignore next */',

clean: {
dist: {
src: [ 'dist/' ]
},
dev: {
src: [ '<%= devDirectory %>' ]
},
src: {
src: [ '{src,tests}/**/*.js' ],
filter: function (path) {
// Only clean the .js file if a .js.map file also exists
var mapPath = path + '.map';
if (grunt.file.exists(mapPath)) {
grunt.file.delete(mapPath);
return true;
}
return false;
}
},
report: {
src: [ 'html-report/', 'coverage-final.json' ]
},
coverage: {
src: [ 'coverage-unmapped.json' ]
}
},

copy: {
staticFiles: {
expand: true,
cwd: '.',
src: [ 'README.md', 'LICENSE', 'package.json', 'bower.json' ],
dest: 'dist/'
},
staticTestFiles: {
expand: true,
cwd: '.',
src: [ '<%= staticTestFiles %>' ],
dest: '<%= devDirectory %>'
},
typings: {
expand: true,
cwd: 'typings/',
src: [ '**/*.d.ts', '!tsd.d.ts' ],
dest: 'dist/typings/'
}
},

dtsGenerator: {
options: {
baseDir: 'src',
name: '<%= name %>'
},
dist: {
options: {
out: 'dist/typings/<%= name %>/<%= name %>.d.ts'
},
src: [ '<%= skipTests %>' ]
}
},

intern: {
options: {
runType: 'runner',
config: '<%= devDirectory %>/tests/intern',
reporters: [ 'Runner' ]
},
remote: {},
local: {
options: {
config: '<%= devDirectory %>/tests/intern-local'
}
},
node: {
options: {
runType: 'client'
}
},
proxy: {
options: {
proxyOnly: true
}
}
},

release: {
options: {
// Update the bower.json version as well
additionalFiles: [ 'bower.json' ],
// Run tasks after the version has been updated in package.json and bower.json
afterBump: [ 'clean', 'dist' ],
// Publish the "dist/" directory to npm
folder: 'dist/',
commitMessage: 'Updating source version to <%= version %>',
tagMessage: 'Release <%= version %>',
// Update the `version` property on the `packageJson` object.
updateVars: [ packageJson ]
}
},

rename: {
sourceMaps: {
expand: true,
cwd: 'dist/',
src: [ '**/*.js.map', '!_debug/**/*.js.map' ],
dest: 'dist/_debug/'
}
},

rewriteSourceMaps: {
dist: {
src: [ 'dist/_debug/**/*.js.map' ]
}
},

replace: {
addIstanbulIgnore: {
src: [ '<%= devDirectory %>/**/*.js' ],
overwrite: true,
replacements: [
{
from: /^(var __(?:extends|decorate) = )/gm,
to: '$1<%= istanbulIgnoreNext %> '
},
{
from: /^(\()(function \(deps, )/m,
to: '$1<%= istanbulIgnoreNext %> $2'
}
]
}
},

require('grunt-dojo2').initConfig(grunt, {
/* loader has to build in a slightly different way than the standard Dojo 2 package */
ts: {
options: tsOptions,
dev: {
outDir: '<%= devDirectory %>',
src: [ '<%= all %>' ]
},
tests: {
options: {
module: 'umd'
},
outDir: '<%= devDirectory %>/tests',
src: [ 'tests/**/*.ts', 'typings/tsd.d.ts', 'src/interfaces.d.ts' ]
},
dist: {
options: {
mapRoot: '../dist/_debug',
sourceMap: true
},
outDir: 'dist',
src: [ '<%= skipTests %>', 'tests/typings/node/node.d.ts' ]
}
},

tslint: {
options: {
configuration: grunt.file.readJSON('tslint.json')
},
src: {
src: [
'<%= all %>',
'!typings/**/*.ts',
'!tests/typings/**/*.ts'
]
}
},

watch: {
grunt: {
options: {
reload: true
},
files: [ 'Gruntfile.js', 'tsconfig.json' ]
},
src: {
options: {
atBegin: true
},
files: [ '<%= all %>', '<%= staticTestFiles %>' ],
tasks: [
'dev'
]
}
},

remapIstanbul: {
coverage: {
options: {
reports: {
'html': 'html-report',
'text': null
}
},
src: [ 'coverage-unmapped.json' ]
},
ci: {
options: {
reports: {
'lcovonly': 'coverage-final.lcov',
'json': 'coverage-final.json',
'text': null
}
},
src: [ 'coverage-unmapped.json' ]
src: [ 'tests/**/*.ts', 'typings/index.d.ts', 'src/interfaces.d.ts' ]
}
},

/* loader has minification built into the package, eventually this should be moved to grunt-dojo2 */
uglify: {
dist: {
options: {
banner: '/*! <%= name %>@<%= version %> - Copyright (c) 2015, The Dojo Foundation. ' +
banner: '/*! <%= name %>@<%= version %> - Copyright (c) 2016, The Dojo Foundation. ' +
'All rights reserved. */',
sourceMap: true,
sourceMapName: 'dist/_debug/loader.min.js.map',
sourceMapName: 'dist/umd/_debug/loader.min.js.map',
sourceMapIncludeSources: true,
sourceMapIn: 'dist/_debug/loader.js.map',
sourceMapIn: 'dist/umd/_debug/loader.js.map',
compress: {
dead_code: true,
unsafe: true
}
},
files: {
'dist/loader.min.js': 'dist/loader.js'
'dist/umd/loader.min.js': 'dist/umd/loader.js'
}
}
}
});

// Set some Intern-specific options if specified on the command line.
[ 'suites', 'functionalSuites', 'grep' ].forEach(function (option) {
var value = grunt.option(option);
if (value) {
if (option !== 'grep') {
value = value.split(',').map(function (string) { return string.trim(); });
}
grunt.config('intern.options.' + option, value);
}
});

function setCombined(combined) {
if (combined) {
grunt.config('intern.options.reporters', [
{ id: 'tests/support/Reporter', file: 'coverage-unmapped.json' }
]);
}
}
setCombined(grunt.option('combined'));

grunt.registerTask('test', function () {
var flags = Object.keys(this.flags);

if (!flags.length) {
flags.push('node');
}

grunt.option('force', true);
grunt.task.run('clean:coverage');
grunt.task.run('dev');
setCombined(true);
flags.forEach(function (flag) {
grunt.task.run('intern:' + flag);
});
grunt.task.run('remapIstanbul:coverage');
grunt.task.run('clean:coverage');
});

/* we have to write the dev task from the default because of the need to copy compile the tests differently */
grunt.registerTask('dev', [
'typings',
'tslint',
'clean:dev',
'ts:dev',
'ts:tests',
'copy:staticTestFiles',
'replace:addIstanbulIgnore',
'updateTsconfig'
]);
grunt.registerTask('dist', [
'tslint',
'ts:dist',
'rename:sourceMaps',
'rewriteSourceMaps',
'copy:typings',
'copy:staticFiles',
'dtsGenerator:dist',
'updatePackageJson',
'uglify:dist'
]);
grunt.registerTask('test-proxy', [ 'dev', 'intern:proxy' ]);
grunt.registerTask('default', [ 'clean', 'dev' ]);

/* we also have to add the uglify task */
grunt.registerTask('dist', grunt.config.get('distTasks').concat('uglify:dist'));
};
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The "New" BSD License
*********************

Copyright (c) 2015, The Dojo Foundation
Copyright (c) 2015-2016, The Dojo Foundation
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Loading