1
0
Fork 0
mirror of synced 2024-07-19 13:15:49 +12:00

Adding an option to disable top level parent directory creation during CLI plugin init incase using this for git repo creation.

This commit is contained in:
mike12345567 2022-09-13 18:22:15 +01:00
parent 5c5e1b10b4
commit 95f7bbd05b
2 changed files with 34 additions and 2 deletions

View file

@ -7,7 +7,7 @@ const { PLUGIN_TYPE_ARR } = require("@budibase/types")
const { validate } = require("@budibase/backend-core/plugins") const { validate } = require("@budibase/backend-core/plugins")
const { runPkgCommand } = require("../exec") const { runPkgCommand } = require("../exec")
const { join } = require("path") const { join } = require("path")
const { success, error, info } = require("../utils") const { success, error, info, moveDirectory } = require("../utils")
function checkInPlugin() { function checkInPlugin() {
if (!fs.existsSync("package.json")) { if (!fs.existsSync("package.json")) {
@ -45,13 +45,28 @@ async function init(opts) {
`An amazing Budibase ${type}!` `An amazing Budibase ${type}!`
) )
const version = await questions.string("Version", "1.0.0") const version = await questions.string("Version", "1.0.0")
console.log(
info(`By default the plugin will be created in the directory "${name}"`)
)
console.log(
info(
"if you are already in an empty directory, such as a new Git repo, you can disable this functionality."
)
)
const topLevel = await questions.confirmation("Create top level directory?")
// get the skeleton // get the skeleton
console.log(info("Retrieving project...")) console.log(info("Retrieving project..."))
await getSkeleton(type, name) await getSkeleton(type, name)
await fleshOutSkeleton(type, name, desc, version) await fleshOutSkeleton(type, name, desc, version)
console.log(info("Installing dependencies...")) console.log(info("Installing dependencies..."))
await runPkgCommand("install", join(process.cwd(), name)) await runPkgCommand("install", join(process.cwd(), name))
console.log(info(`Plugin created in directory "${name}"`)) // if no parent directory desired move to cwd
if (!topLevel) {
moveDirectory(name, process.cwd())
console.log(info(`Plugin created in current directory.`))
} else {
console.log(info(`Plugin created in directory "${name}"`))
}
} }
async function verify() { async function verify() {

View file

@ -3,6 +3,7 @@ const fs = require("fs")
const axios = require("axios") const axios = require("axios")
const path = require("path") const path = require("path")
const progress = require("cli-progress") const progress = require("cli-progress")
const { join } = require("path")
exports.downloadFile = async (url, filePath) => { exports.downloadFile = async (url, filePath) => {
filePath = path.resolve(filePath) filePath = path.resolve(filePath)
@ -67,3 +68,19 @@ exports.progressBar = total => {
exports.checkSlashesInUrl = url => { exports.checkSlashesInUrl = url => {
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2") return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2")
} }
exports.moveDirectory = (oldPath, newPath) => {
const files = fs.readdirSync(oldPath)
// check any file exists already
for (let file of files) {
if (fs.existsSync(file)) {
throw new Error(
"Unable to remove top level directory - some skeleton files already exist."
)
}
}
for (let file of files) {
fs.renameSync(join(oldPath, file), join(newPath, file))
}
fs.rmdirSync(oldPath)
}