2020-04-29 21:29:42 +02:00
|
|
|
const { appPackageFolder } = require("../createAppPackage")
|
2020-02-03 10:24:25 +01:00
|
|
|
const {
|
|
|
|
readJSON,
|
|
|
|
writeJSON,
|
|
|
|
readdir,
|
|
|
|
ensureDir,
|
|
|
|
rename,
|
|
|
|
unlink,
|
|
|
|
rmdir,
|
|
|
|
} = require("fs-extra")
|
2020-04-20 17:17:11 +02:00
|
|
|
const { join, dirname, resolve } = require("path")
|
2020-02-03 10:24:25 +01:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const buildPage = require("./buildPage")
|
2020-02-10 22:35:51 +01:00
|
|
|
const getPages = require("./getPages")
|
|
|
|
const listScreens = require("./listScreens")
|
2020-02-18 13:29:38 +01:00
|
|
|
const deleteCodeMeta = require("./deleteCodeMeta")
|
2020-02-03 10:24:25 +01:00
|
|
|
|
2020-02-10 22:35:51 +01:00
|
|
|
module.exports.buildPage = buildPage
|
|
|
|
module.exports.listScreens = listScreens
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
const getAppDefinition = async appPath =>
|
|
|
|
await readJSON(`${appPath}/appDefinition.json`)
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-03-10 11:05:09 +01:00
|
|
|
module.exports.getPackageForBuilder = async (config, application) => {
|
2020-04-28 15:39:35 +02:00
|
|
|
const appPath = resolve(config.latestPackagesFolder, application._id);
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const pages = await getPages(appPath)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
return {
|
|
|
|
pages,
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-03-10 11:05:09 +01:00
|
|
|
application,
|
2020-04-28 15:39:35 +02:00
|
|
|
|
|
|
|
clientId: process.env.CLIENT_ID
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
2019-07-13 11:35:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const screenPath = (appPath, pageName, name) =>
|
|
|
|
join(appPath, "pages", pageName, "screens", name + ".json")
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
module.exports.saveScreen = async (config, appname, pagename, screen) => {
|
|
|
|
const appPath = appPackageFolder(config, appname)
|
|
|
|
const compPath = screenPath(appPath, pagename, screen.name)
|
2020-02-03 10:24:25 +01:00
|
|
|
await ensureDir(dirname(compPath))
|
2020-02-10 16:51:09 +01:00
|
|
|
if (screen._css) {
|
|
|
|
delete screen._css
|
|
|
|
}
|
2020-02-18 13:29:38 +01:00
|
|
|
|
|
|
|
deleteCodeMeta(screen.props)
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
await writeJSON(compPath, screen, {
|
2020-02-03 10:24:25 +01:00
|
|
|
encoding: "utf8",
|
|
|
|
flag: "w",
|
|
|
|
spaces: 2,
|
|
|
|
})
|
2020-02-18 13:29:38 +01:00
|
|
|
return screen
|
2019-07-26 18:08:59 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
module.exports.renameScreen = async (
|
|
|
|
config,
|
|
|
|
appname,
|
|
|
|
pagename,
|
|
|
|
oldName,
|
|
|
|
newName
|
|
|
|
) => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const appPath = appPackageFolder(config, appname)
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const oldComponentPath = screenPath(appPath, pagename, oldName)
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const newComponentPath = screenPath(appPath, pagename, newName)
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
await ensureDir(dirname(newComponentPath))
|
|
|
|
await rename(oldComponentPath, newComponentPath)
|
2019-07-26 18:08:59 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
module.exports.deleteScreen = async (config, appname, pagename, name) => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const appPath = appPackageFolder(config, appname)
|
2020-02-10 16:51:09 +01:00
|
|
|
const componentFile = screenPath(appPath, pagename, name)
|
2020-02-03 10:24:25 +01:00
|
|
|
await unlink(componentFile)
|
|
|
|
|
|
|
|
const dir = dirname(componentFile)
|
|
|
|
if ((await readdir(dir)).length === 0) {
|
|
|
|
await rmdir(dir)
|
|
|
|
}
|
2019-07-26 18:08:59 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
module.exports.savePage = async (config, appname, pagename, page) => {
|
|
|
|
const appPath = appPackageFolder(config, appname)
|
|
|
|
const pageDir = join(appPath, "pages", pagename)
|
|
|
|
|
|
|
|
await ensureDir(pageDir)
|
|
|
|
await writeJSON(join(pageDir, "page.json"), page, {
|
|
|
|
encoding: "utf8",
|
|
|
|
flag: "w",
|
|
|
|
space: 2,
|
|
|
|
})
|
|
|
|
const appDefinition = await getAppDefinition(appPath)
|
|
|
|
await buildPage(config, appname, appDefinition, pagename, page)
|
2020-05-04 18:13:57 +02:00
|
|
|
}
|