Skip to content
Merged
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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Simple file so that if you require this directory
// in node it instead requires ./lib/server.coffee
// with coffee-script already loaded.
require('coffeescript')
require('coffeescript/register')
import('coffeescript')
import('coffeescript/register.js')

module.exports = require('./lib/server')
const { default: server } = await import('./lib/server.js')
export default server
20 changes: 13 additions & 7 deletions lib/defaultargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
// **defaultargs.coffee** when called on the argv object this
// module will create reasonable defaults for options not supplied,
// based on what information is provided.
const path = require('node:path')
import path from 'node:path'
import { randomBytes } from 'node:crypto'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
Comment on lines +12 to +15
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can line 12 and line 15 be combined, since both are coming from node:path?
Maybe this would work?

import {default:path, dirname} from 'node:path';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. I still consider this an exploratory branch rather than something I'd offer to merge right now. Many things like this to tidy up. Thank you for looking it over and commenting.


const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

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

module.exports = argv => {
export default argv => {
argv = argv || {}
argv.root ||= __dirname
// the directory that contains all the packages that makeup the wiki
Expand All @@ -32,7 +38,7 @@ module.exports = argv => {
argv.url ||= `http://localhost${argv.port === 80 ? '' : ':' + argv.port}`
argv.id ||= path.join(argv.status, 'owner.json')
argv.uploadLimit ||= '5mb'
argv.cookieSecret ||= require('crypto').randomBytes(64).toString('hex')
argv.cookieSecret ||= randomBytes(64).toString('hex')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving the inline require() to an import() above.

argv.secure_cookie ||= false
argv.session_duration ||= 7
argv.neighbors ||= ''
Expand All @@ -43,18 +49,18 @@ module.exports = argv => {
argv.database = JSON.parse(argv.database)
}
argv.database ||= {}
argv.database.type ||= './page'
argv.database.type ||= './page.js'
if (argv.database.type.charAt(0) === '.') {
if (argv.database.type != './page') {
if (argv.database.type != './page.js') {
console.log('\n\nWARNING: This storage option is depeciated.')
console.log(' See ReadMe for details of the changes required.\n\n')
}
} else {
argv.database.type = 'wiki-storage-' + argv.database.type
}

argv.security_type ||= './security'
if (argv.security_type === './security') {
argv.security_type ||= './security.js'
if (argv.security_type === './security.js') {
console.log('\n\nINFORMATION: Using default security module.')
} else {
argv.security_type = 'wiki-security-' + argv.security_type
Expand Down
3 changes: 1 addition & 2 deletions lib/forward.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const init = (app, emitter) => {
export const init = (app, emitter) => {
let sockets = []
app.io.on('connection', socket => {
let listeners = []
Expand Down Expand Up @@ -35,4 +35,3 @@ const init = (app, emitter) => {
})
})
}
module.exports = { init }
30 changes: 20 additions & 10 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@
// Everything is stored using json flat files.

// #### Requires ####
const fs = require('fs')
const path = require('path')
const events = require('events')
const glob = require('glob')

const async = require('async')

const random_id = require('./random_id')
const synopsis = require('wiki-client/lib/synopsis')
// const fs = require('fs')
// const path = require('path')
// const events = require('events')
// const glob = require('glob')
//
// const async = require('async')
//
// // const random_id = require('./random_id.cjs')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is random_id not in use?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several unused imports throughout the files. As far as I can tell, random_id is not used in pages.

// const synopsis = require('wiki-client/lib/synopsis')

import fs from 'node:fs'
import path from 'node:path'
import events from 'node:events'
import glob from 'glob'

import async from 'async'

// import random_id from './random_id.cjs'; // Uncomment if needed
import synopsis from 'wiki-client/lib/synopsis.js' // Add correct extension if necessary

const asSlug = name =>
name
Expand All @@ -28,7 +38,7 @@ const asSlug = name =>

// Export a function that generates a page handler
// when called with options object.
module.exports = exports = argv => {
export default argv => {
const wikiName = new URL(argv.url).hostname

fs.mkdir(argv.db, { recursive: true }, e => {
Expand Down
10 changes: 5 additions & 5 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

// support server-side plugins

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

module.exports = exports = argv => {
export default argv => {
// NOTE: plugins are now in their own package directories alongside this one...
// Plugins are in directories of the form wiki-package-*
// those with a server component will have a server directory
Expand Down
3 changes: 1 addition & 2 deletions lib/random_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
// Simple random hex generator, takes an optional number of
// chars that defaults to 16 and returns a random id.

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

module.exports = random_id.random_id = random_id
14 changes: 7 additions & 7 deletions lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

// **search.js**

const fs = require('node:fs')
const path = require('node:path')
const events = require('node:events')
const url = require('node:url')
const writeFileAtomic = require('write-file-atomic')
import fs from 'node:fs'
import path from 'node:path'
import events from 'node:events'
import url from 'node:url'
import writeFileAtomic from 'write-file-atomic'

const miniSearch = require('minisearch')
import MiniSearch from 'minisearch'

module.exports = exports = argv => {
export default argv => {
const wikiName = new URL(argv.url).hostname
let siteIndex = []
const queue = []
Expand Down
4 changes: 2 additions & 2 deletions lib/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// allow the server to run read-only.

// #### Requires ####
const fs = require('node:fs')
import fs from 'node:fs'

// Export a function that generates security handler
// when called with options object.
module.exports = exports = (log, loga, argv) => {
export default (log, loga, argv) => {
const security = {}

// #### Private utility methods. ####
Expand Down
Loading