forked from mrvautin/expressCart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.js
83 lines (68 loc) · 2.61 KB
/
deploy.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
const { minify } = require('uglify-es');
const cleanCss = require('clean-css');
const globby = require('globby');
const colors = require('colors');
const { render } = require('less');
const fs = require('fs');
const path = require('path');
const compressJS = async () => {
const publicFiles = globby.sync([
'public/javascripts/*.js',
'!public/javascripts/*.min.js'
], { nosort: true });
// Public JS
publicFiles.forEach(async(file) => {
const minified = await minify(fs.readFileSync(file, 'utf-8'));
const parseFilePath = path.parse(file);
fs.writeFileSync(`${parseFilePath.dir}/${parseFilePath.name}.min.js`, minified.code);
});
const themeFiles = globby.sync([
'views/themes/**/*.js',
'!views/themes/**/*.min.js'
], { nosort: true });
// Theme JS
themeFiles.forEach(async(file) => {
const minified = await minify(fs.readFileSync(file, 'utf-8'));
const parseFilePath = path.parse(file);
fs.writeFileSync(`${parseFilePath.dir}/${parseFilePath.name}.min.js`, minified.code);
});
};
const compressCss = async () => {
const publicOutputPath = path.join('public', 'stylesheets');
const themeOutputPath = path.join('views', 'themes');
const publicFiles = globby.sync([
'public/stylesheets/less/*.less'
], { nosort: true });
publicFiles.forEach(async(file) => {
const parseFilePath = path.parse(file);
// Process the less
const less = await render(fs.readFileSync(file, 'utf-8'), {});
// Write less style
fs.writeFileSync(`${publicOutputPath}/${parseFilePath.name}.css`, less.css);
// Minify css
const minified = await new cleanCss({}).minify(less.css).styles;
// Write minified css
fs.writeFileSync(`${publicOutputPath}/${parseFilePath.name}.min.css`, minified);
});
const themeFiles = globby.sync([
'views/themes/*.less'
], { nosort: true });
themeFiles.forEach(async(file) => {
const parseFilePath = path.parse(file);
// Process the less
const less = await render(fs.readFileSync(file, 'utf-8'), {});
// Write less style
fs.writeFileSync(`${themeOutputPath}/${parseFilePath.name}.css`, less.css);
// Minify css
const minified = await new cleanCss({}).minify(less.css).styles;
// Write minified css
fs.writeFileSync(`${themeOutputPath}/${parseFilePath.name}.min.css`, minified);
});
};
const run = async () => {
await compressJS();
await compressCss();
console.log(colors.green('Complete!'));
};
// Run the deploy tasks
run();