CLI tool for exporting apps, tidy up

This commit is contained in:
Martin McKeaveney 2020-09-29 10:32:42 +01:00
parent c83b1d4c35
commit e7c3afb7f1
3 changed files with 37 additions and 12 deletions

42
packages/server/scripts/exportAppTemplate.js Normal file → Executable file
View File

@ -1,12 +1,40 @@
#!/usr/bin/env node
const { exportTemplateFromApp } = require("../src/utilities/templates")
const yargs = require("yargs")
// 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)
exportTemplateFromApp({
templateName: "Funky",
instanceId: "inst_b70abba_16feb394866140a1ac3f2e450e99f28a",
appId: "b70abba3874546bf99a339911b579937",
})
yargs
.command(
"export",
"Export an existing budibase application to the .budibase/templates directory",
{
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

View File

@ -9,7 +9,7 @@ router
.get("/api/templates", authorized(BUILDER), controller.fetch)
.get(
"/api/templates/:type/:name",
// authorized(BUILDER),
authorized(BUILDER),
controller.downloadTemplate
)
.post("/api/templates", authorized(BUILDER), controller.exportTemplateFromApp)

View File

@ -15,7 +15,6 @@ const DEFAULT_TEMPLATES_BUCKET =
exports.downloadTemplate = async function(type, name) {
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`
console.log(templateUrl, type, name)
const response = await fetch(templateUrl)
if (!response.ok) {
@ -40,7 +39,6 @@ exports.exportTemplateFromApp = async function({
instanceId,
}) {
// Copy frontend files
console.log("Copying frontend definition...")
const appToExport = path.join(os.homedir(), ".budibase", appId, "pages")
const templatesDir = path.join(os.homedir(), ".budibase", "templates")
fs.ensureDirSync(templatesDir)
@ -54,7 +52,6 @@ exports.exportTemplateFromApp = async function({
// perform couch dump
const instanceDb = new CouchDB(instanceId)
console.log("Performing database dump..")
await instanceDb.dump(writeStream)
console.log("Export complete!")
return templateOutputPath
}