New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zondax/cli

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zondax/cli - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

src/cmd/testcmd.ts

2

package.json
{
"name": "@zondax/cli",
"version": "0.0.10",
"version": "0.0.11",
"description": "Zondax CLI",

@@ -5,0 +5,0 @@ "author": "Zondax AG <hello@zondax.ch>",

@@ -1,2 +0,2 @@

import { applyTemplateSection } from '../tools/templates'
import { processTemplateSection } from '../tools/templates'
import { TemplateConfig } from '../types'

@@ -20,4 +20,4 @@

await applyTemplateSection('/tmp/npx', templateConfig)
await processTemplateSection('/tmp/npx', templateConfig)
})
})
import path from 'path'
import { getConfigFilename } from '../config'
import { applyTemplateSection, getTemplateConfig, loadConfigFile } from '../tools/templates'
import { applyAllTemplates } from '../tools/templates'
export async function cmdUpdate() {
// FIXME: Show error message if config is missing
const config = loadConfigFile(getConfigFilename())
// TODO: check that we don't have pending changes.. otherwise skip
// - User is expected to commit or stash before this can be applied
const cwd = path.resolve('.')
for (let i = 0; i < config.templates.length; i++) {
const templateConfig = getTemplateConfig(config, i)
console.log(`[Applying] ${templateConfig.local.template}`)
await applyTemplateSection(cwd, templateConfig)
}
await applyAllTemplates(cwd)
return 0
}

@@ -5,2 +5,5 @@ import path from 'path'

// Remove .git/*
export const IGNORE_REGEX = [/^\.git\//, /^zondax.yaml$/, /^\.gitignore$/]
export function getConfigFilename(): string {

@@ -7,0 +10,0 @@ const cwd = path.resolve('.')

@@ -7,2 +7,3 @@ #!/usr/bin/env ts-node

import { cmdKubeconfig } from './cmd/kubeconfig'
import { cmdTest } from './cmd/testcmd'
import { cmdUpdate } from './cmd/update'

@@ -37,2 +38,9 @@

program
.command('test')
.description('Test template')
.action(async () => {
await cmdTest()
})
program
.command('kubeconfig')

@@ -39,0 +47,0 @@ .description('Kubeconfig')

@@ -10,2 +10,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

import { IGNORE_REGEX, getConfigFilename } from '../config'
import { GlobalConfig, TemplateConfig } from '../types'

@@ -68,7 +69,29 @@ import { allFilesTemplate, ensureDirectory } from './tools'

export async function applyTemplateSection(cwd: string, templateConfig: TemplateConfig) {
async function applyTemplateSection(inputDir: string, outputDir: string, templateConfig: TemplateConfig) {
const allFiles = await allFilesTemplate(inputDir, IGNORE_REGEX)
allFiles.map(f => applyTemplateFile(inputDir, outputDir, f, templateConfig))
}
function applyTemplateFile(inputDir: string, outputDir: string, f: string, templateConfig: TemplateConfig) {
const absInputFilename = path.join(inputDir, f)
const absOutputFilename = path.join(outputDir, f)
const renderedContent = renderTemplate(absInputFilename, templateConfig)
ensureDirectory(absOutputFilename)
fs.writeFileSync(absOutputFilename, renderedContent)
}
export async function processTemplateSection(outputDir: string, templateConfig: TemplateConfig) {
if (templateConfig.local.template === '.') {
// Run local template
const cwd = path.resolve('./template')
await applyTemplateSection(cwd, outputDir, templateConfig)
return
}
// TODO: refactor this so we can handle file:// and git:// or tpl:// ??
// else git clone
const tmpDir = await createTempDirectory()
try {
const repoUrl = `https://git.zondax.dev/zondax/${templateConfig.local.template}.git`
// Move contents to $HOME/.kube
await git.clone({

@@ -87,16 +110,3 @@ fs,

// Remove .git/*
const ignoreRegex = [/^\.git\//]
// Get all cloned files
const allFiles = await allFilesTemplate(tmpDir.path, ignoreRegex)
allFiles.map(f => {
const absInputFilename = path.join(tmpDir.path, f)
const absOutputFilename = path.join(cwd, f)
const renderedContent = renderTemplate(absInputFilename, templateConfig)
ensureDirectory(absOutputFilename)
fs.writeFileSync(absOutputFilename, renderedContent)
})
await applyTemplateSection(path.join(tmpDir.path, 'template'), outputDir, templateConfig)
} finally {

@@ -106,1 +116,14 @@ await tmpDir.remove()

}
export async function applyAllTemplates(outputDir: string) {
// FIXME: Show error message if config is missing
const config = loadConfigFile(getConfigFilename())
// TODO: check that we don't have pending changes.. otherwise skip
// - User is expected to commit or stash before this can be applied
for (let i = 0; i < config.templates.length; i++) {
const templateConfig = getTemplateConfig(config, i)
console.log(`[Applying] ${templateConfig.local.template}`)
await processTemplateSection(outputDir, templateConfig)
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc