-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
66 lines (52 loc) · 1.53 KB
/
build.js
File metadata and controls
66 lines (52 loc) · 1.53 KB
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
'use strict';
const Fs = require('fs');
const Util = require('util');
const Path = require('path');
const Postcss = require('postcss');
const Cssnano = require('cssnano');
const Package = require('./package');
const Cssnext = require('postcss-cssnext');
const ReadFolder = Util.promisify(Fs.readdir);
const ReadFile = Util.promisify(Fs.readFile);
const WriteFile = Util.promisify(Fs.writeFile);
const header = `/*
Name: ${Package.name}
Version: ${Package.version}
License: ${Package.license}
Author: ${Package.author}
Email: ${Package.email}
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
`;
const build = async function (name, next) {
let result;
const data = await ReadFile('src/' + name + '.css');
// regular
if (next) {
result = await Postcss([Cssnext]).process(data, {
from: 'src/' + name + '.css',
to: 'dst/' + name + '.css'
});
} else {
result = {};
result.css = data;
}
WriteFile('dst/' + name + '.css', `${header}${result.css}`);
// minified
result = await Postcss([Cssnano]).process(result.css, {
from: 'src/' + name + '.css',
to: 'dst/' + name + '.min.css'
});
WriteFile('dst/' + name + '.min.css', `${header}${result.css}`);
};
(async function() {
const items = await ReadFolder('src');
for (let item of items) {
let name = Path.basename(item, '.css');
await build(name, name === 'boxers');
}
}()).catch(function (error) {
console.error(error);
});