chore: replace nosettings and mock by sandbox

This commit is contained in:
lowlighter
2022-01-27 01:11:22 -05:00
parent cca943ea92
commit ac995db988
7 changed files with 21 additions and 12 deletions

View File

@@ -19,7 +19,7 @@ const __preview_templates_ = paths.join(__preview, ".templates_")
const __preview_about = paths.join(__preview, "about/.statics") const __preview_about = paths.join(__preview, "about/.statics")
//Extract from web server //Extract from web server
const { conf, Templates } = await setup({ nosettings: true, log: false }) const { conf, Templates } = await setup({ log: false })
const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true })) const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true }))
const metadata = Object.fromEntries( const metadata = Object.fromEntries(
Object.entries(conf.metadata.plugins) Object.entries(conf.metadata.plugins)

View File

@@ -88,7 +88,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
} }
//Load configuration //Load configuration
const {conf, Plugins, Templates} = await setup({log:false, nosettings:true, community:{templates:core.getInput("setup_community_templates")}}) const {conf, Plugins, Templates} = await setup({log:false, community:{templates:core.getInput("setup_community_templates")}})
const {metadata} = conf const {metadata} = conf
conf.settings.extras = {default:true} conf.settings.extras = {default:true}
info("Setup", "complete") info("Setup", "complete")
@@ -288,7 +288,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
await new Promise(async (solve, reject) => { await new Promise(async (solve, reject) => {
let stdout = "" let stdout = ""
setTimeout(() => reject("Timeout while waiting for Insights webserver"), 5 * 60 * 1000) setTimeout(() => reject("Timeout while waiting for Insights webserver"), 5 * 60 * 1000)
const web = await processes.spawn("node", ["/metrics/source/app/web/index.mjs"], {env:{...process.env, NO_SETTINGS:true}}) const web = await processes.spawn("node", ["/metrics/source/app/web/index.mjs"], {env:{...process.env}})
web.stdout.on("data", data => (console.debug(`web > ${data}`), stdout += data, /Server ready !/.test(stdout) ? solve() : null)) web.stdout.on("data", data => (console.debug(`web > ${data}`), stdout += data, /Server ready !/.test(stdout) ? solve() : null))
web.stderr.on("data", data => console.debug(`web > ${data}`)) web.stderr.on("data", data => console.debug(`web > ${data}`))
}) })

View File

@@ -13,7 +13,7 @@ const Templates = {}
const Plugins = {} const Plugins = {}
/**Setup */ /**Setup */
export default async function({log = true, nosettings = false, community = {}} = {}) { export default async function({log = true, sandbox = false, community = {}} = {}) {
//Paths //Paths
const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..") const __metrics = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "../../..")
const __statics = path.join(__metrics, "source/app/web/statics") const __statics = path.join(__metrics, "source/app/web/statics")
@@ -42,8 +42,8 @@ export default async function({log = true, nosettings = false, community = {}} =
//Load settings //Load settings
logger("metrics/setup > load settings.json") logger("metrics/setup > load settings.json")
if (fs.existsSync(__settings)) { if (fs.existsSync(__settings)) {
if (nosettings) if (sandbox)
logger("metrics/setup > load settings.json > skipped because no settings is enabled") logger("metrics/setup > load settings.json > skipped because in sandbox is enabled")
else { else {
conf.settings = JSON.parse(`${await fs.promises.readFile(__settings)}`) conf.settings = JSON.parse(`${await fs.promises.readFile(__settings)}`)
logger("metrics/setup > load settings.json > success") logger("metrics/setup > load settings.json > success")

View File

@@ -1,4 +1,4 @@
import app from "./instance.mjs" import app from "./instance.mjs"
;(async function() { ;(async function() {
await app({mock:process.env.USE_MOCKED_DATA, nosettings:process.env.NO_SETTINGS}) await app({sandbox:process.env.SANDBOX})
})() })()

View File

@@ -12,11 +12,20 @@ import presets from "../metrics/presets.mjs"
import setup from "../metrics/setup.mjs" import setup from "../metrics/setup.mjs"
/**App */ /**App */
export default async function({mock, nosettings} = {}) { export default async function({sandbox} = {}) {
//Load configuration settings //Load configuration settings
const {conf, Plugins, Templates} = await setup({nosettings}) const {conf, Plugins, Templates} = await setup({sandbox})
const {token, maxusers = 0, restricted = [], debug = false, cached = 30 * 60 * 1000, port = 3000, ratelimiter = null, plugins = null} = conf.settings const {token, maxusers = 0, restricted = [], debug = false, cached = 30 * 60 * 1000, port = 3000, ratelimiter = null, plugins = null} = conf.settings
mock = mock || conf.settings.mocked const mock = sandbox || conf.settings.mocked
//Sandbox mode
if (sandbox) {
console.debug("metrics/app > sandbox mode is specified, enabling advanced features")
conf.settings.extras = conf.settings.extras ?? {}
conf.settings.extras.default = true
conf.settings["plugins.default"] = true
conf.settings.optimize = true
}
//Process mocking and default plugin state //Process mocking and default plugin state
for (const plugin of Object.keys(Plugins).filter(x => !["base", "core"].includes(x))) { for (const plugin of Object.keys(Plugins).filter(x => !["base", "core"].includes(x))) {

View File

@@ -229,7 +229,7 @@ if (/languages.analyzers.mjs$/.test(process.argv[1])) {
process.exit(1) process.exit(1)
} }
const {default:setup} = await import("../../app/metrics/setup.mjs") const {default:setup} = await import("../../app/metrics/setup.mjs")
const {conf:{metadata}} = await setup({log:false, nosettings:true}) const {conf:{metadata}} = await setup({log:false})
const {"commits.authoring":authoring} = await metadata.plugins.base.inputs({q:{"commits.authoring":_authoring}, account:"bypass"}) const {"commits.authoring":authoring} = await metadata.plugins.base.inputs({q:{"commits.authoring":_authoring}, account:"bypass"})
const data = {shared:{"commits.authoring":authoring}} const data = {shared:{"commits.authoring":authoring}}

View File

@@ -33,7 +33,7 @@ web.run = async vars => (await axios(`http://localhost:3000/lowlighter?${new url
web.start = async () => web.start = async () =>
new Promise(solve => { new Promise(solve => {
let stdout = "" let stdout = ""
web.instance = processes.spawn("node", ["source/app/web/index.mjs"], { env: { ...process.env, USE_MOCKED_DATA: true, NO_SETTINGS: true } }) web.instance = processes.spawn("node", ["source/app/web/index.mjs"], { env: { ...process.env, SANDBOX: true } })
web.instance.stdout.on("data", data => (stdout += data, /Server ready !/.test(stdout) ? solve() : null)) web.instance.stdout.on("data", data => (stdout += data, /Server ready !/.test(stdout) ? solve() : null))
web.instance.stderr.on("data", data => console.error(`${data}`)) web.instance.stderr.on("data", data => console.error(`${data}`))
}) })