@voidwalkers/void-cli
Advanced tools
Comparing version 0.1.12 to 0.1.13
{ | ||
"name": "@voidwalkers/void-cli", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "CLI for Void Walkers Void", | ||
@@ -5,0 +5,0 @@ "main": "./src/app.js", |
@@ -6,2 +6,3 @@ import {Command} from 'commander'; | ||
import commandConfig from '#src/commands/config.js'; | ||
import commandCredentials from '#src/commands/credentials.js'; | ||
import commandDeploy from '#src/commands/deploy.js'; | ||
@@ -11,2 +12,3 @@ import commandEnable from '#src/commands/enable.js'; | ||
import commandMongo from '#src/commands/mongo.js'; | ||
import commandSettings from '#src/commands/settings.js'; | ||
import commandStorage from '#src/commands/storage.js'; | ||
@@ -26,2 +28,3 @@ | ||
.addCommand(commandConfig) | ||
.addCommand(commandCredentials) | ||
.addCommand(commandDeploy) | ||
@@ -31,4 +34,5 @@ .addCommand(commandEnable) | ||
.addCommand(commandMongo) | ||
.addCommand(commandSettings) | ||
.addCommand(commandStorage); | ||
await program.parseAsync(); |
@@ -1,47 +0,110 @@ | ||
import {Argument, Command} from 'commander'; | ||
import axios from 'axios'; | ||
import {Command, Option} from 'commander'; | ||
import {BASE_URL_API} from '#src/lib/constants.js'; | ||
import {loadConfig} from '#src/lib/helper.js'; | ||
function _parseValue(value, type) { | ||
if (value === null) { | ||
return { | ||
isOk: true, | ||
value: null | ||
}; | ||
} | ||
switch (type) { | ||
case 'boolean': | ||
if (!['true', 'false'].includes(value.toLowerCase())) { | ||
return {isOk: false}; | ||
} | ||
return { | ||
isOk: true, | ||
value: value.toLowerCase() === 'true' | ||
}; | ||
case 'number': | ||
if (!/^[0-9]+(?:\.[0-9]+)?$/u.test(value)) { | ||
return {isOk: false}; | ||
} | ||
return { | ||
isOk: true, | ||
value: Number(value) | ||
}; | ||
case 'object': | ||
try { | ||
const obj = JSON.parse(value); | ||
if (!obj || (typeof obj !== 'object') || Array.isArray(obj)) { | ||
return {isOk: false}; | ||
} | ||
return { | ||
isOk: true, | ||
value: obj | ||
}; | ||
} catch { | ||
return {isOk: false}; | ||
} | ||
case 'array': | ||
try { | ||
const arr = JSON.parse(value); | ||
if (!Array.isArray(arr)) { | ||
return {isOk: false}; | ||
} | ||
return { | ||
isOk: true, | ||
value: arr | ||
}; | ||
} catch { | ||
return {isOk: false}; | ||
} | ||
case 'string': | ||
default: | ||
return { | ||
value, | ||
isOk: true | ||
}; | ||
} | ||
} | ||
const command = new Command('config'); | ||
command.description('Manage project config'); | ||
command.description('Manage project configs'); | ||
command.command('print') | ||
.description('Print project config') | ||
.addArgument( | ||
(new Argument('[format]', 'Config format')) | ||
.choices(['client', 'server', 'raw']) | ||
.default('client') | ||
command.command('set') | ||
.description('Set config value') | ||
.argument('<key>', 'Config key') | ||
.argument('[value]', 'Config value', value => value, null) | ||
.addOption( | ||
(new Option('-t, --type <type>', 'Value type')) | ||
.choices(['boolean', 'number', 'string', 'object', 'array']) | ||
) | ||
.action(format => { | ||
const config = loadConfig(); | ||
.action(async (key, value, {type}) => { | ||
const { | ||
isOk, | ||
value: newValue | ||
} = _parseValue(value, type); | ||
switch (format) { | ||
case 'client': | ||
console.log(JSON.stringify({ | ||
project: { | ||
slug: config.project.slug, | ||
tokenPublic: config.project.tokenPublic | ||
} | ||
}, null, 2)); | ||
if (!isOk) { | ||
console.log('Invalid value'); | ||
break; | ||
case 'raw': | ||
console.log(JSON.stringify(config, null, 2)); | ||
return; | ||
} | ||
break; | ||
case 'server': | ||
console.log(JSON.stringify({ | ||
project: { | ||
slug: config.project.slug, | ||
tokenPrivate: config.project.tokenPrivate | ||
} | ||
}, null, 2)); | ||
const config = loadConfig(); | ||
break; | ||
default: | ||
break; | ||
} | ||
await axios.put(`${BASE_URL_API}/api/projects/${config.project.slug}/configs/${key}`, { | ||
value: newValue | ||
}, { | ||
headers: { | ||
Authorization: `Bearer ${config.project.tokenPrivate}` | ||
} | ||
}); | ||
}); | ||
export default command; |
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
const args = [].slice.call(process.argv, 2) | ||
.map(arg => arg.replace(/(\s)/ug, '\\$1')); | ||
.map(arg => arg.replace(/(\s|")/ug, '\\$1')); | ||
@@ -12,0 +12,0 @@ spawnSync(`node --no-warnings ${app}`, args, { |
@@ -47,3 +47,3 @@ import {execSync} from 'node:child_process'; | ||
dependencies: { | ||
'@voidwalkers/void-functions': '^0.1.7' | ||
'@voidwalkers/void-functions': '^0.1.8' | ||
} | ||
@@ -58,5 +58,8 @@ }, null, 2) + '\n'; | ||
// Using this hack to ensure the same instance of package is imported | ||
const {setRegisterHandler} = | ||
const {setGetConfigValueHandler, setRegisterHandler} = | ||
await import(resolve(`${PATH_FUNCTIONS}/node_modules/@voidwalkers/void-functions/src/index.js`)); | ||
// TODO: This may not work for some cases | ||
setGetConfigValueHandler(() => null); | ||
setRegisterHandler((type, name, func, options) => { | ||
@@ -63,0 +66,0 @@ list.push({name, options, type}); |
const CWD = process.cwd(); | ||
export const AuthEmailProvider = { | ||
Resend: 'resend' | ||
}; | ||
export const BucketType = { | ||
@@ -22,4 +26,21 @@ Private: 'private', | ||
export const PROJECT_SETTINGS = { | ||
auth: { | ||
custom: { | ||
isEnabled: [false, 'boolean'] | ||
}, | ||
email: { | ||
isEnabled: [true, 'boolean'], | ||
provider: [AuthEmailProvider.Resend, 'string', Object.values(AuthEmailProvider)], | ||
providers: { | ||
resend: { | ||
apiKey: [null, 'string'] | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
export const RX_BASE64 = | ||
/^(?:[a-zA-Z0-9+/]{4})*(?:|[a-zA-Z0-9+/]{3}=|[a-zA-Z0-9+/]{2}==|[a-zA-Z0-9+/]===)$/u; | ||
export const RX_EMAIL = /^[^@]+@[^@]+\.[^.@]+$/u; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48762
20
1409