Skip to content

Commit 0914cb4

Browse files
committed
Rebased from latest
1 parent ddef9e6 commit 0914cb4

File tree

16 files changed

+155
-89
lines changed

16 files changed

+155
-89
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Simple file so that if you require this directory
33
// in node it instead requires ./lib/server.coffee
44
// with coffee-script already loaded.
5-
require('coffeescript')
6-
require('coffeescript/register')
5+
import('coffeescript')
6+
import('coffeescript/register.js')
77

8-
module.exports = require('./lib/server')
8+
import * as server from './lib/server.cjs'
9+
export default server

lib/defaultargs.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
// **defaultargs.coffee** when called on the argv object this
1010
// module will create reasonable defaults for options not supplied,
1111
// based on what information is provided.
12-
const path = require('node:path')
12+
import path from 'node:path'
13+
import { randomBytes } from 'node:crypto'
14+
import { fileURLToPath } from 'node:url'
15+
import { dirname } from 'node:path'
16+
17+
const __filename = fileURLToPath(import.meta.url)
18+
const __dirname = dirname(__filename)
1319

1420
const getUserHome = () => {
1521
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
1622
}
1723

18-
module.exports = argv => {
24+
const exports = argv => {
1925
argv = argv || {}
2026
argv.root ||= __dirname
2127
// the directory that contains all the packages that makeup the wiki
@@ -32,7 +38,7 @@ module.exports = argv => {
3238
argv.url ||= `http://localhost${argv.port === 80 ? '' : ':' + argv.port}`
3339
argv.id ||= path.join(argv.status, 'owner.json')
3440
argv.uploadLimit ||= '5mb'
35-
argv.cookieSecret ||= require('crypto').randomBytes(64).toString('hex')
41+
argv.cookieSecret ||= randomBytes(64).toString('hex')
3642
argv.secure_cookie ||= false
3743
argv.session_duration ||= 7
3844
argv.neighbors ||= ''
@@ -43,18 +49,18 @@ module.exports = argv => {
4349
argv.database = JSON.parse(argv.database)
4450
}
4551
argv.database ||= {}
46-
argv.database.type ||= './page'
52+
argv.database.type ||= './page.js'
4753
if (argv.database.type.charAt(0) === '.') {
48-
if (argv.database.type != './page') {
54+
if (argv.database.type != './page.js') {
4955
console.log('\n\nWARNING: This storage option is depeciated.')
5056
console.log(' See ReadMe for details of the changes required.\n\n')
5157
}
5258
} else {
5359
argv.database.type = 'wiki-storage-' + argv.database.type
5460
}
5561

56-
argv.security_type ||= './security'
57-
if (argv.security_type === './security') {
62+
argv.security_type ||= './security.js'
63+
if (argv.security_type === './security.js') {
5864
console.log('\n\nINFORMATION: Using default security module.')
5965
} else {
6066
argv.security_type = 'wiki-security-' + argv.security_type
@@ -81,3 +87,6 @@ module.exports = argv => {
8187
}
8288
return argv
8389
}
90+
91+
export default exports
92+
export { exports }

lib/forward.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const init = (app, emitter) => {
1+
export const init = (app, emitter) => {
22
let sockets = []
33
app.io.on('connection', socket => {
44
let listeners = []
@@ -35,4 +35,3 @@ const init = (app, emitter) => {
3535
})
3636
})
3737
}
38-
module.exports = { init }

lib/page.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@
1010
// Everything is stored using json flat files.
1111

1212
// #### Requires ####
13-
const fs = require('fs')
14-
const path = require('path')
15-
const events = require('events')
16-
const glob = require('glob')
17-
18-
const async = require('async')
19-
20-
const random_id = require('./random_id')
21-
const synopsis = require('wiki-client/lib/synopsis')
13+
// const fs = require('fs')
14+
// const path = require('path')
15+
// const events = require('events')
16+
// const glob = require('glob')
17+
//
18+
// const async = require('async')
19+
//
20+
// // const random_id = require('./random_id.cjs')
21+
// const synopsis = require('wiki-client/lib/synopsis')
22+
23+
import fs from 'node:fs'
24+
import path from 'node:path'
25+
import events from 'node:events'
26+
import glob from 'glob'
27+
28+
import async from 'async'
29+
30+
// import random_id from './random_id.cjs'; // Uncomment if needed
31+
import synopsis from 'wiki-client/lib/synopsis.js' // Add correct extension if necessary
2232

2333
const asSlug = name =>
2434
name
@@ -28,7 +38,7 @@ const asSlug = name =>
2838

2939
// Export a function that generates a page handler
3040
// when called with options object.
31-
module.exports = exports = argv => {
41+
const exports = argv => {
3242
const wikiName = new URL(argv.url).hostname
3343

3444
fs.mkdir(argv.db, { recursive: true }, e => {
@@ -446,3 +456,6 @@ module.exports = exports = argv => {
446456

447457
return itself
448458
}
459+
460+
export default exports
461+
export { exports }

lib/plugins.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
// support server-side plugins
1010

11-
const fs = require('node:fs')
12-
const glob = require('glob')
13-
const { pathToFileURL } = require('node:url')
14-
// forward = require './forward'
11+
import fs from 'node:fs'
12+
import glob from 'glob'
13+
import { pathToFileURL } from 'node:url'
14+
// import forward from './forward.cjs'; // Uncomment if needed and adjust import style if it's not a default export
1515

16-
module.exports = exports = argv => {
16+
const exports = argv => {
1717
// NOTE: plugins are now in their own package directories alongside this one...
1818
// Plugins are in directories of the form wiki-package-*
1919
// those with a server component will have a server directory
@@ -52,3 +52,6 @@ module.exports = exports = argv => {
5252

5353
return { startServers }
5454
}
55+
56+
export default exports
57+
export { exports }

lib/random_id.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
const random_id = (chars = 16) => [...Array(chars)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
1414

15-
module.exports = random_id.random_id = random_id
15+
export default random_id
16+
export { random_id }

lib/search.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
// **search.js**
1010

11-
const fs = require('node:fs')
12-
const path = require('node:path')
13-
const events = require('node:events')
14-
const url = require('node:url')
15-
const writeFileAtomic = require('write-file-atomic')
11+
import fs from 'node:fs'
12+
import path from 'node:path'
13+
import events from 'node:events'
14+
import url from 'node:url'
15+
import writeFileAtomic from 'write-file-atomic'
1616

17-
const miniSearch = require('minisearch')
17+
import MiniSearch from 'minisearch'
1818

19-
module.exports = exports = argv => {
19+
const exports = argv => {
2020
const wikiName = new URL(argv.url).hostname
2121
let siteIndex = []
2222
const queue = []
@@ -388,3 +388,6 @@ module.exports = exports = argv => {
388388

389389
return itself
390390
}
391+
392+
export default exports
393+
export { exports }

lib/security.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
// allow the server to run read-only.
1414

1515
// #### Requires ####
16-
const fs = require('node:fs')
16+
import fs from 'node:fs'
1717

1818
// Export a function that generates security handler
1919
// when called with options object.
20-
module.exports = exports = (log, loga, argv) => {
20+
const exports = (log, loga, argv) => {
2121
const security = {}
2222

2323
// #### Private utility methods. ####
@@ -92,3 +92,6 @@ module.exports = exports = (log, loga, argv) => {
9292

9393
return security
9494
}
95+
96+
export default exports
97+
export { exports }

lib/server.js renamed to lib/server.cjs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const bodyParser = require('body-parser')
5151
const errorHandler = require('errorhandler')
5252

5353
// Local files
54-
const random = require('./random_id')
55-
const defargs = require('./defaultargs')
54+
// const random = require('./random_id.cjs')
55+
const defargs = require('./defaultargs.js')
5656
const resolveClient = require('wiki-client/lib/resolve')
57-
const pluginsFactory = require('./plugins')
58-
const sitemapFactory = require('./sitemap')
59-
const searchFactory = require('./search')
57+
const pluginsFactory = require('./plugins.js')
58+
const sitemapFactory = require('./sitemap.js')
59+
const searchFactory = require('./search.js')
6060

6161
const render = page => {
6262
return (
@@ -103,7 +103,7 @@ module.exports = exports = argv => {
103103
// defaultargs.coffee exports a function that takes the argv object
104104
// that is passed in and then does its
105105
// best to supply sane defaults for any arguments that are missing.
106-
argv = defargs(argv)
106+
argv = defargs.default(argv)
107107

108108
app.startOpts = argv
109109

@@ -130,16 +130,16 @@ module.exports = exports = argv => {
130130
}
131131
let pagehandler, sitemaphandler, searchhandler, securityhandler
132132
// Require the database adapter and initialize it with options.
133-
app.pagehandler = pagehandler = require(argv.database.type)(argv)
133+
app.pagehandler = pagehandler = require(argv.database.type).default(argv)
134134

135135
// Require the sitemap adapter and initialize it with options.
136-
app.sitemaphandler = sitemaphandler = sitemapFactory(argv)
136+
app.sitemaphandler = sitemaphandler = sitemapFactory.default(argv)
137137

138138
// Require the site indexer and initialize it with options
139-
app.searchhandler = searchhandler = searchFactory(argv)
139+
app.searchhandler = searchhandler = searchFactory.default(argv)
140140

141141
// Require the security adapter and initialize it with options.
142-
app.securityhandler = securityhandler = require(argv.security_type)(log, loga, argv)
142+
app.securityhandler = securityhandler = require(argv.security_type).default(log, loga, argv)
143143

144144
// If the site is owned, owner will contain the name of the owner
145145
let owner = ''
@@ -928,7 +928,7 @@ module.exports = exports = argv => {
928928
app.on('running-serv', server => {
929929
// ### Plugins ###
930930
// Should replace most WebSocketServers below.
931-
const plugins = pluginsFactory(argv)
931+
const plugins = pluginsFactory.default(argv)
932932
plugins.startServers({ argv, app })
933933
// ### Sitemap ###
934934
// create sitemap at start-up

lib/sitemap.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77
*/
88

99
// **sitemap.coffee**
10+
import fs from 'node:fs'
11+
import path from 'node:path'
12+
import events from 'node:events'
13+
import writeFileAtomic from 'write-file-atomic'
14+
import xml2js from 'xml2js'
1015

11-
const fs = require('fs')
12-
const path = require('path')
13-
const events = require('events')
14-
const writeFileAtomic = require('write-file-atomic')
15-
const xml2js = require('xml2js')
16-
17-
const synopsis = require('wiki-client/lib/synopsis')
16+
import synopsis from 'wiki-client/lib/synopsis.js' // Add .js if needed
1817

1918
const asSlug = name =>
2019
name
2120
.replace(/\s/g, '-')
2221
.replace(/[^A-Za-z0-9-]/g, '')
2322
.toLowerCase()
2423

25-
module.exports = exports = argv => {
24+
const exports = argv => {
2625
const wikiName = new URL(argv.url).hostname
2726

2827
let sitemap = []
@@ -286,3 +285,6 @@ module.exports = exports = argv => {
286285

287286
return itself
288287
}
288+
289+
export default exports
290+
export { exports }

0 commit comments

Comments
 (0)