Skip to content

Commit 6294fce

Browse files
committed
Added support for UMD deployment
1 parent 0ba6ad3 commit 6294fce

File tree

3 files changed

+94
-36
lines changed

3 files changed

+94
-36
lines changed

Gruntfile.js

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
module.exports = function (grunt) {
2-
// Project configuration.
2+
33
grunt.initConfig({
4+
45
properties: grunt.file.readJSON('properties.json'),
6+
57
pkg: grunt.file.readJSON('package.json'),
6-
clean: ['<%= properties.webappBuildDir %>'],
7-
sync: [
8-
// copy tests
9-
{expand: true, cwd: '<%= properties.webappTestDir %>', src: '**', dest: '<%= properties.webappBuildDir %>'},
10-
11-
// copy tests resources
12-
{expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1/ttml/**', dest: '<%= properties.webappBuildDir %>'},
13-
{expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1/tests.json', dest: '<%= properties.webappBuildDir %>'},
14-
{expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1_1/ttml/**', dest: '<%= properties.webappBuildDir %>'},
15-
{expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1_1/tests.json', dest: '<%= properties.webappBuildDir %>'},
16-
{expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'unit-tests/**', dest: '<%= properties.webappBuildDir %>'}
17-
],
8+
9+
clean: ['<%= properties.webappBuildDir %>', '<%= properties.umdBuildDir %>'],
10+
11+
sync: {
12+
all: {
13+
files:
14+
[
15+
// copy tests
16+
{ expand: true, cwd: '<%= properties.webappTestDir %>', src: '**', dest: '<%= properties.webappBuildDir %>' },
17+
18+
// copy tests resources
19+
{ expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1/ttml/**', dest: '<%= properties.webappBuildDir %>' },
20+
{ expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1/tests.json', dest: '<%= properties.webappBuildDir %>' },
21+
{ expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1_1/ttml/**', dest: '<%= properties.webappBuildDir %>' },
22+
{ expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'imsc-tests/imsc1_1/tests.json', dest: '<%= properties.webappBuildDir %>' },
23+
{ expand: true, cwd: '<%= properties.unitTestsResourcesDir %>', src: 'unit-tests/**', dest: '<%= properties.webappBuildDir %>' }
24+
]
25+
},
26+
27+
release: {
28+
src: '<%= properties.umdBuildDir %>/<%= properties.umdMinName %>',
29+
dest: '<%= properties.webappBuildDir %>/libs/imsc.js'
30+
},
31+
32+
debug: {
33+
src: '<%= properties.umdBuildDir %>/<%= properties.umdDebugName %>',
34+
dest: '<%= properties.webappBuildDir %>/libs/imsc.js'
35+
}
36+
},
37+
1838
npmcopy: {
1939
default: {
2040
files: {
@@ -28,40 +48,67 @@ module.exports = function (grunt) {
2848
}
2949
}
3050
},
31-
browserify: {
32-
default: {
33-
src: "./src/main/js/main.js",
34-
dest: "<%= properties.webappBuildDir %>/libs/imsc.js",
51+
52+
browserify: [
53+
{
54+
src: "<%= pkg.main %>",
55+
dest: "<%= properties.umdBuildDir %>/<%= properties.umdDebugName %>",
3556
options: {
3657
exclude: ["sax"],
3758
browserifyOptions: {
3859
standalone: 'imsc'
3960
}
4061
}
62+
},
63+
{
64+
src: "<%= pkg.main %>",
65+
dest: "<%= properties.umdBuildDir %>/<%= properties.umdAllDebugName %>",
66+
options: {
67+
browserifyOptions: {
68+
standalone: 'imsc'
69+
}
70+
}
4171
}
42-
},
72+
],
73+
4374
jshint: {
44-
default: {
75+
'default': {
4576
src: "src/main/js",
4677
options: {
4778
"-W032": true
4879
}
4980
}
81+
},
82+
83+
exec: {
84+
minify:
85+
{
86+
cmd: [
87+
"npx google-closure-compiler --js=<%= properties.umdBuildDir %>/<%= properties.umdAllDebugName %> --js_output_file=<%= properties.umdBuildDir %>/<%= properties.umdAllMinName %>",
88+
"npx google-closure-compiler --js=<%= properties.umdBuildDir %>/<%= properties.umdDebugName %> --js_output_file=<%= properties.umdBuildDir %>/<%= properties.umdMinName %>"
89+
].join("&&")
90+
}
5091
}
51-
});
92+
}
93+
94+
);
5295

5396
grunt.loadNpmTasks('grunt-contrib-clean');
5497

5598
grunt.loadNpmTasks('grunt-npmcopy');
5699

57100
grunt.loadNpmTasks('grunt-browserify');
58-
101+
59102
grunt.loadNpmTasks('grunt-contrib-jshint');
60-
103+
61104
grunt.loadNpmTasks('grunt-sync');
62105

63-
grunt.registerTask('build', ['jshint', 'sync', 'npmcopy', 'browserify']);
64-
106+
grunt.loadNpmTasks('grunt-exec');
107+
108+
grunt.registerTask('build:release', ['jshint', 'browserify', 'exec:minify', 'sync:all', 'sync:release', 'npmcopy']);
109+
110+
grunt.registerTask('build:debug', ['jshint', 'browserify', 'exec:minify', 'sync:all', 'sync:debug', 'npmcopy']);
111+
65112
grunt.registerTask('clean', ['clean']);
66113

67114
};

package.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "imsc",
33
"description": "Renders IMSC 1.1 documents to HTML5 fragments",
4-
"version": "1.1.0-beta.1",
4+
"version": "1.1.0-beta.2",
55
"publishConfig": {
6-
"tag" : "dev"
6+
"tag": "dev"
77
},
88
"license": "BSD-2-Clause",
99
"homepage": "https://github.com/sandflow/imscJS",
1010
"bugs": "https://github.com/sandflow/imscJS/issues",
1111
"repository": "github:sandflow/imscJS",
1212
"files": [
1313
"src/main/js",
14-
"README.txt"
14+
"README.txt",
15+
"build/umd"
1516
],
1617
"keywords": [
1718
"imsc1",
@@ -26,20 +27,26 @@
2627
],
2728
"author": "Pierre-Anthony Lemieux <[email protected]>",
2829
"main": "src/main/js/main.js",
30+
"scripts": {
31+
"prepublishOnly": "grunt build:release"
32+
},
2933
"dependencies": {
30-
"node-qunit": "^1.0.0",
3134
"sax": "1.2.1"
3235
},
3336
"devDependencies": {
37+
"browserify": "^16.2.3",
38+
"filesaver.js-npm": "latest",
39+
"google-closure-compiler": "^20180910.1.0",
3440
"grunt": "latest",
35-
"grunt-sync": "latest",
36-
"grunt-contrib-clean": "latest",
37-
"grunt-npmcopy": "latest",
38-
"qunit-assert-close": "latest",
39-
"qunitjs": "latest",
4041
"grunt-browserify": "latest",
42+
"grunt-contrib-clean": "latest",
4143
"grunt-contrib-jshint": "latest",
44+
"grunt-exec": "^3.0.0",
45+
"grunt-npmcopy": "latest",
46+
"grunt-sync": "latest",
4247
"jszip": "latest",
43-
"filesaver.js-npm": "latest"
48+
"node-qunit": "^1.0.0",
49+
"qunit-assert-close": "latest",
50+
"qunitjs": "latest"
4451
}
4552
}

properties.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"name" : "Pierre-Anthony Lemieux <[email protected]>",
32
"webappSrcDir" : "src/main/webapp",
43
"webappTestDir" : "src/test/webapp",
54
"webappBuildDir" : "build/public_html",
6-
"unitTestsResourcesDir" : "src/test/resources"
5+
"unitTestsResourcesDir" : "src/test/resources",
6+
"umdBuildDir" : "build/umd",
7+
"umdAllDebugName" : "imsc.all.debug.js",
8+
"umdDebugName" : "imsc.debug.js",
9+
"umdAllMinName" : "imsc.all.min.js",
10+
"umdMinName" : "imsc.min.js"
711
}

0 commit comments

Comments
 (0)