Skip to content

Commit

Permalink
Merge pull request #99 from geotrev/develop
Browse files Browse the repository at this point in the history
fixes to scripts/ for consistent release versioning and hash creation
  • Loading branch information
geotrev committed Oct 26, 2018
2 parents 55a9a3e + e91ca0e commit ba56bc9
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 53 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ Clone the repo and re-clone the wiki contents.
```sh
$ git clone git@github.com:USER_NAME/undernet.git
$ cd undernet/
$ npm run setup
$ npm install
```

The site is both a demo and marketing tool. It is built with my own webpack setup called [Pulsar](https://github.com/geotrev/pulsar). It's basically just Webpack + React, so don't panic.
The site is both a demo and marketing tool. It is built with my own webpack setup called [Pulsar](https://github.com/geotrev/pulsar). It's basically just Webpack + React, so don't panic. :)

### Run the dev server

Expand Down Expand Up @@ -183,18 +183,19 @@ $ npm run js:watch

### New releases

New releases are simply zipped and compiled files.
New releases are simply zipped and compiled files to be distributed on npm, then for use on a CDN, such as jsdelivr.

To increment the version of the release, run the following command, where `VERSION` is the semver value. E.g., `--tag=2.3.0`. The script will find specific files: `package.json`, `scss/undernet.scss`, and `docs/introduction.md`. It then increments the version, creates new sub-resource integrity hashes, and updates unpkg.com links for CDN access.
To run a release build, run the following two commands, where `VERSION` is the semver value incremented from `package.json`:

```sh
$ update-version --tag=VERSION
$ npm run build:release
```

Then to build assets:
These will do three things:

```sh
$ npm run build:release
```
1. Increment the project version across multiple files that require it.
2. Build all assets with the new version.
3. Generate new sha-256 hashes for CDN access (see `docs/introduction.md`, "Get Started" section).

All that's left is a `npm publish` and the new version is out in the wild!
All that's left is a `npm publish` and the new version is out in the wild! Crazy cool!
2 changes: 1 addition & 1 deletion dist/undernet.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/undernet.bundle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/undernet.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/undernet.css.zip
Binary file not shown.
Binary file modified dist/undernet.js.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/undernet.min.css

Large diffs are not rendered by default.

Binary file modified dist/undernet.modules.js.zip
Binary file not shown.
Binary file modified dist/undernet.scss.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Undernet is extremely light, carrying no external dependencies apart from needin

## Get Started

The quickest way to use Undernet is to link the bundled js and minified css using a CDN, such as [unpkg](https://www.unpkg.com).
The quickest way to use Undernet is to link the bundled js and minified css using a CDN, such as [jsdelivr](https://jsdelivr.com).

```html
<link rel="stylesheet" href="https://unpkg.com/undernet@2.4.0/dist/undernet.min.css" integrity="sha256-aCt3hDWtL1yGzwbbOIz38YAgMVIrMJygL18UZSJ34Tk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/undernet@2.4.1/dist/undernet.min.css" integrity="sha256-bX29Vc8vjuAFBJS+PKK2r9iJOj1aMLn4A1Sj8iH63BM=" crossorigin="anonymous">
```

```html
<script type="text/javascript" src="https://unpkg.com/undernet@2.4.0/dist/undernet.bundle.min.js" integrity="sha256-rOovHww6Dn9bQcTvKoAwZv/Rys+zd9UJQqb21SqCKaE=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/undernet@2.4.1/dist/undernet.bundle.min.js" integrity="sha256-1QnHhJ6tkW1PuBOTUeAPdrzYxcRceAvqJTi4mHxGmZg=" crossorigin="anonymous"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', Undernet.start())
</script>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undernet",
"version": "2.4.0",
"version": "2.4.1",
"homepage": "https://undernet.io",
"description": "Undernet is a Front-End Framework for Modern Web Development",
"main": "js/dist/undernet.js",
Expand All @@ -20,7 +20,8 @@
"framework"
],
"bin": {
"update-version": "./scripts/update-version.js"
"update-version": "./scripts/update-version.js",
"create-hashes": "./scripts/create-hashes.js"
},
"scripts": {
"test": "BABEL_ENV=test nyc mocha -r @babel/register -r config/mocha.config.js --recursive src/**/*.spec.js",
Expand All @@ -30,7 +31,7 @@
"lint": "prettier --write 'src/**/*.js' && prettier --write 'src/**/*.scss'",
"build:development": "npm run build:lint && npm run js:build && npm run css:build && npm run css:minify",
"build:lint": "npm run js:lint && npm run scss:lint",
"build:release": "npm run clean && npm run build:lint && npm run scss:prepublish && npm run css:prepublish && npm run js:prepublish",
"build:release": "npm run clean && npm run build:lint && npm run scss:prepublish && npm run css:prepublish && npm run js:prepublish && create-hashes",
"clean": "rm -rf dist/ && mkdir dist/",
"js:build": "babel js/src/ --out-dir js/dist/",
"js:merge": "BABEL_ENV=rollup rollup -c config/rollup.config.js",
Expand Down
49 changes: 49 additions & 0 deletions scripts/create-hashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node

const fs = require("fs")
const path = require("path")
const Hashes = require("jshashes")

// set up for operations

const distJsFilePath = path.resolve(__dirname, "../dist/undernet.bundle.min.js")
const distCssFilePath = path.resolve(__dirname, "../dist/undernet.min.css")
const introArticleFilePath = path.resolve(__dirname, "../docs/introduction.md")
const readFormat = "utf-8"

// update hashes in docs/introduction.md

const introArticleFile = fs.readFileSync(introArticleFilePath, readFormat)

function createNewHash(str) {
return new Hashes.SHA256().b64(str)
}

// regex pattern to detect base 64 encoded string.
// https://stackoverflow.com/a/31245864
const reb64 = /\"sha256-([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}|[A-Za-z0-9+/]{2})=\"/g

// retrieve existing hashes
const b64Strings = introArticleFile.match(reb64)

// apply new hashes and return new introduction.md
const distCssFile = fs.readFileSync(distCssFilePath, readFormat)
const distJsFile = fs.readFileSync(distJsFilePath, readFormat)
const newCssHash = `"sha256-${createNewHash(distCssFile)}"`
const newJsHash = `"sha256-${createNewHash(distJsFile)}"`

// get new hashes and inject them into docs/introduction.md
function getNewIntroductionArticle() {
const currentCssHash = b64Strings[0]
const currentJsHash = b64Strings[1]
return introArticleFile.replace(currentJsHash, newJsHash).replace(currentCssHash, newCssHash)
}

fs.writeFileSync("docs/introduction.md", getNewIntroductionArticle(), readFormat)
console.log(`
#========================================#
-> New content hashes created! They're used in docs/introduction.md.
- CSS: ${newCssHash.slice(1, -1)}
- JS: ${newJsHash.slice(1, -1)}
`)
Loading

0 comments on commit ba56bc9

Please sign in to comment.