CLI tool for exporting apps, tidy up
This commit is contained in:
parent
c83b1d4c35
commit
e7c3afb7f1
|
@ -1,12 +1,40 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { exportTemplateFromApp } = require("../src/utilities/templates")
|
const { exportTemplateFromApp } = require("../src/utilities/templates")
|
||||||
|
const yargs = require("yargs")
|
||||||
|
|
||||||
// Script to export a chosen budibase app into a package
|
// Script to export a chosen budibase app into a package
|
||||||
|
// Usage: ./scripts/exportAppTemplate.js export --name=Funky --instanceId=someInstanceId --appId=appId
|
||||||
|
|
||||||
const [name, instanceId, appId] = process.argv.slice(1)
|
yargs
|
||||||
|
.command(
|
||||||
exportTemplateFromApp({
|
"export",
|
||||||
templateName: "Funky",
|
"Export an existing budibase application to the .budibase/templates directory",
|
||||||
instanceId: "inst_b70abba_16feb394866140a1ac3f2e450e99f28a",
|
{
|
||||||
appId: "b70abba3874546bf99a339911b579937",
|
name: {
|
||||||
})
|
description: "The name of the newly exported template",
|
||||||
|
alias: "n",
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
instanceId: {
|
||||||
|
description: "The instanceId to dump the database for",
|
||||||
|
alias: "inst",
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
appId: {
|
||||||
|
description: "The appId of the application you want to export",
|
||||||
|
alias: "app",
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async args => {
|
||||||
|
console.log("Exporting app..")
|
||||||
|
const exportPath = await exportTemplateFromApp({
|
||||||
|
templateName: args.name,
|
||||||
|
instanceId: args.instanceId,
|
||||||
|
appId: args.appId,
|
||||||
|
})
|
||||||
|
console.log(`Template ${args.name} exported to ${exportPath}`)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.help()
|
||||||
|
.alias("help", "h").argv
|
||||||
|
|
|
@ -9,7 +9,7 @@ router
|
||||||
.get("/api/templates", authorized(BUILDER), controller.fetch)
|
.get("/api/templates", authorized(BUILDER), controller.fetch)
|
||||||
.get(
|
.get(
|
||||||
"/api/templates/:type/:name",
|
"/api/templates/:type/:name",
|
||||||
// authorized(BUILDER),
|
authorized(BUILDER),
|
||||||
controller.downloadTemplate
|
controller.downloadTemplate
|
||||||
)
|
)
|
||||||
.post("/api/templates", authorized(BUILDER), controller.exportTemplateFromApp)
|
.post("/api/templates", authorized(BUILDER), controller.exportTemplateFromApp)
|
||||||
|
|
|
@ -15,7 +15,6 @@ const DEFAULT_TEMPLATES_BUCKET =
|
||||||
|
|
||||||
exports.downloadTemplate = async function(type, name) {
|
exports.downloadTemplate = async function(type, name) {
|
||||||
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`
|
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`
|
||||||
console.log(templateUrl, type, name)
|
|
||||||
const response = await fetch(templateUrl)
|
const response = await fetch(templateUrl)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
@ -40,7 +39,6 @@ exports.exportTemplateFromApp = async function({
|
||||||
instanceId,
|
instanceId,
|
||||||
}) {
|
}) {
|
||||||
// Copy frontend files
|
// Copy frontend files
|
||||||
console.log("Copying frontend definition...")
|
|
||||||
const appToExport = path.join(os.homedir(), ".budibase", appId, "pages")
|
const appToExport = path.join(os.homedir(), ".budibase", appId, "pages")
|
||||||
const templatesDir = path.join(os.homedir(), ".budibase", "templates")
|
const templatesDir = path.join(os.homedir(), ".budibase", "templates")
|
||||||
fs.ensureDirSync(templatesDir)
|
fs.ensureDirSync(templatesDir)
|
||||||
|
@ -54,7 +52,6 @@ exports.exportTemplateFromApp = async function({
|
||||||
// perform couch dump
|
// perform couch dump
|
||||||
const instanceDb = new CouchDB(instanceId)
|
const instanceDb = new CouchDB(instanceId)
|
||||||
|
|
||||||
console.log("Performing database dump..")
|
|
||||||
await instanceDb.dump(writeStream)
|
await instanceDb.dump(writeStream)
|
||||||
console.log("Export complete!")
|
return templateOutputPath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue