1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00
budibase/packages/server/scripts/exportAppTemplate.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-09-26 01:47:42 +12:00
#!/usr/bin/env node
2020-09-29 22:32:42 +13:00
const yargs = require("yargs")
const fs = require("fs")
const { join } = require("path")
require("../src/db").init()
const { doWithDB } = require("@budibase/backend-core/db")
// load environment
const env = require("../src/environment")
const {
USER_METDATA_PREFIX,
LINK_USER_METADATA_PREFIX,
} = require("../src/db/utils")
2020-09-26 01:47:42 +12:00
2020-09-29 05:04:08 +13:00
// Script to export a chosen budibase app into a package
2021-01-12 04:34:43 +13:00
// Usage: ./scripts/exportAppTemplate.js export --name=Funky --appId=appId
2020-09-26 01:47:42 +12:00
2020-09-29 22:32:42 +13: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",
},
},
2021-05-04 22:32:22 +12:00
async args => {
if (!env.isDev()) {
throw "Only works in dev"
}
const name = args.name,
appId = args.appId
2020-09-29 22:32:42 +13: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
await doWithDB(appId, async db => {
return db.dump(writeStream, {
filter: doc =>
!(
doc._id.includes(USER_METDATA_PREFIX) ||
doc.includes(LINK_USER_METADATA_PREFIX)
),
})
})
console.log(`Template ${name} exported to ${exportPath}`)
2020-09-29 22:32:42 +13:00
}
)
.help()
.alias("help", "h").argv