2020-09-07 09:32:59 +02:00
|
|
|
const fs = require('fs');
|
2020-08-25 07:32:00 +02:00
|
|
|
const sass = require('sass');
|
|
|
|
const write = require('write');
|
|
|
|
const rimraf = require('rimraf');
|
|
|
|
const postcss = require('postcss');
|
|
|
|
const cssnano = require('cssnano');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
|
2020-09-14 08:12:09 +02:00
|
|
|
const constants = require('./constants');
|
2020-09-14 08:02:44 +02:00
|
|
|
const log = require('./log');
|
2020-09-07 09:32:59 +02:00
|
|
|
|
2020-08-25 07:32:00 +02:00
|
|
|
async function build() {
|
2020-09-07 09:32:59 +02:00
|
|
|
log('Starting PaperCSS build...');
|
|
|
|
log('Cleaning "dist/, docs/static/assets/paper.css" folder...');
|
2020-08-25 07:32:00 +02:00
|
|
|
|
|
|
|
rimraf.sync('dist', { disableGlob: true });
|
2020-09-14 08:02:44 +02:00
|
|
|
|
2020-09-14 08:12:09 +02:00
|
|
|
if (fs.existsSync(constants.PAPER_DOCS_PATH)) {
|
|
|
|
fs.unlinkSync(constants.PAPER_DOCS_PATH);
|
2020-09-13 19:48:31 +02:00
|
|
|
}
|
2020-08-25 07:32:00 +02:00
|
|
|
|
2020-09-14 08:12:09 +02:00
|
|
|
log('Compiling SCSS to CSS, entrypoint:', constants.ENTRYPOINT_PATH);
|
2020-08-25 07:32:00 +02:00
|
|
|
|
2020-09-14 08:12:09 +02:00
|
|
|
const compiledCSS = sass.renderSync({ file: constants.ENTRYPOINT_PATH });
|
2020-08-25 07:32:00 +02:00
|
|
|
|
2020-09-07 09:32:59 +02:00
|
|
|
log('Processing CSS: autoprefixer...');
|
2020-08-25 07:32:00 +02:00
|
|
|
|
|
|
|
const autoprefixedCSS = await postcss([autoprefixer]).process(compiledCSS.css, { from: undefined });
|
2020-09-07 09:32:59 +02:00
|
|
|
|
|
|
|
log('Processing CSS: cssnano...');
|
|
|
|
|
2020-08-25 07:32:00 +02:00
|
|
|
const minifiedCSS = await postcss([cssnano]).process(autoprefixedCSS.css, { from: undefined });
|
|
|
|
|
2020-09-07 09:32:59 +02:00
|
|
|
log('Writing paper.css and paper.min.css files to dist/ and docs/ folders...');
|
2020-08-25 07:32:00 +02:00
|
|
|
|
2020-09-14 08:12:09 +02:00
|
|
|
write(constants.PAPER_DIST_PATH, autoprefixedCSS.css);
|
|
|
|
write(constants.PAPER_DIST_MIN_PATH, minifiedCSS.css);
|
|
|
|
write(constants.PAPER_DOCS_PATH, autoprefixedCSS.css);
|
2020-08-25 07:32:00 +02:00
|
|
|
|
2020-09-07 09:32:59 +02:00
|
|
|
log('Build done!');
|
2020-08-25 07:32:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build();
|