Commit 8e0d69cb authored by Jure's avatar Jure

Add seed script that runs on every 'yarn start'

parent 60186f2b
......@@ -14,9 +14,6 @@ const Navigation = ({ logoutUser, currentUser }) => (
<Authorize object={{ path: '/users' }} operation="GET">
<Action to="/manage/users">Users</Action>
</Authorize>,
<Authorize object={{ path: '/teams' }} operation="GET">
<Action to="/manage/teams">Teams</Action>
</Authorize>,
]}
onLogoutClick={logoutUser}
user={currentUser}
......
......@@ -3,7 +3,7 @@ services:
web:
image: pubsweet/pubsweet:base
command: sh -c "yarn && yarn server"
command: sh -c "yarn && yarn seed && yarn server"
ports:
- ${PORT:-3000}:3000
volumes:
......
......@@ -87,7 +87,7 @@
"server": "pubsweet server",
"start:services": "docker-compose up db",
"setupdb": "pubsweet setupdb",
"create:collection": "node scripts/add-collection.js",
"seed": "node scripts/seed.js",
"precommit": "lint-staged",
"test":
"NODE_ENV=test NODE_PRESERVE_SYMLINKS=1 testcafe chrome 'test/**/*.test.js'"
......
#!/usr/bin/env node
const logger = require('@pubsweet/logger')
const { addCollection } = require('@pubsweet/db-manager')
const [, , title] = process.argv
if (!title) {
logger.error(
`Please specify a title, e.g. npm run create:collection -- "Some title"`,
)
process.exit()
}
addCollection({ title }).catch(err => logger.error(err))
#!/usr/bin/env node
const logger = require('@pubsweet/logger')
const { Collection, Fragment, User } = require('pubsweet-server/src/models')
const { setupDb } = require('@pubsweet/db-manager')
const seed = async () => {
await setupDb({
username: 'admin',
password: 'password',
email: 'admin@example.com',
admin: true,
clobber: true,
})
const user = await new User({
username: 'john',
email: 'john@example.com',
password: 'johnjohn',
}).save()
const collection = new Collection({
title: 'My Blog',
owners: [user.id],
})
await collection.save()
const fragment1 = await new Fragment({
title: 'My first post',
owners: [user.id],
}).save()
const fragment2 = await new Fragment({
title: 'My second post',
owners: [user.id],
}).save()
collection.addFragment(fragment1)
collection.addFragment(fragment2)
await collection.save()
logger.info('Seeding complete.')
}
seed()
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