2020-09-25 15:47:42 +02:00
|
|
|
#!/usr/bin/env node
|
2020-09-29 11:32:42 +02:00
|
|
|
const yargs = require("yargs")
|
2021-03-19 20:07:47 +01:00
|
|
|
const fs = require("fs")
|
|
|
|
const { join } = require("path")
|
|
|
|
const CouchDB = require("../src/db")
|
2021-03-25 19:03:58 +01:00
|
|
|
// 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 => {
|
2021-03-25 19:03:58 +01:00
|
|
|
if (!env.isDev()) {
|
|
|
|
throw "Only works in dev"
|
|
|
|
}
|
2021-03-19 20:07:47 +01:00
|
|
|
const name = args.name,
|
|
|
|
appId = args.appId
|
2020-09-29 11:32:42 +02:00
|
|
|
console.log("Exporting app..")
|
2021-03-19 20:07:47 +01:00
|
|
|
if (name == null || appId == null) {
|
2020-11-06 13:30:30 +01:00
|
|
|
console.error(
|
|
|
|
"Unable to export without a name and app ID being specified, check help for more info."
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
2021-03-25 19:03:58 +01:00
|
|
|
const exportPath = join(process.cwd(), name, "db")
|
2021-03-19 20:07:47 +01:00
|
|
|
fs.ensureDirSync(exportPath)
|
|
|
|
const writeStream = fs.createWriteStream(join(exportPath, "dump.text"))
|
|
|
|
// perform couch dump
|
2021-03-25 19:03:58 +01:00
|
|
|
|
2021-03-19 20:07:47 +01:00
|
|
|
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
|