budibase/packages/server/scripts/exportAppTemplate.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-09-25 15:47:42 +02:00
#!/usr/bin/env node
2020-09-29 11:32:42 +02:00
const yargs = require("yargs")
const fs = require("fs")
const { join } = require("path")
const CouchDB = require("../src/db")
// load environment
const env = require("../src/environment")
2020-09-25 15:47:42 +02:00
2020-09-28 18:04:08 +02:00
// Script to export a chosen budibase app into a package
2021-01-11 16:34:43 +01:00
// Usage: ./scripts/exportAppTemplate.js export --name=Funky --appId=appId
2020-09-25 15:47:42 +02:00
2020-09-29 11:32:42 +02:00
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",
},
appId: {
description: "The appId of the application you want to export",
alias: "app",
type: "string",
},
},
async args => {
if (!env.isDev()) {
throw "Only works in dev"
}
const name = args.name,
appId = args.appId
2020-09-29 11:32:42 +02:00
console.log("Exporting app..")
if (name == null || appId == null) {
console.error(
"Unable to export without a name and app ID being specified, check help for more info."
)
return
}
const exportPath = join(process.cwd(), name, "db")
fs.ensureDirSync(exportPath)
const writeStream = fs.createWriteStream(join(exportPath, "dump.text"))
// perform couch dump
const instanceDb = new CouchDB(appId)
await instanceDb.dump(writeStream, {})
console.log(`Template ${name} exported to ${exportPath}`)
2020-09-29 11:32:42 +02:00
}
)
.help()
.alias("help", "h").argv