Cleanup KnockoutJS

This commit is contained in:
djmaze 2021-09-28 14:40:24 +02:00
parent 4c7ce61bc0
commit 4142526ba6
9 changed files with 121 additions and 279 deletions

View file

@ -13,31 +13,9 @@ module.exports = function(grunt) {
' * License: <%= pkg.licenses[0].type %> (<%= pkg.licenses[0].url %>)\n' +
' */\n\n',
checktrailingspaces: {
main: {
src: [
"**/*.{js,html,css,bat,ps1,sh}",
"!build/output/**",
"!node_modules/**"
],
filter: 'isFile'
}
},
build: {
debug: './build/output/knockout-latest.debug.js',
min: './build/output/knockout-latest.js'
},
dist: {
debug: './dist/knockout.debug.js',
min: './dist/knockout.js'
},
test: {
phantomjs: 'spec/runner.phantom.js',
node: 'spec/runner.node.js'
},
testtypes: {
global: "spec/types/global",
module: "spec/types/module"
}
});
@ -52,25 +30,6 @@ module.exports = function(grunt) {
return !this.errorCount;
});
var trailingSpaceRegex = /[ ]$/;
grunt.registerMultiTask('checktrailingspaces', 'checktrailingspaces', function() {
var matches = [];
this.files[0].src.forEach(function(filepath) {
var content = grunt.file.read(filepath),
lines = content.split(/\r*\n/);
lines.forEach(function(line, index) {
if (trailingSpaceRegex.test(line)) {
matches.push([filepath, (index+1), line].join(':'));
}
});
});
if (matches.length) {
grunt.log.error("The following files have trailing spaces that need to be cleaned up:");
grunt.log.writeln(matches.join('\n'));
return false;
}
});
function getReferencedSources(sourceReferencesFilename) {
// Returns the array of filenames referenced by a file like source-references.js
var result;
@ -134,65 +93,6 @@ module.exports = function(grunt) {
return !this.errorCount;
});
grunt.registerMultiTask('test', 'Run tests', function () {
/*
var done = this.async();
grunt.util.spawn({ cmd: this.target, args: [this.data] },
function (error, result, code) {
if (code === 127) {
// not found
grunt.verbose.error(result.stderr);
// ignore this error
done(true);
} else {
grunt.log.writeln(result.stdout);
if (error)
grunt.log.error(result.stderr);
done(!error);
}
}
);
*/
});
grunt.registerMultiTask('testtypes', 'Run types tests', function () {
/*
var done = this.async(),
target = this.target;
grunt.util.spawn({ cmd: "tsc", args: ["-p", this.data] },
function (error, result, code) {
grunt.log.writeln(result.stdout);
if (error)
grunt.log.error(result.stderr);
else
grunt.log.ok("Knockout TypeScript " + target + " types validated!");
done(!error);
}
);
*/
});
grunt.registerTask('dist', function() {
var version = grunt.config('pkg.version'),
buildConfig = grunt.config('build'),
distConfig = grunt.config('dist');
grunt.file.copy(buildConfig.debug, distConfig.debug);
grunt.file.copy(buildConfig.min, distConfig.min);
console.log('To publish, run:');
console.log(' git add bower.json');
console.log(' git add -f ' + distConfig.debug);
console.log(' git add -f ' + distConfig.min);
console.log(' git checkout head');
console.log(' git commit -m \'Version ' + version + ' for distribution\'');
console.log(' git tag -a v' + version + ' -m \'Add tag v' + version + '\'');
console.log(' git checkout master');
console.log(' git push origin --tags');
});
// Default task.
grunt.registerTask('default', ['clean', 'checktrailingspaces', 'build', 'test', 'testtypes']);
grunt.registerTask('default', ['clean', 'build']);
};