2015-01-05 05:27:45 +08:00
|
|
|
/**
|
|
|
|
* Created by Tivie on 12-11-2014.
|
|
|
|
*/
|
|
|
|
|
2022-04-28 15:38:48 +08:00
|
|
|
const commonmark = require('commonmark-spec');
|
2015-01-05 05:27:45 +08:00
|
|
|
module.exports = function (grunt) {
|
|
|
|
|
2015-07-12 02:12:04 +08:00
|
|
|
if (grunt.option('q') || grunt.option('quiet')) {
|
|
|
|
require('quiet-grunt');
|
|
|
|
}
|
|
|
|
|
2022-03-27 08:05:30 +08:00
|
|
|
/**
|
|
|
|
* Load common tasks for legacy and normal tests
|
|
|
|
*/
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
|
|
grunt.loadNpmTasks('grunt-mocha-test');
|
|
|
|
grunt.loadNpmTasks('grunt-endline');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
|
|
|
2015-01-19 23:43:47 +08:00
|
|
|
// Project configuration.
|
2022-04-28 04:45:10 +08:00
|
|
|
let config = {
|
2015-01-19 23:43:47 +08:00
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
2015-06-01 01:45:33 +08:00
|
|
|
|
2015-01-19 23:43:47 +08:00
|
|
|
concat: {
|
|
|
|
dist: {
|
2022-03-03 20:15:50 +08:00
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
banner: ';/*! <%= pkg.name %> v <%= pkg.version %> - <%= grunt.template.today("dd-mm-yyyy") %> */\n(function(){\n',
|
|
|
|
footer: '}).call(this);\n'
|
|
|
|
},
|
2015-07-11 04:00:21 +08:00
|
|
|
src: [
|
2015-07-13 12:09:03 +08:00
|
|
|
'src/options.js',
|
2015-01-19 23:43:47 +08:00
|
|
|
'src/showdown.js',
|
|
|
|
'src/helpers.js',
|
2022-04-28 04:42:24 +08:00
|
|
|
'src/event.js',
|
refactor(subParsers): change name and directory of subparsers
BREAKING CHANGE: makeHtml subparsers names changed, by prepending 'makehtml.' to them.
Example: 'anchors', subparser is now named 'makehtml.anchors'.
Event names were also changed to reflect this.
Example: 'anchors.before' is now named 'makehtml.anchors.before'.
**To migrate:**
If you have a listener extension, replace the old event name with the new one. Example:
Replace this
```js
showdown.extension('myext', function() {
return [{
type: 'listener',
listeners: {
'anchors.before': function (event, text, converter, options, globals) {
//... some code
return text;
}
}];
});
```
with this
```js
showdown.extension('myext', function() {
return [{
type: 'listener',
listeners: {
'makehtml.anchors.before': function (event, text, converter, options, globals) {
//... some code
return text;
}
}];
});
```
2017-12-17 02:25:44 +08:00
|
|
|
'src/subParsers/makehtml/*.js',
|
2018-07-08 02:05:16 +08:00
|
|
|
'src/subParsers/makemarkdown/*.js',
|
2015-06-01 03:56:28 +08:00
|
|
|
'src/converter.js',
|
2015-01-19 23:43:47 +08:00
|
|
|
'src/loader.js'
|
|
|
|
],
|
|
|
|
dest: 'dist/<%= pkg.name %>.js'
|
2015-07-11 04:00:21 +08:00
|
|
|
},
|
2022-03-03 20:15:50 +08:00
|
|
|
cli: {
|
|
|
|
src: [
|
|
|
|
'src/cli/cli.js'
|
|
|
|
],
|
|
|
|
dest: 'bin/showdown.js'
|
|
|
|
},
|
2015-07-11 04:00:21 +08:00
|
|
|
test: {
|
2015-07-12 02:32:22 +08:00
|
|
|
src: '<%= concat.dist.src %>',
|
2015-07-11 04:00:21 +08:00
|
|
|
dest: '.build/<%= pkg.name %>.js',
|
|
|
|
options: {
|
|
|
|
sourceMap: false
|
|
|
|
}
|
2015-01-19 23:43:47 +08:00
|
|
|
}
|
|
|
|
},
|
2015-06-01 03:56:28 +08:00
|
|
|
|
2015-07-11 04:00:21 +08:00
|
|
|
clean: ['.build/'],
|
|
|
|
|
2015-01-19 23:43:47 +08:00
|
|
|
uglify: {
|
|
|
|
dist: {
|
2022-03-03 20:15:50 +08:00
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
banner: '/*! <%= pkg.name %> v <%= pkg.version %> - <%= grunt.template.today("dd-mm-yyyy") %> */'
|
|
|
|
},
|
2015-01-19 23:43:47 +08:00
|
|
|
files: {
|
|
|
|
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
|
2015-01-05 05:27:45 +08:00
|
|
|
}
|
2022-03-03 20:15:50 +08:00
|
|
|
},
|
|
|
|
cli: {
|
|
|
|
options: {
|
|
|
|
sourceMap: false,
|
|
|
|
banner: '#!/usr/bin/env node'
|
|
|
|
},
|
|
|
|
files: {
|
|
|
|
'bin/showdown.js': ['<%= concat.cli.dest %>']
|
|
|
|
}
|
2015-01-19 23:43:47 +08:00
|
|
|
}
|
|
|
|
},
|
2015-06-01 01:45:33 +08:00
|
|
|
|
2015-10-15 04:44:19 +08:00
|
|
|
endline: {
|
|
|
|
dist: {
|
|
|
|
files: {
|
|
|
|
'dist/<%= pkg.name %>.js': 'dist/<%= pkg.name %>.js',
|
|
|
|
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.min.js'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-19 23:43:47 +08:00
|
|
|
jshint: {
|
2015-06-17 08:26:50 +08:00
|
|
|
options: {
|
2022-02-23 13:04:55 +08:00
|
|
|
jshintrc: '.jshintrc'
|
2015-06-17 08:26:50 +08:00
|
|
|
},
|
2015-01-19 23:43:47 +08:00
|
|
|
files: [
|
|
|
|
'Gruntfile.js',
|
|
|
|
'src/**/*.js',
|
|
|
|
'test/**/*.js'
|
|
|
|
]
|
|
|
|
},
|
2015-06-01 01:45:33 +08:00
|
|
|
|
2017-01-31 13:46:25 +08:00
|
|
|
eslint: {
|
2015-01-19 23:43:47 +08:00
|
|
|
options: {
|
2021-11-10 12:51:01 +08:00
|
|
|
overrideConfigFile: '.eslintrc.json'
|
2015-04-22 23:56:31 +08:00
|
|
|
},
|
2017-01-31 13:46:25 +08:00
|
|
|
target: [
|
|
|
|
'Gruntfile.js',
|
|
|
|
'src/**/*.js',
|
|
|
|
'test/**/*.js'
|
|
|
|
]
|
2015-01-19 23:43:47 +08:00
|
|
|
},
|
2015-06-01 01:45:33 +08:00
|
|
|
|
2015-08-11 09:38:29 +08:00
|
|
|
conventionalChangelog: {
|
2015-05-14 08:59:33 +08:00
|
|
|
options: {
|
2015-08-11 09:38:29 +08:00
|
|
|
changelogOpts: {
|
|
|
|
preset: 'angular'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
release: {
|
|
|
|
src: 'CHANGELOG.md'
|
2015-05-14 08:59:33 +08:00
|
|
|
}
|
2015-01-20 00:27:28 +08:00
|
|
|
},
|
2015-06-01 01:45:33 +08:00
|
|
|
|
2015-08-11 09:37:51 +08:00
|
|
|
conventionalGithubReleaser: {
|
|
|
|
release: {
|
|
|
|
options: {
|
|
|
|
auth: {
|
|
|
|
type: 'oauth',
|
|
|
|
token: process.env.GH_TOEKN
|
|
|
|
},
|
|
|
|
changelogOpts: {
|
|
|
|
preset: 'angular'
|
|
|
|
}
|
2015-10-15 04:44:19 +08:00
|
|
|
}
|
2015-08-11 09:37:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-27 08:05:30 +08:00
|
|
|
mochaTest: {
|
2017-12-22 23:28:41 +08:00
|
|
|
functional: {
|
2022-04-28 04:45:10 +08:00
|
|
|
src: 'test/functional/**/testsuite.*.js',
|
|
|
|
options: {
|
|
|
|
timeout: 3000,
|
|
|
|
ignoreLeaks: true,
|
|
|
|
reporter: 'spec',
|
|
|
|
require: ['test/bootstrap.js']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
commonmark: {
|
|
|
|
src: 'test/functional/makehtml/extra.testsuite.commonmark.js',
|
2015-01-19 23:43:47 +08:00
|
|
|
options: {
|
|
|
|
timeout: 3000,
|
2015-07-15 04:17:27 +08:00
|
|
|
ignoreLeaks: true,
|
2022-03-27 08:05:30 +08:00
|
|
|
reporter: 'spec',
|
|
|
|
require: ['test/bootstrap.js']
|
2015-01-19 23:43:47 +08:00
|
|
|
}
|
|
|
|
},
|
2017-12-22 23:28:41 +08:00
|
|
|
unit: {
|
|
|
|
src: 'test/unit/**/*.js',
|
2015-07-11 09:42:53 +08:00
|
|
|
options: {
|
|
|
|
timeout: 3000,
|
2017-12-22 23:28:41 +08:00
|
|
|
ignoreLeaks: true,
|
2022-03-27 08:05:30 +08:00
|
|
|
reporter: 'spec',
|
|
|
|
require: ['test/bootstrap.js']
|
2015-07-11 09:42:53 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
single: {
|
|
|
|
options: {
|
|
|
|
timeout: 3000,
|
|
|
|
ignoreLeaks: false,
|
2022-03-27 08:05:30 +08:00
|
|
|
reporter: 'spec',
|
|
|
|
require: ['test/bootstrap.js']
|
2015-01-19 23:43:47 +08:00
|
|
|
}
|
2022-03-03 20:15:50 +08:00
|
|
|
},
|
|
|
|
cli: {
|
2022-03-10 20:56:34 +08:00
|
|
|
src: 'test/unit/cli.js',
|
2022-03-03 20:15:50 +08:00
|
|
|
options: {
|
|
|
|
timeout: 3000,
|
|
|
|
ignoreLeaks: false,
|
2022-03-27 08:05:30 +08:00
|
|
|
reporter: 'spec',
|
|
|
|
require: ['test/bootstrap.js']
|
2022-03-03 20:15:50 +08:00
|
|
|
}
|
2015-01-19 23:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
grunt.initConfig(config);
|
2015-01-05 05:27:45 +08:00
|
|
|
|
2017-03-05 13:08:52 +08:00
|
|
|
/**
|
|
|
|
* Generate Changelog
|
|
|
|
*/
|
|
|
|
grunt.registerTask('generate-changelog', function () {
|
|
|
|
'use strict';
|
|
|
|
grunt.loadNpmTasks('grunt-conventional-changelog');
|
|
|
|
grunt.loadNpmTasks('grunt-conventional-github-releaser');
|
|
|
|
grunt.task.run('conventionalChangelog');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lint tasks
|
|
|
|
*/
|
|
|
|
grunt.registerTask('lint', function () {
|
|
|
|
'use strict';
|
|
|
|
grunt.loadNpmTasks('grunt-eslint');
|
|
|
|
grunt.task.run('jshint', 'eslint');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performance task
|
|
|
|
*/
|
|
|
|
grunt.registerTask('performancejs', function () {
|
|
|
|
'use strict';
|
2022-04-28 04:45:10 +08:00
|
|
|
let perf = require('./test/performance/performance.js');
|
2017-03-05 13:08:52 +08:00
|
|
|
perf.runTests();
|
|
|
|
perf.generateLogs();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a single test
|
|
|
|
*/
|
2022-03-10 20:56:34 +08:00
|
|
|
grunt.registerTask('single-test', function (file) {
|
2015-07-11 09:42:53 +08:00
|
|
|
'use strict';
|
|
|
|
grunt.config.merge({
|
2022-03-27 08:05:30 +08:00
|
|
|
mochaTest: {
|
2015-07-11 09:42:53 +08:00
|
|
|
single: {
|
2022-03-10 20:56:34 +08:00
|
|
|
src: file
|
2015-07-11 09:42:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-27 08:05:30 +08:00
|
|
|
grunt.task.run(['lint', 'concat:test', 'mochaTest:single', 'clean']);
|
2015-07-11 09:42:53 +08:00
|
|
|
});
|
|
|
|
|
2022-04-28 15:38:48 +08:00
|
|
|
grunt.registerTask('extract-commonmark-tests', function () {
|
|
|
|
'use strict';
|
|
|
|
let commonmark = require('commonmark-spec');
|
|
|
|
let testsuite = JSON.stringify(commonmark.tests, null, 2);
|
|
|
|
grunt.file.write('test/functional/makehtml/cases/commonmark.testsuite.json', testsuite)
|
|
|
|
});
|
|
|
|
|
2017-03-05 13:08:52 +08:00
|
|
|
/**
|
2017-12-22 23:28:41 +08:00
|
|
|
* Tasks
|
2017-03-05 13:08:52 +08:00
|
|
|
*/
|
2022-03-27 08:05:30 +08:00
|
|
|
grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'mochaTest:unit', 'mochaTest:functional', 'clean']);
|
|
|
|
grunt.registerTask('test-functional', ['concat:test', 'mochaTest:functional', 'clean']);
|
|
|
|
grunt.registerTask('test-unit', ['concat:test', 'mochaTest:unit', 'clean']);
|
|
|
|
grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'mochaTest:cli', 'clean']);
|
2022-04-28 15:38:48 +08:00
|
|
|
grunt.registerTask('test-commonmark', ['clean', 'lint', 'concat:test', 'extract-commonmark-tests', 'mochaTest:commonmark', 'clean']);
|
2022-03-10 20:56:34 +08:00
|
|
|
|
2016-12-23 17:29:58 +08:00
|
|
|
grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
|
2022-03-03 20:15:50 +08:00
|
|
|
grunt.registerTask('build', ['test', 'concat:dist', 'concat:cli', 'uglify:dist', 'uglify:cli', 'endline']);
|
2018-09-24 03:34:54 +08:00
|
|
|
grunt.registerTask('build-without-test', ['concat:dist', 'uglify', 'endline']);
|
2022-03-03 20:15:50 +08:00
|
|
|
grunt.registerTask('prep-release', ['build', 'performance', 'generate-changelog']);
|
2015-01-05 05:27:45 +08:00
|
|
|
|
2022-04-28 04:35:06 +08:00
|
|
|
|
|
|
|
|
2015-01-19 23:43:47 +08:00
|
|
|
// Default task(s).
|
2015-05-27 09:21:36 +08:00
|
|
|
grunt.registerTask('default', ['test']);
|
2015-01-05 05:27:45 +08:00
|
|
|
};
|