mirror of
https://github.com/papercss/papercss
synced 2024-05-19 14:16:39 +02:00
Add constants for build-scripts
This commit is contained in:
parent
270c302e51
commit
53ac2a6b6f
|
@ -1,5 +1,4 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const sass = require('sass');
|
||||
const write = require('write');
|
||||
const rimraf = require('rimraf');
|
||||
|
@ -7,24 +6,22 @@ const postcss = require('postcss');
|
|||
const cssnano = require('cssnano');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
|
||||
const constants = require('./constants');
|
||||
const log = require('./log');
|
||||
|
||||
async function build() {
|
||||
const entrypoint = path.resolve(__dirname, '../src/styles.scss');
|
||||
const paperDocsPath = path.resolve(__dirname, '../docs/static/assets/paper.css');
|
||||
|
||||
log('Starting PaperCSS build...');
|
||||
log('Cleaning "dist/, docs/static/assets/paper.css" folder...');
|
||||
|
||||
rimraf.sync('dist', { disableGlob: true });
|
||||
|
||||
if (fs.existsSync(paperDocsPath)) {
|
||||
fs.unlinkSync(paperDocsPath);
|
||||
if (fs.existsSync(constants.PAPER_DOCS_PATH)) {
|
||||
fs.unlinkSync(constants.PAPER_DOCS_PATH);
|
||||
}
|
||||
|
||||
log('Compiling SCSS to CSS, entrypoint:', entrypoint);
|
||||
log('Compiling SCSS to CSS, entrypoint:', constants.ENTRYPOINT_PATH);
|
||||
|
||||
const compiledCSS = sass.renderSync({ file: entrypoint });
|
||||
const compiledCSS = sass.renderSync({ file: constants.ENTRYPOINT_PATH });
|
||||
|
||||
log('Processing CSS: autoprefixer...');
|
||||
|
||||
|
@ -34,14 +31,11 @@ async function build() {
|
|||
|
||||
const minifiedCSS = await postcss([cssnano]).process(autoprefixedCSS.css, { from: undefined });
|
||||
|
||||
const paperPath = path.resolve(__dirname, '../dist/paper.css');
|
||||
const paperminpath = path.resolve(__dirname, '../dist/paper.min.css');
|
||||
|
||||
log('Writing paper.css and paper.min.css files to dist/ and docs/ folders...');
|
||||
|
||||
write(paperPath, autoprefixedCSS.css);
|
||||
write(paperminpath, minifiedCSS.css);
|
||||
write(paperDocsPath, autoprefixedCSS.css);
|
||||
write(constants.PAPER_DIST_PATH, autoprefixedCSS.css);
|
||||
write(constants.PAPER_DIST_MIN_PATH, minifiedCSS.css);
|
||||
write(constants.PAPER_DOCS_PATH, autoprefixedCSS.css);
|
||||
|
||||
log('Build done!');
|
||||
}
|
||||
|
|
8
build/constants.js
Normal file
8
build/constants.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
ENTRYPOINT_PATH: path.resolve(__dirname, '../src/styles.scss'),
|
||||
PAPER_DIST_PATH: path.resolve(__dirname, '../dist/paper.css'),
|
||||
PAPER_DIST_MIN_PATH: path.resolve(__dirname, '../dist/paper.min.css'),
|
||||
PAPER_DOCS_PATH: path.resolve(__dirname, '../docs/static/assets/paper.css'),
|
||||
};
|
|
@ -1,23 +1,26 @@
|
|||
const util = require('util');
|
||||
const path = require('path');
|
||||
const sass = require('sass');
|
||||
const write = require('write');
|
||||
const postcss = require('postcss');
|
||||
const chokidar = require('chokidar');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
|
||||
const constants = require('./constants');
|
||||
const log = require('./log');
|
||||
|
||||
const sassRenderPromisified = util.promisify(sass.render);
|
||||
|
||||
const entrypoint = path.resolve(__dirname, '../src/styles.scss');
|
||||
const paperDocsPath = path.resolve(__dirname, '../docs/static/assets/paper.css');
|
||||
|
||||
chokidar.watch('./src/**/*.scss').on('change', (event, path) => {
|
||||
log(`Detected file change (${event}), re-building compiled CSS...`);
|
||||
|
||||
sassRenderPromisified({ file: entrypoint })
|
||||
function compile() {
|
||||
sassRenderPromisified({ file: constants.ENTRYPOINT_PATH })
|
||||
.then((compiledCSS) => postcss([autoprefixer]).process(compiledCSS.css.toString(), { from: undefined }))
|
||||
.then((autoprefixedCSS) => write(paperDocsPath, autoprefixedCSS.css))
|
||||
.then(() => log('Re-built compiled CSS.'));
|
||||
.then((autoprefixedCSS) => write(constants.PAPER_DOCS_PATH, autoprefixedCSS.css))
|
||||
.then(() => log('Compiled CSS in docs/ folder.'));
|
||||
}
|
||||
|
||||
chokidar.watch('./src/**/*.scss').on('change', (event) => {
|
||||
log(`Detected file change (${event}), compiling SCSS to CSS...`);
|
||||
compile();
|
||||
});
|
||||
|
||||
// Do initial compilation.
|
||||
compile();
|
||||
|
|
Loading…
Reference in a new issue