From 413a8b5b81af93c7d4477961013bcb41d3a5afdf Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 12 Dec 2019 00:33:59 -0500 Subject: [PATCH] Switch to good old make to reduce redundancies in build --- Makefile | 62 ++++++++++++++++++++++++++++++++++++++++++++ doc/gendoc.litcoffee | 16 ++++++++---- doc/tech.md | 5 ++-- package.json | 13 +--------- 4 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1dfe971 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +GENEXT = src/helpers/pkglock_to_externals.litcoffee +GENDOC = doc/gendoc.litcoffee +DOCFILES = $(shell coffee $(GENDOC) -list) +COFFILES = $(wildcard src/*.litcoffee) +JSFILES = $(patsubst src/%.litcoffee,site/%.js,$(COFFILES)) +HTMLSRC = $(wildcard src/*.html) +HTMLSITE = $(patsubst src/%,site/%,$(HTMLSRC)) +BLDTARGS = $(JSFILES) site/externals.js site/doc/dyna3.html $(HTMLSITE) site/node_modules +TESTCOFF = $(wildcard coffeetest/*.coffee) +TESTJS = $(patsubst coffeetest/%.coffee,__tests__/%.js,$(TESTCOFF)) + +build: $(BLDTARGS) + +site/externals.js: $(GENEXT) package.json package-lock.json + mkdir -p site + coffee $(GENEXT) > $@ + +site/%.js: src/%.litcoffee + coffee -o $@ -c -m $< + +docbuild/extlist.md: $(GENEXT) package.json package-lock.json + mkdir -p docbuild + coffee $(GENEXT) --doc > $@ + +site/doc/dyna3.md: $(DOCFILES) + mkdir -p site/doc + coffee $(GENDOC) > $@ + +site/doc/dyna3.html: site/doc/dyna3.md + pandoc -s --metadata title='dyna3' --toc $< > $@ + +site/%.html: src/%.html + mkdir -p site + cp $< $@ + +site/node_modules: node_modules package.json package-lock.json + rm -rf tmpproj + mkdir tmpproj + mkdir -p site + cp package.json package-lock.json tmpproj + cd tmpproj && npm install --production + cp -r tmpproj/node_modules site + +dyna3.zip: $(BLDTARGS) + zip -r $@ site + +__tests__/%.js: coffeetest/%.coffee + coffee -o $@ -c -m $< + +$(BLDTARGS) $(TESTJS): Makefile + +doc: site/doc/dyna3.md + +dist: dyna3.zip + +pretest: $(BLDTARGS) $(TESTJS) + +test: $(BLDTARGS) $(TESTJS) + npm test + +clean: + rm -rf site docbuild tmpproj __tests__ coverage dyna3.zip diff --git a/doc/gendoc.litcoffee b/doc/gendoc.litcoffee index a79880c..d2f7108 100644 --- a/doc/gendoc.litcoffee +++ b/doc/gendoc.litcoffee @@ -2,6 +2,16 @@ ```javascript fs = require 'fs' + docsrcs = [ + 'README.md', 'src/dyna3.litcoffee', + 'src/helpers/pkglock_to_externals.litcoffee', 'docbuild/extlist.md', + 'doc/tech.md', 'doc/gendoc.litcoffee' + ] + if process.argv.length > 2 + process.stdout.write docsrcs.join ' ' + process.stdout.write "\n" + process.exit 0 + striplit = (text) -> String(text).replace(/^```javascript[^]*?```\n/mg,'') incfile = (fn, filt = null) -> if (filt is null) @@ -9,9 +19,5 @@ else filt = (x)->x process.stdout.write filt fs.readFileSync fn process.stdout.write "\n" - incfile f for f in [ - 'README.md', 'src/dyna3.litcoffee', - 'src/helpers/pkglock_to_externals.litcoffee', 'docbuild/extlist.md', - 'doc/tech.md', 'doc/gendoc.litcoffee' ] - + incfile f for f in docsrcs ``` diff --git a/doc/tech.md b/doc/tech.md index f29515a..0277771 100644 --- a/doc/tech.md +++ b/doc/tech.md @@ -2,8 +2,9 @@ The intial modest outline for bootstrapping dyna3 is as follows: -- dyna3 will be an npm project, but as it runs entirely client-side, there's no initial concern for being able to run under Node.js. However, npm will be useful as a dependency manager and build tool. In addition, helper scripts for the build can be run with node (via coffee). -- The package will build into a top-level site/ directory, which will contain all and only the files that must be on a server to deliver dyna3 to a client browser. Everything in site/ will generated from the package files; nothing in site/ will be committed to the repository. Right now the planned contents a of site/ are just a handful of top-level files, the modules/ directory for in-package javascript, the /doc directory for generated documentation, and a copy of the node_modules/ directory as a backup for the external dependencies. +- dyna3 will be an npm project, but as it runs entirely client-side, there's no initial concern for being able to run under Node.js. However, npm will be useful as a dependency manager. In addition, helper scripts for the build can be run with node (via coffee). +- For a build tool, we are just going to go with the venerable "make." I tried using npm scripts, and they can handle the necessary operations, but they have no notion of a "target being up to date" like make does, so I was constantly re-running unnecessary/redundant pieces of the process, which was frustrating. +- The package will build into a top-level site/ directory, which will contain all and only the files that must be on a server to deliver dyna3 to a client browser. Everything in site/ will generated from the package files; nothing in site/ will be committed to the repository. Right now the planned contents a of site/ are just a handful of top-level files, the modules/ directory for in-package javascript, the /doc directory for generated documentation, and a copy of the production node_modules/ directory as a backup for the external dependencies. - Literate coffeescript modules (in the src/modules directory except for the top-level application) will compile into individual js modules in the site/modules directory (again, except for the top-level application) - Why coffeescript? The motivation for the javascript family of languages is wide deployability and availability of numerous libraries; the motivation for coffeescript is that it (still) reduces the amount of punctuation and extraneous characters from Javascript, resulting in better readability. And Literate coffeescript so that the manual and code are co-located. - All modules will use ES Modules syntax/format for imports. diff --git a/package.json b/package.json index 45879be..78853e3 100644 --- a/package.json +++ b/package.json @@ -5,18 +5,7 @@ "private": "true", "main": "dyna3.js", "scripts": { - "clean": "rm -rf site docbuild tmpproj __tests__ dyna3.zip coverage", - "doc:extra": "mkdir -p docbuild && coffee src/helpers/pkglock_to_externals.litcoffee --doc > docbuild/extlist.md", - "doc:collate": "mkdir -p site/doc && coffee doc/gendoc.litcoffee > site/doc/dyna3.md", - "doc": "npm run doc:extra && npm run doc:collate", - "prebuild": "npm run clean", - "build:coffee": "coffee -o site -c -m src/*.litcoffee", - "build:ext": "coffee src/helpers/pkglock_to_externals.litcoffee > site/externals.js", - "build:doc": "npm run doc && pandoc -s --toc site/doc/dyna3.md > site/doc/dyna3.html", - "build:copy": "mkdir -p site && rm -rf tmpproj && cp src/*.html site && mkdir tmpproj && rsync -av . tmpproj --exclude tmpproj --exclude node_modules && cd tmpproj && npm install --production && cp -r node_modules ../site && cd ..", - "build": "npm run build:coffee && npm run build:ext && npm run build:doc && npm run build:copy", - "dist": "npm run build && zip -r dyna3.zip site", - "pretest": "npm run build && coffee -o __tests__ -c -m coffeetest/*.coffee", + "pretest": "make pretest", "test": "ava" }, "repository": {