From 096b3524b216c54bd395f994c7758b301db4816f Mon Sep 17 00:00:00 2001 From: Tony Spiro Date: Thu, 24 May 2018 20:48:22 -0500 Subject: [PATCH] import script, develop command --- package.json | 4 +++- scripts/import.js | 18 ++++++++++++++++++ scripts/object-type.json | 5 +++++ scripts/objects.json | 20 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 scripts/import.js create mode 100644 scripts/object-type.json create mode 100644 scripts/objects.json diff --git a/package.json b/package.json index 41be118..d2561ac 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/import.js b/scripts/import.js new file mode 100644 index 0000000..0ce3af8 --- /dev/null +++ b/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() \ No newline at end of file diff --git a/scripts/object-type.json b/scripts/object-type.json new file mode 100644 index 0000000..c309932 --- /dev/null +++ b/scripts/object-type.json @@ -0,0 +1,5 @@ +{ + "title": "Pages", + "slug": "pages", + "singular": "page" +} \ No newline at end of file diff --git a/scripts/objects.json b/scripts/objects.json new file mode 100644 index 0000000..e3e2f89 --- /dev/null +++ b/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" + } +] \ No newline at end of file