forked from auth0/lock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
137 lines (130 loc) · 3.62 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
module.exports = function (grunt) {
const pkg_info = grunt.file.readJSON('package.json');
grunt.initConfig({
pkg: pkg_info,
clean: {
build: ['build/'],
dev: ['build/'],
dist: ['lib/']
},
babel: {
dist: {
files: [
{
expand: true,
cwd: 'src',
src: ['**/*.js', '**/*.jsx'],
dest: 'lib',
ext: '.js'
}
]
}
},
env: {
build: {
NODE_ENV: 'production'
}
},
exec: {
touch_index: 'touch src/index.js'
},
webpack: {
build: {
...webpackConfig,
mode: 'production',
devtool: 'source-map',
output: {
path: path.join(__dirname, 'build'),
filename: 'lock.min.js'
},
watch: false,
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new UnminifiedWebpackPlugin(),
new webpack.BannerPlugin({
raw: false,
entryOnly: true,
banner: `lock v${pkg_info.version}\n\nAuthor: ${
pkg_info.author
}\nDate: ${new Date().toLocaleString()}\nLicense: ${pkg_info.license}\n`
})
]
}
},
'webpack-dev-server': {
options: {
output: {
publicPath: '/build/'
}
},
dev: webpackConfig,
design: {
webpack: {
entry: './support/design/index.js',
output: {
path: path.join(__dirname, 'build'),
filename: 'lock.design.js'
},
devtool: 'cheap-module-source-map'
}
}
},
i18n: {
build: {
files: [
{
expand: true,
cwd: 'lib/i18n',
src: '**/*.js',
dest: 'build',
ext: '.js'
}
]
}
}
});
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('build', ['clean:build', 'env:build', 'webpack:build', 'i18n:build']);
grunt.registerTask('dist', ['clean:dist', 'babel:dist']);
grunt.registerTask('prepare_dev', ['clean:dev']);
grunt.registerTask('dev', ['prepare_dev', 'webpack-dev-server:dev']);
grunt.registerTask('design', ['prepare_dev', 'webpack-dev-server:design']);
grunt.registerMultiTask('i18n', 'Prepares i18n files to be hosted in CDN', function () {
var languages = {};
var Auth0 = {
registerLanguageDictionary: function (lang, dict) {
languages[lang] = dict;
}
};
this.files.forEach(function (file) {
var filename = file.src[0];
var lang = path.basename(filename, '.js');
var dict = require('./' + filename).default || require('./' + filename);
var jsonp = `Auth0.registerLanguageDictionary("${lang}", ${JSON.stringify(dict)});`;
eval(jsonp.toString());
if (languages[lang] === undefined) {
grunt.fail.fatal(`Failed to process language file ${filename}`);
}
grunt.file.write(file.dest, jsonp);
grunt.log.ok(`Built ${lang}.js file`);
});
});
};