JSPM

@scaffit/core

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 468
  • Score
    100M100P100Q63937F
  • License MIT

Core utilities for Scaffit - Framework detection, AST manipulation, file operations, and scaffold execution

Package Exports

  • @scaffit/core

Readme

@scaffit/core

Core utilities for Scaffit - Framework detection, AST manipulation, file operations, and scaffold execution.

Features

  • Framework Detection: Automatically detect Next.js, React, Vue, Angular, Svelte, Express, Fastify, Node.js
  • AST Engine: Parse, modify, and generate JavaScript/TypeScript code
  • File Operations: Safe file reading/writing with project detection
  • Template Engine: Variable replacement and conditional rendering
  • Scaffold Executor: Common installation logic and dependency management
  • Validation: Zod-based configuration validation

Usage

import { FileOperations, ASTEngine, ScaffoldExecutor } from '@scaffit/core';

// Detect project framework
const framework = FileOperations.detectFramework('./my-project');
const projectInfo = FileOperations.detectProject('./my-project');

// Parse and modify files
const ast = ASTEngine.parseFile('./src/index.ts');
ASTEngine.addImport('./src/index.ts', 'react', ['useState']);

// Execute scaffold
const result = await ScaffoldExecutor.executeScaffold(scaffold, config, './my-project');

API

FileOperations

  • detectFramework(rootDir) - Detect project framework (Next.js, React, Vue, Angular, Svelte, Express, Fastify, Node.js)
  • detectProject(rootDir) - Detect framework and configuration
  • readFile(filePath) - Safely read file
  • writeFile(filePath, content) - Safely write file
  • addDependency(rootDir, name, version, isDev) - Add package dependency
  • addScript(rootDir, name, command) - Add npm script
  • getFrameworkConfigPaths(framework) - Get framework-specific directory paths
  • getFrameworkExtensions(framework) - Get framework-specific file extensions
  • getFrameworkDependencies(framework) - Get recommended dependencies for framework

ASTEngine

  • parseFile(filePath) - Parse JS/TS to AST
  • addImport(filePath, source, specifiers) - Add import statement
  • addExport(filePath, name, value) - Add export statement
  • addFunction(filePath, name, params, body) - Add function
  • applyModifications(filePath, modifications) - Apply multiple changes

TemplateEngine

  • renderTemplate(template, variables) - Simple variable replacement
  • renderTemplateWithConditionals(template, variables) - With if/unless blocks
  • generateFileContent(templatePath, variables) - Generate file content

ScaffoldExecutor

  • executeScaffold(scaffold, config, projectRoot) - Run scaffold installation
  • getScaffoldPreview(scaffold, config, projectRoot) - Preview changes
  • createFileFromTemplate(filePath, templateName, variables) - Create file
  • installDependencies(projectRoot, packageManager) - Install deps