-
Notifications
You must be signed in to change notification settings - Fork 33
/
Gruntfile.js
117 lines (109 loc) · 2.68 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
/* eslint-disable camelcase */
/* jshint node:true */
/* global require */
const fs = require( 'fs' );
const blocks = require( './blocks.json' );
module.exports = function( grunt ) {
grunt.loadNpmTasks( 'grunt-version' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
const sassFiles = {};
const sourceFiles = [];
Object.keys( blocks ).filter( block => blocks[ block ].assets !== undefined )
.forEach( block => {
Object.keys( blocks[ block ].assets ).forEach( s => {
if ( blocks[ block ]?.isPro ) {
sassFiles[ `build/pro/${ s }` ] = `src/${ blocks[ block ].assets[ s ] }`;
} else {
sassFiles[ `build/blocks/${ s }` ] = `src/${ blocks[ block ].assets[ s ] }`;
}
sourceFiles.push( `src/${ blocks[ block ].assets[ s ] }` );
});
});
grunt.initConfig({
sass: {
dist: {
options: {
sourcemap: false,
style: 'compressed'
},
files: sassFiles
}
},
watch: {
sass: {
files: sourceFiles,
tasks: [ 'build' ],
options: {
atBegin: true
}
}
},
version: {
json: {
options: {
flags: ''
},
src: [ 'package.json', 'composer.json', 'package-lock.json', 'plugins/blocks-animation/composer.json' ]
},
metatag: {
options: {
prefix: 'Version:\\s*',
flags: ''
},
src: [
'otter-blocks.php',
'plugins/blocks-animation/blocks-animation.php',
'plugins/blocks-css/blocks-css.php',
'plugins/blocks-export-import/blocks-export-imports.php',
'plugins/otter-pro/otter-pro.php'
]
},
php: {
options: {
prefix: 'OTTER_BLOCKS_VERSION\', \'',
flags: ''
},
src: [ 'otter-blocks.php' ]
},
blocks: {
options: {
prefix: 'THEMEISLE_BLOCKS_VERSION\', \'',
flags: ''
},
src: [ 'inc/class-main.php' ]
},
pro: {
options: {
prefix: 'OTTER_PRO_VERSION\', \'',
flags: ''
},
src: [ 'plugins/otter-pro/otter-pro.php' ]
}
},
wp_readme_to_markdown: {
plugin: {
files: {
'readme.md': 'readme.txt',
'plugins/blocks-animation/readme.md': 'plugins/blocks-animation/readme.txt',
'plugins/blocks-css/readme.md': 'plugins/blocks-css/readme.txt',
'plugins/blocks-export-import/readme.md': 'plugins/blocks-export-import/readme.txt'
}
}
}
});
grunt.registerTask( 'build', 'Generate CSS', function() {
const done = this.async();
function checkFlag() {
if ( fs.existsSync( `./build/blocks/${ Object.keys( blocks )[0] }` ) ) {
grunt.task.run( 'sass' );
done();
} else {
grunt.log.writeln( 'Waiting...' );
setTimeout( checkFlag, 5000 );
}
}
checkFlag();
});
};