--- /dev/null
+/disk_build-*.tgz
+/node_modules
+/package-lock.json
+/yarn.lock
+/yarn-error.log
--- /dev/null
+/disk_build-*.tgz
+/node_modules
+/package-lock.json
+/yarn.lock
+/yarn-error.log
--- /dev/null
+/disk_build-*.tgz
+/node_modules
+/package-lock.json
+/yarn.lock
+/yarn-error.log
--- /dev/null
+Copyright (C) 2018 Nick Downing <nick@ndcode.org>
+SPDX-License-Identifier: MIT
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
--- /dev/null
+# Disk Build helper
+
+An NDCODE project.
+
+## Overview
+
+The `disk_build` package exports a function `disk_build(pathname, build_func)`,
+which given a pathname to an existing source file, will generate a a pathname
+for a corresponding on-disk temporary file, check whether this exists and is
+newer than the original, and rebuild it via a caller-provided function if not.
+
+## Calling API
+
+The interface for the `disk_build`-provided helper function `disk_build()` is:
+
+`await disk_build(pathname, build_func)` — generates the corresponding
+`built_pathname`, checks if the temporary file `built_pathname` exists and is
+newer than `pathname`, and if not, calls the user-provided callback function
+`build_func(built_pathname)` to rebuild the temporary file before returning.
+
+The interface for the user-provided callback function `build_func()` is:
+
+`await build_func(text, built_pathname)` — user must create the file
+`built_pathname` and then return, or alternatively an exception can be thrown.
+
+## About diagnostics
+
+A diagnostic will be printed if the temporary file is up-to-date and does not
+need to be rebuilt. No diagnostic is printed if the `build_func()` callback is
+invoked, since it is expected that the user can provide an appropriate one
+(allowing the diagnostic to be suppressed if the source file isn't readable).
+
+## To be implemented
+
+It is intended that dependencies will be tracked in the future, so that an
+on-disk temporary file can be built from several on-disk sources. In that case
+we will write a second temporary file `*.deps` containing a list of the build
+dependencies, so that up-to-dateness can be checked from only the disk status.
+
+## GIT repository
+
+The development version can be cloned, downloaded, or browsed with `gitweb` at:
+https://git.ndcode.org/public/disk_build.git
+
+## License
+
+All of our NPM packages are MIT licensed, please see LICENSE in the repository.
+
+## Contributions
+
+We would greatly welcome your feedback and contributions. The `disk_build` is
+under active development (and is part of a larger project that is also under
+development) and thus the API is considered tentative and subject to change. If
+this is undesirable, you could possibly pin the version in your `package.json`.
+
+Contact: Nick Downing <nick@ndcode.org>
--- /dev/null
+/*
+ * Copyright (C) 2018 Nick Downing <nick@ndcode.org>
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+let fs = require('fs')
+let path = require('path')
+let util = require('util')
+
+let fs_stat = util.promisify(fs.stat)
+
+let disk_build = async (pathname, build_func) => {
+ let stats = await fs_stat(pathname)
+
+ let built_pathname = path.posix.resolve(
+ path.posix.dirname(pathname),
+ `.${path.posix.basename(pathname)}`
+ )
+
+ let built_stats
+ try {
+ built_stats = await fs_stat(built_pathname)
+ }
+ catch (err) {
+ if (!(err instanceof Error) || err.code !== 'ENOENT')
+ throw err
+ //built_stats = undefined
+ }
+ if (built_stats === undefined || stats.mtimeMs > built_stats.mtimeMs)
+ await build_func(built_pathname)
+ else
+ console.log('reloading', built_pathname)
+
+ return built_pathname
+}
+
+module.exports = disk_build
--- /dev/null
+{
+ "name": "@ndcode/disk_build",
+ "version": "0.1.0",
+ "description": "Helper function for checking and rebuilding disk objects.",
+ "keywords": [
+ "disk",
+ "build",
+ "helper",
+ "modified",
+ "sources",
+ "compile",
+ "compiler"
+ ],
+ "homepage": "https://www.ndcode.org",
+ "repository": {
+ "type": "git",
+ "url": "https://git.ndcode.org/public/disk_build.git"
+ },
+ "bugs": {
+ "email": "nick@ndcode.org"
+ },
+ "main": "disk_build.js",
+ "directories": {},
+ "dependencies": {},
+ "devDependencies": {},
+ "scripts": {},
+ "author": "Nick Downing <nick@ndcode.org>",
+ "license": "MIT"
+}