Skip to content

Commit

Permalink
GitHub Issue #34 - add releaseId to build artifact (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
oakmac authored Feb 21, 2023
1 parent acad0ce commit 6f6ad18
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 11 deletions.
59 changes: 48 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const md5 = require('md5')
const kidif = require('kidif')
const marked = require('marked')
const shell = require('shelljs')

const hashLength = 15

Expand All @@ -13,8 +14,8 @@ module.exports = function (grunt) {
function splitSection (str) {
const lines = str.split('\n')
const lines2 = []
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim()
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim()
if (line !== '') {
lines2.push(line)
}
Expand All @@ -23,22 +24,22 @@ module.exports = function (grunt) {
}

function docsToObj (docsArr) {
var docs = {}
const docs = {}

for (var i = 0; i < docsArr.length; i++) {
var symbol = docsArr[i]
for (let i = 0; i < docsArr.length; i++) {
const symbol = docsArr[i]

docs[symbol.name] = {}
docs[symbol.name]['full-name'] = symbol.name
docs[symbol.name]['signature'] = splitSection(symbol.signature)
docs[symbol.name].signature = splitSection(symbol.signature)
docs[symbol.name]['description-html'] = marked(symbol.description)

if (symbol.related) {
docs[symbol.name]['related'] = splitSection(symbol.related)
docs[symbol.name].related = splitSection(symbol.related)
}

if (symbol.type) {
docs[symbol.name]['type'] = symbol.type
docs[symbol.name].type = symbol.type
}
}

Expand All @@ -51,8 +52,8 @@ module.exports = function (grunt) {
const symbolsWeNeed = require('./symbols.json')

// build only the symbols we need for the cheatsheet
var docsWeNeed = {}
for (var i = 0; i < symbolsWeNeed.length; i++) {
const docsWeNeed = {}
for (let i = 0; i < symbolsWeNeed.length; i++) {
const cljsName = symbolsWeNeed[i].replace('clojure.core', 'cljs.core')
const clojureName = symbolsWeNeed[i].replace('cljs.core', 'clojure.core')

Expand Down Expand Up @@ -91,6 +92,31 @@ module.exports = function (grunt) {
grunt.log.writeln('Everything looks ok for a build.')
}

function nowStr () {
const opts = {
day: '2-digit',
hour12: false,
month: '2-digit',
year: 'numeric'
}
const now = new Date()
const timeStr = now.toLocaleTimeString('en-US', opts)
const year = timeStr.substring(6, 10)
const month = timeStr.substring(0, 2)
const day = timeStr.substring(3, 5)
const hours = timeStr.substring(12, 14)
const minutes = timeStr.substring(15, 17)
const seconds = timeStr.substring(18, 20)

return year + '-' + month + '-' + day + '-' + hours + minutes + seconds
}

function createReleaseId () {
const gitFullHash = shell.exec('git rev-parse HEAD', { silent: true }).stdout.trim()
const gitShortHash = gitFullHash.substr(0, 10)
return nowStr() + '-' + gitShortHash
}

// FIXME: re-write this to be more generic please :)
function hashAssets () {
const unhashedDocsFilename = '00_build/docs.HASHME.json'
Expand Down Expand Up @@ -136,6 +162,15 @@ module.exports = function (grunt) {
'00_build/js/cheatsheet.min.' + jsHash + '.js')
}

function addReleaseId () {
const htmlFile = grunt.file.read('00_build/index.html')
const releaseId = createReleaseId()
const updatedFile = htmlFile.replace('<html>', '<html data-release-id="' + releaseId + '">')

grunt.file.write('00_build/index.html', updatedFile)
grunt.log.writeln('Tagged 00_build/index.html with releaseId: ' + releaseId)
}

// ---------------------------------------------------------------------------
// Grunt Config
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -202,13 +237,15 @@ module.exports = function (grunt) {
grunt.registerTask('docs', buildDocs)
grunt.registerTask('pre-build-sanity-check', preBuildSanityCheck)
grunt.registerTask('hash-assets', hashAssets)
grunt.registerTask('add-release-id', addReleaseId)

grunt.registerTask('build', [
'pre-build-sanity-check',
'clean:pre',
'copy:cheatsheet',
'clean:post',
'hash-assets'
'hash-assets',
'add-release-id'
])

grunt.registerTask('default', 'watch')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"kidif": "1.1.0",
"marked": "0.3.18",
"md5": "2.2.1",
"shelljs": "0.8.5",
"snowflake-css": "0.1.0"
}
}
78 changes: 78 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==

gaze@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/gaze/-/gaze-1.1.2.tgz#847224677adb8870d679257ed3388fdb61e40105"
Expand Down Expand Up @@ -582,6 +587,18 @@ [email protected], glob@^7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0:
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.1.1"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.5, glob@~7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
Expand Down Expand Up @@ -743,6 +760,13 @@ has-flag@^3.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=

has@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==
dependencies:
function-bind "^1.1.1"

hawk@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
Expand Down Expand Up @@ -821,6 +845,11 @@ inherits@2, [email protected], inherits@~2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

interpret@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==

[email protected]:
version "1.5.2"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.5.2.tgz#d4b505bde9946987ccf0fc58d9010ff9607e3fa0"
Expand All @@ -839,6 +868,13 @@ is-builtin-module@^1.0.0:
dependencies:
builtin-modules "^1.0.0"

is-core-module@^2.9.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144"
integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==
dependencies:
has "^1.0.3"

is-finite@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa"
Expand Down Expand Up @@ -1030,6 +1066,13 @@ mime@^1.2.11:
dependencies:
brace-expansion "^1.1.7"

minimatch@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
dependencies:
brace-expansion "^1.1.7"

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
Expand Down Expand Up @@ -1151,6 +1194,11 @@ path-is-absolute@^1.0.0, path-is-absolute@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"

path-parse@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==

[email protected]:
version "0.1.7"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
Expand Down Expand Up @@ -1263,6 +1311,13 @@ read-pkg@^1.0.0:
normalize-package-data "^2.3.2"
path-type "^1.0.0"

rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
integrity sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==
dependencies:
resolve "^1.1.6"

redent@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde"
Expand Down Expand Up @@ -1313,6 +1368,15 @@ require-main-filename@^2.0.0:
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==

resolve@^1.1.6:
version "1.22.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177"
integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==
dependencies:
is-core-module "^2.9.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@~1.1.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
Expand Down Expand Up @@ -1386,6 +1450,15 @@ [email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656"

[email protected]:
version "0.8.5"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"

signal-exit@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down Expand Up @@ -1511,6 +1584,11 @@ supports-color@^6.1.0:
dependencies:
has-flag "^3.0.0"

supports-preserve-symlinks-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

tiny-lr@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/tiny-lr/-/tiny-lr-0.2.1.tgz#b3fdba802e5d56a33c2f6f10794b32e477ac729d"
Expand Down

0 comments on commit 6f6ad18

Please sign in to comment.