@voidwalkers/void-cli
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "@voidwalkers/void-cli", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "CLI for Void Walkers Void", | ||
@@ -5,0 +5,0 @@ "main": "./src/app.js", |
@@ -6,2 +6,3 @@ import {Command} from 'commander'; | ||
import commandDeploy from '#src/commands/deploy.js'; | ||
import commandEnable from '#src/commands/enable.js'; | ||
import commandInit from '#src/commands/init.js'; | ||
@@ -21,4 +22,5 @@ | ||
.addCommand(commandDeploy) | ||
.addCommand(commandEnable) | ||
.addCommand(commandInit); | ||
await program.parseAsync(); |
@@ -112,27 +112,5 @@ import fs from 'node:fs'; | ||
.argument('[email]', 'User email') | ||
/* TODO .addOption( | ||
(new Option('--private-token [name]', 'Also create private token')) | ||
.conflicts(['tokens']) | ||
) | ||
.addOption( | ||
(new Option('--public-token [name]', 'Also create public token')) | ||
.conflicts(['tokens']) | ||
) | ||
.addOption( | ||
(new Option('-t, --tokens', 'Also create private and public token with default names')) | ||
.conflicts(['public-token', 'private-token']) | ||
) */ | ||
.action(async /* TODO ( */email /* TODO , options) */ => { | ||
.action(async email => { | ||
const globalConfig = loadGlobalConfig(); | ||
/* TODO let {privateToken, publicToken, tokens} = options; | ||
if ((privateToken === true) || tokens) { | ||
privateToken = 'Private token'; | ||
} | ||
if ((publicToken === true) || tokens) { | ||
publicToken = 'Public token'; | ||
} */ | ||
if (!globalConfig.admin?.secret) { | ||
@@ -174,10 +152,2 @@ console.log('Admin not logged in. Use "void-cli admin login"'); | ||
console.log(`Created user: ${JSON.stringify(data.item, null, 2)}`); | ||
/* TODO if (privateToken) { | ||
await createToken(globalConfig, data.item.id, privateToken, false); | ||
} | ||
if (publicToken) { | ||
await createToken(globalConfig, data.item.id, publicToken, true); | ||
} */ | ||
}); | ||
@@ -184,0 +154,0 @@ |
@@ -1,27 +0,11 @@ | ||
import {execSync} from 'node:child_process'; | ||
import fs from 'node:fs'; | ||
import {Command} from 'commander'; | ||
import {Command, Option} from 'commander'; | ||
import prompt from 'prompt'; | ||
import {PATH_CONFIG, PATH_FUNCTIONS} from '#src/lib/constants.js'; | ||
import {PATH_CONFIG, PATH_FUNCTIONS, PATH_WEBSITES} from '#src/lib/constants.js'; | ||
import {init as initFunctions} from '#src/lib/init/functions.js'; | ||
import {init as initWebsites} from '#src/lib/init/websites.js'; | ||
const DEFAULT_ENTRY_POINT = './src/index.js'; | ||
const TEMPLATE_ESLINTRC = 'extends:\n' + | ||
" - '@ololoepepe/eslint-config'\n"; | ||
/* eslint-disable array-element-newline */ | ||
// eslint-disable-next-line prefer-template | ||
const TEMPLATE_GITIGNORE = ['logs', '*.log', 'npm-debug.log*', 'yarn-debug.log*', 'yarn-error.log*', 'pids', '*.pid', | ||
'*.seed', '*.pid.lock', 'lib-cov', 'coverage', '.nyc_output', '.grunt', 'bower_components', '.lock-wscript', | ||
'build/Release', 'node_modules/', 'jspm_packages/', 'typings/', '.npm', '.eslintcache', '.node_repl_history', '*.tgz', | ||
'.yarn-integrity', '.env', '.idea'].join('\n') + '\n'; | ||
/* eslint-enable array-element-newline */ | ||
const TEMPLATE_INDEX = "import {registerHttpFunction} from '@voidwalkers/void-functions';\n\n" + | ||
"registerHttpFunction('hello-world', (req, res) => {\n" + | ||
" res.writeHead(200, {'Content-Type': 'text/plain'});\n" + | ||
" res.write('Hello World!');\n" + | ||
' res.end();\n' + | ||
'});\n'; | ||
function createConfig(slug, tokenPrivate, tokenPublic, entryPoint = DEFAULT_ENTRY_POINT, include = ['src']) { | ||
function createConfig(slug, tokenPrivate, tokenPublic) { | ||
// eslint-disable-next-line prefer-template | ||
@@ -32,4 +16,3 @@ return JSON.stringify({ | ||
tokenPrivate, | ||
tokenPublic, | ||
functions: {entryPoint, include} | ||
tokenPublic | ||
} | ||
@@ -39,27 +22,2 @@ }, null, 2) + '\n'; | ||
function createPackageJson(slug, entryPoint = DEFAULT_ENTRY_POINT) { | ||
/* eslint-disable sort-keys-shorthand/sort-keys-shorthand */ | ||
// eslint-disable-next-line prefer-template | ||
return JSON.stringify({ | ||
name: `${slug}-functions`, | ||
version: '0.1.0', | ||
main: entryPoint, | ||
imports: { | ||
'#src/*.js': './src/*.js' | ||
}, | ||
type: 'module', | ||
scripts: { | ||
lint: 'eslint ./src' | ||
}, | ||
devDependencies: { | ||
'@ololoepepe/eslint-config': '^0.0.16', | ||
eslint: '^8.54.0' | ||
}, | ||
dependencies: { | ||
'@voidwalkers/void-functions': '^0.1.2' | ||
} | ||
}, null, 2) + '\n'; | ||
/* eslint-enable sort-keys-shorthand/sort-keys-shorthand */ | ||
} | ||
const command = new Command('init'); | ||
@@ -69,3 +27,4 @@ | ||
.description('Initialize Void project') | ||
.action(async () => { | ||
.addOption(new Option('-c, --components [components...]', 'Components to enable').choices(['functions', 'websites'])) | ||
.action(async ({components}) => { | ||
if (fs.existsSync(PATH_CONFIG)) { | ||
@@ -77,2 +36,6 @@ console.log('Config file void.json already exists'); | ||
if (!Array.isArray(components)) { | ||
components = ['functions', 'websites']; | ||
} | ||
prompt.start(); | ||
@@ -119,20 +82,20 @@ | ||
if (fs.existsSync(PATH_FUNCTIONS)) { | ||
console.log('"functions" directory already exists. Skipping it\'s creation\n'); | ||
} else { | ||
fs.mkdirSync(`${PATH_FUNCTIONS}/src`, {recursive: true}); | ||
console.log(`Selected components:\n\n${components.join('\n')}\n`); | ||
fs.writeFileSync(`${PATH_FUNCTIONS}/src/index.js`, TEMPLATE_INDEX, 'utf8'); | ||
fs.writeFileSync(`${PATH_FUNCTIONS}/package.json`, createPackageJson(projectSlug), 'utf8'); | ||
fs.writeFileSync(`${PATH_FUNCTIONS}/.gitignore`, TEMPLATE_GITIGNORE, 'utf8'); | ||
fs.writeFileSync(`${PATH_FUNCTIONS}/.eslintrc.yml`, TEMPLATE_ESLINTRC, 'utf8'); | ||
if (components.includes('functions')) { | ||
if (fs.existsSync(PATH_FUNCTIONS)) { | ||
console.log('"functions" directory already exists. Skipping it\'s creation\n'); | ||
} else { | ||
initFunctions(projectSlug); | ||
} | ||
} | ||
console.log('Running "npm install"\n'); | ||
if (components.includes('websites')) { | ||
if (fs.existsSync(PATH_WEBSITES)) { | ||
console.log('"websites" directory already exists. Skipping it\'s creation\n'); | ||
} else { | ||
initWebsites(projectSlug); | ||
} | ||
} | ||
execSync('npm install', { | ||
cwd: PATH_FUNCTIONS, | ||
stdio: 'inherit' | ||
}); | ||
console.log( | ||
@@ -139,0 +102,0 @@ "Project initialized. Don't forget to add void.json to .gitignore as it contains sensitive information" |
@@ -9,3 +9,4 @@ const CWD = process.cwd(); | ||
export const PATH_FUNCTIONS = `${CWD}/functions`; | ||
export const PATH_WEBSITES = `${CWD}/websites`; | ||
export const RX_EMAIL = /^[^@]+@[^@]+\.[^.@]+$/u; |
@@ -0,3 +1,11 @@ | ||
import fs from 'node:fs'; | ||
import prompt from 'prompt'; | ||
import {PATH_CONFIG} from '#src/lib/constants.js'; | ||
export function loadConfig() { | ||
return JSON.parse(fs.readFileSync(PATH_CONFIG, 'utf8')); | ||
} | ||
export async function promptYesNo(description, defaultValue = false) { | ||
@@ -21,1 +29,9 @@ try { | ||
} | ||
export function saveConfig(config) { | ||
fs.writeFileSync(PATH_CONFIG, JSON.stringify(config, null, 2), 'utf8'); | ||
} | ||
export function updateConfig(transform) { | ||
saveConfig(transform(loadConfig())); | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23093
12
614
0