UNPKG

create-sps-project

Version:

CLI tool to create SPS Digital Tech template projects

67 lines (57 loc) 1.97 kB
const Logger = require('../utils/logger'); class ArgParser { constructor() { this.projectName = 'my-sps-project'; this.token = null; this.isDev = false; this.isSingleComponent = false; } parse(args) { // Parse arguments for (let i = 0; i < args.length; i++) { if (args[i] === '--token' || args[i] === '-t') { this.token = args[i + 1]; i++; // Skip next argument // Check if this is a component token (starts with sps_c_) if (this.token && this.token.startsWith('sps_c_')) { this.isSingleComponent = true; } } else if (args[i] === '--dev' || args[i] === '-d') { this.isDev = true; } else if (!this.projectName || this.projectName === 'my-sps-project') { this.projectName = args[i]; // Check if this is explicitly set to singleComponent if (this.projectName === 'singleComponent') { this.isSingleComponent = true; } } } return this.validate(); } validate() { // Validate token parameter if (!this.token) { Logger.error('Purchase token is required'); this.showUsage(); return false; } return true; } showUsage() { Logger.info('Usage: create-sps-project [project-name] --token <purchase-token>'); Logger.info('Options:'); Logger.info(' --token, -t Purchase token (required)'); Logger.info('\nExample: create-sps-project my-app --token sps_abc123'); Logger.info('Example: create-sps-project singleComponent --token sps_c_abc123'); Logger.info('\nYou can find your purchase tokens in your profile at https://sps-home.netlify.app/profile'); } getConfig() { return { projectName: this.projectName, token: this.token, isDev: this.isDev, isSingleComponent: this.isSingleComponent }; } } module.exports = ArgParser;