UNPKG

create-sps-project

Version:

CLI tool to create SPS Digital Tech template projects

54 lines (46 loc) • 1.63 kB
const path = require('path'); const fs = require('fs'); const Logger = require('../utils/logger'); const Downloader = require('../services/downloader'); const TemplateInstaller = require('../services/template-installer'); class ProjectCreator { constructor(config) { this.config = { ...config, projectDir: config.isSingleComponent ? process.cwd() : path.join(process.cwd(), config.projectName) }; } async validateProject() { // Only check for existing directory if not in single component mode if (!this.config.isSingleComponent && fs.existsSync(this.config.projectDir)) { Logger.error(`Directory ${this.config.projectName} already exists`); return false; } return true; } async create() { try { const isValid = await this.validateProject(); if (!isValid) { return false; } Logger.info('\nšŸš€ Creating your SPS Digital Tech project\n'); Logger.info(this.config.isSingleComponent ? `Setting up component with token ${this.config.token}...` : `Setting up ${this.config.projectName}...`); // Download the template package const downloader = new Downloader(this.config); const zipPath = await downloader.downloadTemplate(); // Install the template const installer = new TemplateInstaller(this.config); await installer.install(zipPath); return true; } catch (error) { Logger.error('Failed to create project', error.message); return false; } } } module.exports = ProjectCreator;