Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"scripts": {
"build": "./songs-to-json && pug-pack src && cp Songbook.pdf dist && cp qr-code.svg dist",
"postinstall": "patch-package",
"build": "node songs-to-json.js && pug-pack src && node -e \"const fs=require('fs');for(const f of ['Songbook.pdf','qr-code.svg'])fs.cpSync(f,'dist/'+f)\"",
"booklet": "node node_modules/markdown-booklet/src/cli.js build booklet/book.yaml --out booklet/sea-shanties.html",
"booklet:proof": "node node_modules/markdown-booklet/src/cli.js build booklet/book.yaml --reading --out booklet/proof.html",
"booklet:single": "node node_modules/markdown-booklet/src/cli.js build booklet/book.yaml --single --out booklet/sea-shanties-single.html",
"scaleL": "coffee src/transform.coffee scaleL",
"dev": "nodemon -w src -w songs -i src/songs.json -i src/by-title.json -e '*' -x npm run build"
"dev": "nodemon -w src -w songs -i src/songs.json -i src/by-title.json -e \"*\" -x npm run build"
},
"dependencies": {
"coffeescript": "^2.7.0",
"markdown-booklet": "chrisglein/markdown-booklet",
"mathjs": "^11.10.0",
"nodemon": "^2.0.22",
"patch-package": "^8.0.1",
"pug-pack": "brewingcode/pug-pack"
}
}
67 changes: 67 additions & 0 deletions patches/pug-pack+1.11.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/node_modules/pug-pack/lib/build.coffee b/node_modules/pug-pack/lib/build.coffee
index da9318b..359c63a 100644
--- a/node_modules/pug-pack/lib/build.coffee
+++ b/node_modules/pug-pack/lib/build.coffee
@@ -66,13 +66,18 @@ module.exports = self =

out

+ # compile :coffeescript blocks with our bundled compiler, so the build
+ # doesn't depend on pug hoisting jstransformer-coffeescript to top-level
+ coffeescript: (text, options) ->
+ coffeescript.compile text
+
# replacement for path.parse(), but in the context of this module
parsename: (f) ->
parts = path.parse f
parts.ext = parts.ext.replace /^\./, ''
parts.absfile = path.resolve self.vars.basedir, f
parts.absdir = path.resolve self.vars.basedir
- parts.srcname = parts.absfile.replace(new RegExp(parts.absdir, 'i'), '').replace(/^\//, '')
+ parts.srcname = path.relative(parts.absdir, parts.absfile).split(path.sep).join('/')
self.vars.files[parts.srcname] = parts.absfile
parts

@@ -176,23 +181,33 @@ module.exports = self =
# 1, for example
crawl: (rootDir, skipPug) ->
self.vars.basedir = path.resolve rootDir
+ gitOpts = { cwd: self.vars.basedir }
+
+ walkFiles = (dir) ->
+ results = []
+ for entry in fs.readdirSync dir
+ full = path.join dir, entry
+ if fs.statSync(full).isDirectory()
+ results = results.concat walkFiles full
+ else
+ results.push full
+ results

- execAsync("cd '#{self.vars.basedir}' && git rev-parse --short HEAD").then (stdout) =>
+ execAsync("git rev-parse --short HEAD", gitOpts).then (stdout) =>
self.vars.src.GIT_HEAD = stdout.toString().trim()
- .catch ->
+ .catch =>
self.vars.src.GIT_HEAD = null
-
- if head = self.vars.src.GIT_HEAD
- execAsync("cd '#{self.vars.basedir}' && git tag --points-at #{head}").then (stdout) =>
+ .then =>
+ return unless head = self.vars.src.GIT_HEAD
+ execAsync("git tag --points-at #{head}", gitOpts).then (stdout) =>
self.vars.src.GIT_TAGS = stdout.toString().split('\n').filter (s) -> s.match(/\S/)
- .catch ->
+ .catch =>
self.vars.src.GIT_TAGS = []
-
- execAsync("find '#{self.vars.basedir}' -type f -print0").then (stdout) =>
+ .then =>
pug_files = []
other_files = []

- stdout.split('\0').forEach (f) =>
+ walkFiles(self.vars.basedir).forEach (f) =>
return unless f
{ name, ext, srcname } = self.parsename f
if name.match(/^_/)
29 changes: 0 additions & 29 deletions songs-to-json

This file was deleted.

27 changes: 27 additions & 0 deletions songs-to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs');
const path = require('path');

const songsDir = 'songs';
const songs = {};
const byTitle = {};

for (const f of fs.readdirSync(songsDir)) {
if (!/\.txt$/i.test(f)) continue;

const buf = fs.readFileSync(path.join(songsDir, f));
let song = buf.toString('utf8');
if (song.includes('\uFFFD')) song = buf.toString('latin1');
song = song.replace(/\r\n/g, '\n');

songs[f] = song;

const m = song.match(/^T:\s*(.*)/m);
if (m) {
byTitle[m[1]] = song;
} else {
console.log('weird song:', f);
}
}

fs.writeFileSync('src/songs.json', JSON.stringify(songs));
fs.writeFileSync('src/by-title.json', JSON.stringify(byTitle));
Loading