Skip to content

Commit

Permalink
build: update to use demo build
Browse files Browse the repository at this point in the history
  • Loading branch information
blackfalcon committed Jan 30, 2021
1 parent bf71040 commit c65d38c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ src/*.css

## dist files
dist/
build/

## Karma code coverage reports
coverage/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ Open [localhost:8000](http://localhost:8000/)

### Testing
Automated tests are required for every Auro component. See `.\test\auro-button.test.js` for the tests for this component. Run `npm test` to run the tests and check code coverage. Tests must pass and meet a certain coverage threshold to commit. See [the testing documentation](https://auro.alaskaair.com/support/tests) for more details.

### Demo deployment

To deploy a demo version of the component for review, run `npm run demo:build` to create a `./build` directory that can be pushed to any static server.
7 changes: 3 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<link
rel="stylesheet"
type="text/css"
href="../node_modules/prismjs/themes/prism.css"
href="https://unpkg.com/prismjs@latest/themes/prism.css"
/>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<main></main>

<script type="module">
import 'marked/marked.min.js';
import 'prismjs';
import 'https://unpkg.com/marked@latest/marked.min.js';
import 'https://unpkg.com/prismjs@latest/prism.js';
fetch('/demo/demo.md')
.then((response) => response.text())
.then((text) => {
Expand All @@ -26,7 +26,6 @@
});
</script>
<script type="module" src="../src/auro-button.js"></script>
<script type="module" src="../src/auro-button-light.js"></script>
<script src="https://unpkg.com/@alaskaairux/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
<script src="https://unpkg.com/@alaskaairux/auro-icon@latest/dist/auro-icon__bundled.js" type="module"></script>
<script type="text/javascript">
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@
"sassBuild:demo": "node-sass ./demo/sass/ --output ./demo/css/",
"sassBuild:component": "node-sass ./src/ --output ./src/",
"sassBuild:watch": "nodemon -e scss --watch src --exec npm run sassBuild:dev",
"postCss:component": "node ./scripts/postCss.js"
"postCss:component": "node ./scripts/postCss.js",
"demo:rmBuild": "rm -rf ./build",
"demo:newBuild": "mkdir ./build && mkdir ./build/css && mkdir ./build/demo",
"demo:copyDemo": "copyfiles -u 1 -V './demo/demo.md' ./build/demo",
"demo:copyIndex": "copyfiles -u 1 -V './demo/index.html' ./build",
"demo:updateIndex": "node ./scripts/prepForBuild",
"demo:build": "npm-run-all ciBuild demo:rmBuild demo:newBuild demo:copyIndex demo:copyDemo demo:updateIndex"
},
"husky": {
"hooks": {
Expand Down
31 changes: 31 additions & 0 deletions scripts/prepForBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const bundle = 'auro-button__bundled.js';
const indexFile = './build/index.html';

// File destination.txt will be created or overwritten by default.
let copyFiles = async function() {
fs.copyFile(`./dist/${bundle}`, `./build/${bundle}`, (err) => {
if (err) throw err;
console.log(`${bundle} was copied to ./build dir`);
});

fs.copyFile(`./demo/css/style.css`, `./build/css/style.css`, (err) => {
if (err) throw err;
console.log(`CSS was copied to ./build dir`);
});
}

// Edit string in new index.html file
fs.readFile(indexFile, 'utf8', function (err,data) {
copyFiles();

if (err) {
return console.log(err);
}

const element = data.replace(`../src/auro-button.js`, `auro-button__bundled.js`);

fs.writeFile(indexFile, element, 'utf8', function (err) {
if (err) return console.log(err);
});
});

0 comments on commit c65d38c

Please sign in to comment.