Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yocode

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yocode - npm Package Compare versions

Comparing version 1.0.0-alpha to 1.0.0-alpha.2

lib/generateCommand.js

108

index.js
#!/usr/bin/env node
import fs from "fs"; // Import fs to interact with the filesystem
import { Command } from "commander"; // Import Commander.js for CLI functionality
import path from "path";

@@ -8,43 +10,89 @@ import { getPrompts } from "./lib/prompts.js";

import { installPackages } from "./lib/packageInstaller.js";
import { generateCommand } from "./lib/generateCommand.js"; // Function for command scaffolding
async function main() {
console.log(`
const program = new Command();
// Display the Yocode banner
console.log(`
🚀 Yocode - Your VS Code Extension Generator 🚀
Ready to bring your extension ideas to life!
`);
`);
const answers = await getPrompts();
const targetDir = path.join(process.cwd(), answers.identifier);
// `yocode init` command to initialize a new project
program
.command("init")
.description("Initialize a new VS Code extension project")
.action(async () => {
const answers = await getPrompts();
const targetDir = path.join(process.cwd(), answers.identifier);
// Step 1: Generate all necessary files and folders
await generateFiles(targetDir, answers);
// Step 1: Generate files
await generateFiles(targetDir, answers);
// Step 2: Initialize Git, if requested
if (answers.gitInit) {
// Step 2: Initialize Git
if (answers.gitInit) {
try {
await initializeGit(targetDir);
} catch (error) {
console.error("Failed to initialize Git repository:", error);
}
}
// Step 3: Install dependencies
try {
await initializeGit(targetDir);
await installPackages(targetDir, answers.packageManager);
} catch (error) {
console.error("Failed to initialize Git repository:", error);
console.error(
`Failed to install dependencies with ${answers.packageManager}:`,
error
);
}
}
// Step 3: Install dependencies using the specified package manager
try {
await installPackages(targetDir, answers.packageManager);
} catch (error) {
console.error(
`Failed to install dependencies with ${answers.packageManager}:`,
error
// Success message
console.log(
`🎉 Congratulations! Your project has been set up successfully in ${targetDir} 🎉`
);
}
console.log("🚀 Time to start building your awesome extension! 🚀");
});
// Final message after project setup is complete
console.log(
`🎉 Congratulations! Your project has been set up successfully in ${targetDir} 🎉`
);
console.log(
"🚀 Time to start building your awesome extension! Happy coding! 🚀"
);
}
// `yocode generate:command <commandName>` to scaffold a new command
program
.command("generate:command <commandName>")
.description("Generate a new command in the current project")
.action(async (commandName) => {
const targetDir = process.cwd(); // Use the current working directory
const packageJsonPath = path.join(targetDir, "package.json");
main();
// Check if the command is being run inside a valid Yocode project
if (!fs.existsSync(packageJsonPath)) {
console.error(
"❌ Error: package.json not found. Please run this command inside a Yocode project."
);
return;
}
// Detect the language type from package.json
let languageType = "JavaScript"; // Default to JavaScript
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
if (packageJson.devDependencies?.typescript) {
languageType = "TypeScript";
}
} catch (error) {
console.error("❌ Error reading package.json:", error.message);
return;
}
try {
await generateCommand(commandName, languageType, targetDir);
} catch (error) {
console.error(
`❌ Failed to generate the command "${commandName}": ${error.message}`
);
}
});
// Parse CLI arguments
program.parse(process.argv);
// spinner.succeed('Files generated successfully!');

@@ -86,3 +86,3 @@ import path from "path";

{ template: "jsconfig.json.ejs", target: "jsconfig.json" },
{ template: "src/extension.js.ejs", target: "src/extension.js" },
{ template: "extension.js.ejs", target: "extension.js" },
{ template: ".vscode-test.mjs.ejs", target: ".vscode-test.mjs" },

@@ -136,2 +136,2 @@ { template: ".npmrc-pnpm.ejs", target: ".npmrc-pnpm" },

}
}
}

@@ -1,59 +0,60 @@

import inquirer from 'inquirer';
import inquirer from "inquirer";
export async function getPrompts() {
const answers = await inquirer.prompt([
{
type: 'list',
name: 'languageType',
message: 'Select the language you want to use:',
choices: [
'TypeScript',
'JavaScript'
]
},
{
type: 'input',
name: 'displayName',
message: "Enter a display name for your extension:",
validate: input => input ? true : 'Display name is required.'
},
{
type: 'input',
name: 'identifier',
message: "Enter an identifier for your extension:",
default: answers => answers.displayName.toLowerCase().replace(/\s+/g, '-'),
validate: input => {
const isValid = /^[a-z0-9\-]+$/.test(input);
return isValid || 'Identifier must be lowercase and contain only letters, numbers, and hyphens.';
},
filter: input => input.toLowerCase().replace(/\s+/g, '-')
},
{
type: 'input',
name: 'description',
message: "Provide a brief description for your extension:"
},
{
type: 'confirm',
name: 'jsTypeChecking',
message: "Enable JavaScript type checking in 'jsconfig.json'?",
default: false,
when: answers => answers.languageType.includes('JavaScript')
},
{
type: 'confirm',
name: 'gitInit',
message: 'Do you want to initialize a Git repository?',
default: true
},
{
type: 'list',
name: 'packageManager',
message: 'Select a package manager to use:',
choices: ['npm', 'yarn', 'pnpm'],
default: 'npm'
}
]);
const answers = await inquirer.prompt([
{
type: "list",
name: "languageType",
message: "Select the language you want to use:",
choices: ["TypeScript", "JavaScript"],
},
{
type: "input",
name: "displayName",
message: "Enter a display name for your extension:",
validate: (input) => (input ? true : "Display name is required."),
},
{
type: "input",
name: "identifier",
message: "Enter an identifier for your extension:",
default: (answers) =>
answers.displayName.toLowerCase().replace(/\s+/g, "-"),
validate: (input) => {
const isValid = /^[a-z0-9\-]+$/.test(input);
return (
isValid ||
"Identifier must be lowercase and contain only letters, numbers, and hyphens."
);
},
filter: (input) => input.toLowerCase().replace(/\s+/g, "-"),
},
{
type: "input",
name: "description",
message: "Provide a brief description for your extension:",
},
{
type: "confirm",
name: "jsTypeChecking",
message: "Enable JavaScript type checking in 'jsconfig.json'?",
default: false,
when: (answers) => answers.languageType.includes("JavaScript"),
},
{
type: "confirm",
name: "gitInit",
message: "Do you want to initialize a Git repository?",
default: true,
},
{
type: "list",
name: "packageManager",
message: "Select a package manager to use:",
choices: ["npm", "yarn", "pnpm", "bun"],
default: "npm",
},
]);
return answers;
return answers;
}
{
"name": "yocode",
"description": "The VS Code Extension Generator for Modern Development.",
"version": "1.0.0-alpha",
"version": "1.0.0-alpha.2",
"type": "module",

@@ -45,2 +45,2 @@ "author": "Mr Sharafdin",

}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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