* IN THE SOFTWARE.
*/
-let assert = require('assert')
-let fs = require('fs')
-let http = require('http')
-let https = require('https')
-let util = require('util')
+import assert from 'assert'
+import fs from 'fs'
+import http from 'http'
+import https from 'https'
+import util from 'util'
let fs_readFile = util.promisify(fs.readFile)
}
}
-module.exports = Listener
+export default Listener
* IN THE SOFTWARE.
*/
-let assert = require('assert')
+import assert from 'assert'
let Resources = function(diag) {
if (!this instanceof Resources)
}
Resources.prototype.ref = async function(key, factory_func, destroy_func) {
- result = this.map.get(key)
+ let result = this.map.get(key)
if (result === undefined) {
result = {
refs: 0,
}
}
-module.exports = Resources
+export default Resources
* IN THE SOFTWARE.
*/
-let JSTCache = require('@ndcode/jst_cache')
-let Listener = require('./Listener')
-let Resources = require('./Resources')
-let Site = require('./Site')
-let assert = require('assert')
-let fs = require('fs')
-let jst_server = require('./index')
-let url = require('url')
-let util = require('util')
+import JSTCache from '@ndcode/jst_cache'
+import Listener from './Listener.mjs'
+import Resources from './Resources.mjs'
+import Site from './Site.mjs'
+import assert from 'assert'
+import fs from 'fs'
+import jst_server from './index.mjs'
+import url from 'url'
+import util from 'util'
let fs_readFile = util.promisify(fs.readFile)
}
}
-module.exports = Server
+export default Server
* IN THE SOFTWARE.
*/
-let JSONCache = require('@ndcode/json_cache')
-let JSONCacheRW = require('@ndcode/json_cache_rw')
-let JSTCache = require('@ndcode/jst_cache')
-let LessCSSCache = require('@ndcode/less_css_cache')
-let MenuCache = require('@ndcode/menu_cache')
-let MinCSSCache = require('@ndcode/min_css_cache')
-let MinJSCache = require('@ndcode/min_js_cache')
-let MinHTMLCache = require('@ndcode/min_html_cache')
-let MinSVGCache = require('@ndcode/min_svg_cache')
-let Resources = require('./Resources')
-let SassCSSCache = require('@ndcode/sass_css_cache')
-let TextCache = require('@ndcode/text_cache')
-let ZipCache = require('@ndcode/zip_cache')
-let assert = require('assert')
-let fs = require('fs')
-let jst_server = require('./index')
-let util = require('util')
+import JSONCache from '@ndcode/json_cache'
+import JSONCacheRW from '@ndcode/json_cache_rw'
+import JSTCache from '@ndcode/jst_cache'
+import LessCSSCache from '@ndcode/less_css_cache'
+import MenuCache from '@ndcode/menu_cache'
+import MinCSSCache from '@ndcode/min_css_cache'
+import MinJSCache from '@ndcode/min_js_cache'
+import MinHTMLCache from '@ndcode/min_html_cache'
+import MinSVGCache from '@ndcode/min_svg_cache'
+import Resources from './Resources.mjs'
+import SassCSSCache from '@ndcode/sass_css_cache'
+import TextCache from '@ndcode/text_cache'
+import ZipCache from '@ndcode/zip_cache'
+import assert from 'assert'
+import fs from 'fs'
+import jst_server from './index.mjs'
+import util from 'util'
let fs_mkdir = util.promisify(fs.mkdir)
let fs_stat = util.promisify(fs.stat)
return /*await*/ this.serve_path(env, this.root, components)
}
-module.exports = Site
+export default Site
+++ /dev/null
-#!/usr/bin/env node
-
-/*
- * 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.
- */
-
-// must load index first, to avoid circular dependency issue
-let jst_server = require('./index')
-
-let JSTCache = require('@ndcode/jst_cache')
-let Resources = require('./Resources')
-let Server = require('./Server')
-
-;(
- async () => {
- let resources = new Resources()
- let jst_cache = await resources.ref(
- 'jst_cache:.',
- async () => new JSTCache('.', {_jst_server: jst_server}, true)
- )
- let server = undefined
-
- // refresh the config immediately, then every 1 second,
- // use setTimeout() instead of setInterval() to avoid bunches
- // of calls after the computer has been suspended for a while
- let refresh_config = async () => {
- try {
- let config = await jst_cache.get('_config/server.jst', true)
- if (config !== undefined) {
- let prev_server = server
- let new_server = await config(resources, prev_server)
- await new_server.start() // exception here cancels server change
- server = new_server
- if (prev_server !== undefined)
- await prev_server.stop() // exception here doesn't cancel change
- }
- await server.kick()
- }
- catch (err) {
- console.error(err.stack || err.message)
- }
- setTimeout(refresh_config, 1000)
- // returned Promise will be ignored
- }
- refresh_config()
- }
-)()
--- /dev/null
+#!/usr/bin/env node
+
+/*
+ * 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.
+ */
+
+// must load index first, to avoid circular dependency issue
+import jst_server from './index.mjs'
+
+import JSTCache from '@ndcode/jst_cache'
+import Resources from './Resources.mjs'
+import Server from './Server.mjs'
+
+let resources = new Resources()
+let jst_cache = await resources.ref(
+ 'jst_cache:.',
+ async () => new JSTCache('.', {_jst_server: jst_server}, true)
+)
+let server = undefined
+
+// refresh the config every 1 second
+while (true) {
+ try {
+ let config = await jst_cache.get('_config/server.jst', true)
+ if (config !== undefined) {
+ let prev_server = server
+ let new_server = await config(resources, prev_server)
+ await new_server.start() // exception here cancels server change
+ server = new_server
+ if (prev_server !== undefined)
+ await prev_server.stop() // exception here doesn't cancel change
+ }
+ await server.kick()
+ }
+ catch (err) {
+ console.error(err.stack || err.message)
+ }
+ await new Promise(resolve => setTimeout(resolve, 1000))
+}
+++ /dev/null
-exports.Resources = require('./Resources')
-exports.Server = require('./Server')
-exports.Site = require('./Site')
--- /dev/null
+import Resources from './Resources.mjs'
+import Server from './Server.mjs'
+import Site from './Site.mjs'
+
+export default {Resources, Server, Site}
"email": "nick@ndcode.org"
},
"bin": {
- "jst_server": "cli.js"
+ "jst_server": "cli.mjs"
},
- "main": "index.js",
+ "main": "index.mjs",
"engines": {
"node": ">=0.4.0"
},