-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
100 lines (84 loc) · 2.66 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
const findUsedJsFiles = (grunt) => {
const file = grunt.file.read('snippets/js.liquid', 'utf8');
const regex = /'([0-9a-zA-Z\-_\.]*.js)' \| asset_url/gm;
let jsFiles = [];
let m;
while ((m = regex.exec(file)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
jsFiles.push(`assets/js/**/${m[1]}`);
}
return jsFiles;
};
const findUsedJsLibs = (grunt) => {
const file = grunt.file.read('snippets/js.liquid', 'utf8');
const regex = /src="(http[0-9a-zA-Z\-_\.\/:]*)*"/gm;
let jsFiles = [];
let m;
while ((m = regex.exec(file)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
jsFiles.push(`${m[1]}`);
}
return jsFiles;
};
module.exports = function (grunt) {
let shopifyConfig = grunt.file.readJSON('config.json', 'utf8');
grunt.initConfig({
jsFiles: findUsedJsFiles(grunt),
jsLibs: findUsedJsLibs(grunt),
theme: grunt.file.readJSON('config/settings_schema.json', 'utf8')[0],
pkg: grunt.file.readJSON('package.json'),
install: {
options: {
env: ['default', 'staging', 'production']
}
},
shopify: {
options: {
auth: shopifyConfig,
files: [
'assets/theme.min.js',
'assets/theme.js',
'assets/theme.min.css',
'assets/theme.css',
'assets/**/*',
'config/*',
'layout/*',
'locales/*',
'sections/*',
'snippets/*',
'templates/*'
]
}
}
});
const tasks = grunt.file.expand({ filter: 'isFile', cwd: 'tasks' }, ['*']);
tasks.forEach(task => {
require(`./tasks/${task}`)(grunt);
});
grunt.event.on('watch', function (action, filepath) {
grunt.config.set('shopify.options.files', filepath.replace(/\\/g, '/'));
grunt.config.set('shopify.options.mode', action);
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-purgecss');
grunt.loadNpmTasks('grunt-csso');
grunt.loadNpmTasks('grunt-complexity');
grunt.registerTask('dev-js', ['complexity', 'jshint']);
grunt.registerTask('dev', ['dev-js']);
grunt.registerTask('js', ['dev-js', 'clean:js', 'libs', 'concat:js', 'babel', 'headers:js']);
grunt.registerTask('css', ['clean:css','postcss', 'concat:css', 'purgecss', 'csso', 'headers:css']);
grunt.registerTask('build', ['css', 'js']);
grunt.registerTask('deploy', ['build', 'shopify:deploy']);
grunt.registerTask('deploy:staging', ['build', 'shopify:deploy:staging']);
grunt.registerTask('deploy:prod', ['build', 'shopify:deploy:production']);
grunt.registerTask('init', ['install', 'deploy']);
grunt.registerTask('default', ['watch']);
};