cli - new and run handlers
This commit is contained in:
parent
e2b393a077
commit
c2c4f5b174
|
@ -24,6 +24,7 @@
|
|||
"@budibase/server": "^0.0.32",
|
||||
"@inquirer/password": "^0.0.6-alpha.0",
|
||||
"chalk": "^2.4.2",
|
||||
"dotenv": "^8.2.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"inquirer": "^7.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
const inquirer = require("inquirer")
|
||||
const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
||||
const chalk = require("chalk")
|
||||
const { serverFileName } = require("../../common")
|
||||
const { serverFileName, xPlatHomeDir } = require("../../common")
|
||||
const { join } = require("path")
|
||||
const initialiseClientDb = require("@budibase/server/db/initialiseClientDb")
|
||||
const Sqrl = require("squirrelly")
|
||||
const uuid = require("uuid")
|
||||
const { homedir } = require("os")
|
||||
const CouchDb = require("@budibase/server/db/client")
|
||||
|
||||
module.exports = opts => {
|
||||
|
@ -26,9 +25,7 @@ const run = async opts => {
|
|||
}
|
||||
|
||||
const ensureAppDir = async opts => {
|
||||
if (opts.dir.startsWith("~")) {
|
||||
opts.dir = join(homedir(), opts.dir.substring(1))
|
||||
}
|
||||
opts.dir = xPlatHomeDir(opts.dir)
|
||||
await ensureDir(opts.dir)
|
||||
|
||||
if (opts.database === "local") {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"levels": [],
|
||||
"version": 0
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"hierarchy": {
|
||||
"name": "root",
|
||||
"type": "root",
|
||||
"children": [],
|
||||
"pathMaps":[],
|
||||
"indexes":[],
|
||||
"nodeId": 0
|
||||
},
|
||||
"triggers": [],
|
||||
"actions": [],
|
||||
"props": {}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"title": "Test App",
|
||||
"favicon": "./_shared/favicon.png",
|
||||
"stylesheets": [],
|
||||
"componentLibraries": ["@budibase/standard-components", "@budibase/materialdesign-components"],
|
||||
"props" : {
|
||||
"_component": "@budibase/standard-components/container",
|
||||
"_children": [],
|
||||
"_id": 1,
|
||||
"type": "div",
|
||||
"_styles": {
|
||||
"layout": {},
|
||||
"position": {}
|
||||
},
|
||||
"_code": ""
|
||||
},
|
||||
"_css": "",
|
||||
"uiFunctions": ""
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
whats the craic big lawd ?
|
|
@ -1 +0,0 @@
|
|||
whats the craic big lawd ?
|
|
@ -1,7 +1,7 @@
|
|||
const handler = require("./newHandler")
|
||||
|
||||
module.exports = {
|
||||
command: "new <name> [config]",
|
||||
command: "new <name> [dir]",
|
||||
desc: "Create a new Budibase app",
|
||||
builder: yargs => {
|
||||
yargs.positional("name", {
|
||||
|
@ -9,11 +9,11 @@ module.exports = {
|
|||
describe: "the name of your app",
|
||||
alias: "n",
|
||||
})
|
||||
yargs.positional("config", {
|
||||
yargs.positional("dir", {
|
||||
type: "string",
|
||||
describe: "config file to use - optional, defaults to config.js",
|
||||
alias: "c",
|
||||
default: "config.js",
|
||||
describe: "budibase apps directory",
|
||||
alias: "d",
|
||||
default: "~/budibase",
|
||||
})
|
||||
},
|
||||
handler,
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
const { getAppContext } = require("../../common")
|
||||
const {
|
||||
getMasterApisWithFullAccess,
|
||||
} = require("@budibase/server/utilities/budibaseApi")
|
||||
const { xPlatHomeDir } = require("../../common")
|
||||
const dotenv = require("dotenv")
|
||||
const createInstance = require("@budibase/server/middleware/controllers/instance").create
|
||||
const createApplication = require("@budibase/server/middleware/controllers/application").create
|
||||
const { copy, readJSON, writeJSON, remove, exists } = require("fs-extra")
|
||||
const { resolve, join } = require("path")
|
||||
const thisPackageJson = require("../../../package.json")
|
||||
const chalk = require("chalk")
|
||||
const { exec } = require("child_process")
|
||||
|
||||
|
@ -13,34 +12,42 @@ module.exports = opts => {
|
|||
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
||||
}
|
||||
|
||||
const run2 = async opts => {
|
||||
// create a brand new app in couch
|
||||
// create an empty app package locally
|
||||
exec(`cd ${join(opts.config.latestPackagesFolder, opts.name)} && npm install`)
|
||||
const run = async opts => {
|
||||
opts.dir = xPlatHomeDir(opts.dir)
|
||||
process.chdir(opts.dir)
|
||||
dotenv.config()
|
||||
await createRecords(opts)
|
||||
await createEmptyAppPackage(opts)
|
||||
exec(`cd ${join(opts.dir, opts.name)} && npm install`)
|
||||
}
|
||||
|
||||
const run = async opts => {
|
||||
const context = await getAppContext({
|
||||
configName: opts.config,
|
||||
masterIsCreated: true,
|
||||
const createRecords = async opts => {
|
||||
const createAppCtx = {
|
||||
params: { clientId: process.env.CLIENT_ID },
|
||||
request: {
|
||||
body: { name: opts.name },
|
||||
},
|
||||
body: {},
|
||||
}
|
||||
|
||||
await createApplication(createAppCtx)
|
||||
opts.applicationId = createAppCtx.body.id
|
||||
await createInstance({
|
||||
params: {
|
||||
clientId: process.env.CLIENT_ID,
|
||||
applicationId: opts.applicationId,
|
||||
},
|
||||
request: {
|
||||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||
},
|
||||
})
|
||||
opts.config = context.config
|
||||
const bb = await getMasterApisWithFullAccess(context)
|
||||
|
||||
const app = bb.recordApi.getNew("/applications", "application")
|
||||
app.name = opts.name
|
||||
|
||||
await bb.recordApi.save(app)
|
||||
await createEmptyAppPackage(opts)
|
||||
|
||||
exec(`cd ${join(opts.config.latestPackagesFolder, opts.name)} && npm install`)
|
||||
}
|
||||
|
||||
const createEmptyAppPackage = async opts => {
|
||||
const templateFolder = resolve(__dirname, "appPackageTemplate")
|
||||
const templateFolder = resolve(__dirname, "appDirectoryTemplate")
|
||||
|
||||
const appsFolder = opts.config.latestPackagesFolder || "."
|
||||
const destinationFolder = resolve(appsFolder, opts.name)
|
||||
const appsFolder = opts.dir
|
||||
const destinationFolder = resolve(appsFolder, opts.applicationId)
|
||||
|
||||
if (await exists(destinationFolder)) {
|
||||
console.log(chalk.red(`App ${opts.name} already exists.`))
|
||||
|
@ -49,13 +56,10 @@ const createEmptyAppPackage = async opts => {
|
|||
|
||||
await copy(templateFolder, destinationFolder)
|
||||
|
||||
const packageJsonPath = join(appsFolder, opts.name, "package.json")
|
||||
const packageJsonPath = join(appsFolder, opts.applicationId, "package.json")
|
||||
const packageJson = await readJSON(packageJsonPath)
|
||||
|
||||
packageJson.name = opts.name
|
||||
packageJson.dependencies[
|
||||
"@budibase/standard-components"
|
||||
] = `^${thisPackageJson.version}`
|
||||
|
||||
await writeJSON(packageJsonPath, packageJson)
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
const handler = require("./runHandler")
|
||||
|
||||
module.exports = {
|
||||
command: "run [config]",
|
||||
command: "run [dir]",
|
||||
aliases: ["$0"],
|
||||
desc:
|
||||
"Start budibase Server. You can access your apps and the builder from here if you have dev=true in your config",
|
||||
builder: yargs => {
|
||||
yargs.positional("config", {
|
||||
yargs.positional("dir", {
|
||||
type: "string",
|
||||
describe:
|
||||
"config file to use. optional, defaults to config.js. Use 'dev' as shorthand for 'config.dev.js' ",
|
||||
alias: "c",
|
||||
default: "config.js",
|
||||
describe: "your budibase apps directory",
|
||||
alias: "d",
|
||||
default: "~/budibase",
|
||||
})
|
||||
},
|
||||
handler,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const { getAppContext } = require("../../common")
|
||||
const app = require("@budibase/server/app")
|
||||
const { xPlatHomeDir } = require("../../common")
|
||||
|
||||
module.exports = ({ config }) => {
|
||||
getAppContext({ configName: config, masterIsCreated: true }).then(context => {
|
||||
app(context)
|
||||
console.log(`Budibase Builder running on port ${context.config.port}..`)
|
||||
})
|
||||
module.exports = ({ dir }) => {
|
||||
dir = xPlatHomeDir(dir)
|
||||
process.chdir(dir)
|
||||
app()
|
||||
console.log(`Budibase Builder running on port ${process.env.PORT}..`)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { resolve } = require("path")
|
||||
const { resolve, join } = require("path")
|
||||
const { cwd } = require("process")
|
||||
const buildAppContext = require("@budibase/server/initialise/buildAppContext")
|
||||
|
||||
const { homedir } = require("os")
|
||||
module.exports.serverFileName = relativePath =>
|
||||
resolve(__dirname, "..", "node_modules", "@budibase", "server", relativePath)
|
||||
|
||||
|
@ -17,3 +17,10 @@ module.exports.getAppContext = async ({ configName, masterIsCreated }) => {
|
|||
const config = require(resolve(cwd(), configName))()
|
||||
return await buildAppContext(config, masterIsCreated)
|
||||
}
|
||||
|
||||
module.exports.xPlatHomeDir = dir => {
|
||||
if (dir.startsWith("~")) {
|
||||
dir = join(homedir(), dir.substring(1))
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
|
|
@ -1509,6 +1509,11 @@ destroy@^1.0.4:
|
|||
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
|
||||
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
|
||||
|
||||
dotenv@^8.2.0:
|
||||
version "8.2.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
|
||||
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
|
||||
|
||||
ee-first@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
||||
|
|
Loading…
Reference in New Issue