Skip to content

Commit

Permalink
import script, develop command
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyspiro committed May 25, 2018
1 parent b02be3e commit 096b352
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -8,9 +8,11 @@
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"develop": "npm run dev",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
"precommit": "npm run lint",
"import": "node ./scripts/import.js"
},
"dependencies": {
"cosmicjs": "^3.2.7",
Expand Down
18 changes: 18 additions & 0 deletions scripts/import.js
@@ -0,0 +1,18 @@
const Cosmic = require('cosmicjs')
const api = Cosmic()
const COSMIC_BUCKET = process.env.COSMIC_BUCKET || 'node-starter'
const bucket = api.bucket({
slug: COSMIC_BUCKET
})
const default_objects = require('./objects')
const default_object_type = require('./object-type')
const importObjects = async () => {
const res = await bucket.getObjects()
if(res.status === 'empty') {
bucket.addObjectType(default_object_type)
default_objects.forEach(object => {
bucket.addObject(object)
})
}
}
importObjects()
5 changes: 5 additions & 0 deletions scripts/object-type.json
@@ -0,0 +1,5 @@
{
"title": "Pages",
"slug": "pages",
"singular": "page"
}
20 changes: 20 additions & 0 deletions scripts/objects.json
@@ -0,0 +1,20 @@
[
{
"title": "Home",
"slug": "home",
"content": "This is the home page content.",
"type_slug": "pages"
},
{
"title": "About",
"slug": "about",
"content": "This is the about page content.",
"type_slug": "pages"
},
{
"title": "Contact",
"slug": "contact",
"content": "This is the contact page content.",
"type_slug": "pages"
}
]

0 comments on commit 096b352

Please sign in to comment.