Snpy is a tool for generating templates using various options to gather user input.
npm install -D snpyimport { Snpy } from 'snpy';
await Snpy.prompt(async snpy => {
//...
});Receives a string input.
const component_name = await snpy.run({
type: 'input',
name: 'component_name',
message: 'Enter component name',
default: 'Component',
});Selects a directory.
const targetDir = await snpy.run({
type: 'directory',
name: 'targetDir',
message: 'Choose target directory',
basePath: '.',
});Selects one item from a list.
const framework = await snpy.run({
type: 'list',
name: 'framework',
message: 'Choose a framework:',
choices: ['React', 'Vue', 'Angular', 'Svelte'],
});Selects multiple items from a list.
const database = await snpy.run({
type: 'nlist',
name: 'database',
message: 'Choose a database:',
choices: ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis'],
});Selects multiple items using checkboxes.
const features = await snpy.run({
type: 'checkbox',
name: 'features',
message: 'Select features to include:',
choices: ['Authentication', 'API Integration', 'File Upload', 'Real-time Updates'],
});Asks for confirmation.
const typescript = await snpy.run({
type: 'confirm',
name: 'typescript',
message: 'Would you like to use TypeScript?',
default: true,
});import { Snpy } from 'snpy';
const template = (component_name: string) => {
return `<template>
${component_name}
</template>`;
};
(async () => {
await Snpy.prompt(async snpy => {
const component_name = await snpy.run({
type: 'input',
name: 'component_name',
message: 'Enter component name',
default: 'Button',
});
const targetDir = await snpy.run({
type: 'directory',
name: 'targetDir',
message: 'Choose target directory',
basePath: './src',
});
const file_name = `${component_name}.ts`;
const tmpl = template(component_name);
snpy.makeTemplate({
dir: targetDir,
file_name,
code: tmpl,
});
snpy.logSuccess('Template created successfully.');
});
})();Creates a template file.
snpy.makeTemplate({
dir: 'path/to/dir',
file_name: 'template.ts',
code: '<template>Component</template>',
});Creates a new folder.
const newPath = snpy.makeFolder('path/to/dir', 'newFolder');
snpy.logHint(`Folder created at ${newPath}`);Logs a message.
snpy.log('This is a log message.');
snpy.logSuccess('Operation completed successfully.');
snpy.logError('An error occurred.');
snpy.logHint('This is a hint.');