Commit 910fa9bb authored by Tamlyn Rhodes's avatar Tamlyn Rhodes

Remove unused scripts

parent adeecfe8
Pipeline #2692 passed with stage
in 3 minutes and 57 seconds
module.exports = {
username: {
description: 'Admin username'
},
email: {
description: 'Admin email address'
},
password: {
description: 'Admin password',
hidden: true,
replace: '*'
},
collection: {
description: 'Initial collection title (optional)'
}
}
const path = require('path')
const fs = require('fs-extra')
const crypto = require('crypto')
const logger = require('@pubsweet/logger')
const envDir = process.cwd() // TODO: require this from a module?
module.exports = async () => {
const env = process.env.NODE_ENV
logger.info('Generating env file for', env)
// generate a unique secret
const conf = {
PUBSWEET_SECRET: crypto.randomBytes(64).toString('hex')
}
// generate the output string
const output = Object.keys(conf).map(key => {
return [key, conf[key]].join('=')
}).join('\n')
// env file per environment, inside the root dir
const envPath = path.join(envDir, '.env.' + env)
// write the data to the env file
await fs.outputFile(envPath, output)
logger.info('Generated env files')
}
process.env.PUBSWEET_BACKEND_SILENT = true
const colors = require('colors/safe')
const logger = require('@pubsweet/logger')
const runPrompt = async ({ override, properties }) => {
const prompt = require('prompt')
prompt.override = override
prompt.message = colors.cyan('question:')
prompt.delimiter = colors.green('><')
prompt.start()
return new Promise((resolve, reject) => {
prompt.get({properties}, (err, result) => {
if (err) reject(err)
resolve(result)
})
})
}
const logResult = results => {
logger.info('Received the following answers')
Object.keys(results).forEach(key => {
const answer = key === 'password' ? '<redacted>' : results[key]
logger.info(` ${key}: ${answer}`)
})
}
const createAdminUser = async data => {
logger.info('Creating the admin user')
const User = require('pubsweet-server/src/models/User')
// create and save an admin user
const user = new User({
username: data.username,
email: data.email,
password: data.password,
admin: true
})
await user.save()
logger.info('Saved admin user: ', user.username)
user.password = data.password
return user
}
const createCollection = async (title, user) => {
logger.info('Creating the initial collection')
const Collection = require('pubsweet-server/src/models/Collection')
const created = Date.now()
// create and save an initial collection
const collection = new Collection({ title, created })
collection.setOwners([user.id])
await collection.save()
logger.info('Created initial collection: ', collection.title)
return collection
}
module.exports = async options => {
try {
logger.info('Setting up the database')
// ask the user for input
const result = await runPrompt(options)
// log the result
logResult(result)
// create initial user
const user = await createAdminUser(result)
// create initial collection, if specified
const collection = result.collection ? await createCollection(result.collection, user) : null
logger.info('Finished setting up the database')
return {user, collection}
} catch (e) {
logger.error('Database setup failed')
throw e
}
}
const logger = require('@pubsweet/logger')
const colors = require('colors/safe')
const program = require('commander')
const properties = require('../src/scripts/db-properties')
module.exports = async args => {
program
.arguments('[path]')
.description('Setup a database for this PubSweet app')
.option('--clobber', 'Overwrite any existing database')
Object.keys(properties).forEach(key => {
program.option(`--${key} [string]`, properties[key].description)
})
program.parse(args || process.argv)
logger.info('Generating PubSweet database')
await require('../src/scripts/newdb')({
appPath: appPath,
properties: require('../src/scripts/db-properties'),
override: program
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment