Skip to content

Commit

Permalink
Have npm package deploy base sass (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
bameyrick authored Feb 13, 2019
1 parent b15861d commit 7817f14
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage/
/fonts/
/img/
/scripts/
/scss/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
!/img/**/*
!/page-templates/**/*
!/scripts/**/*
!/scss/**/*
!/LICENSE
!/package.json
22 changes: 22 additions & 0 deletions lib/generate-npm-package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';

import rimraf from 'rimraf';
import ncp from 'ncp';

const cwd = process.cwd();
const sourcePath = `${cwd}/src`;
Expand All @@ -10,6 +11,7 @@ const templatesPath = `${sourcePath}/styles/page-template`;
const newTemplatesPath = `${cwd}/page-templates`;
const assetFolders = ['css', 'favicons', 'fonts', 'img', 'scripts'];
const builtAssetsFolders = assetFolders.map(folder => `${cwd}/build/${folder}`);
const newSassPath = `${cwd}/scss`;

async function removeExistingFolders() {
const folders = [newComponentsPath, newTemplatesPath, ...assetFolders];
Expand Down Expand Up @@ -107,6 +109,25 @@ async function copyAssets() {
});
}

async function copyBaseSass() {
await createFolder(newSassPath);
await copyDir(`${sourcePath}/scss/helpers`, `${newSassPath}/helpers`);
await copyDir(`${sourcePath}/scss/vars`, `${newSassPath}/vars`);
}

async function copyDir(from, to) {
return new Promise((resolve, reject) => {
ncp(from, to, error => {
if (error) {
throw new Error(error);
reject(error);
} else {
resolve();
}
});
});
}

async function createFolder(folderPath) {
try {
await fs.mkdirSync(folderPath);
Expand Down Expand Up @@ -134,6 +155,7 @@ async function run() {
await copyComponents();
await copyTemplates();
await copyAssets();
await copyBaseSass();
}

run();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test:browserstack": "TEST_ON_BROWSERSTACK=true karma start ./src/tests/config/karma.conf.js && TEST_ON_BROWSERSTACK=true karma start ./src/tests/config/karma.conf.nomodule.js",
"test:local": "KARMA_SINGLE_RUN=false karma start ./src/tests/config/karma.conf.js",
"dedupe-deps": "npx yarn-deduplicate yarn.lock",
"tidy-clean": "rm -rf build css favicons fonts img components page-templates scripts coverage",
"tidy-clean": "rm -rf build css favicons fonts img components page-templates scripts coverage scss",
"npm-bundle": "NODE_ENV=production yarn build && babel-node lib/generate-npm-package.js"
},
"browserslist": [
Expand Down Expand Up @@ -99,6 +99,7 @@
"lodash": "^4.17.11",
"marked": "^0.5.2",
"mocha": "^5.2.0",
"ncp": "^2.0.0",
"node-sass": "^4.10.0",
"node-sass-glob-importer": "^5.2.0",
"nunjucks": "^3.1.4",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6303,6 +6303,11 @@ natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"

ncp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=

needle@^2.2.1:
version "2.2.4"
resolved "https://registry.yarnpkg.com/needle/-/needle-2.2.4.tgz#51931bff82533b1928b7d1d69e01f1b00ffd2a4e"
Expand Down

0 comments on commit 7817f14

Please sign in to comment.