Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ async function createAction(projectName, options) {
initGit: options.git !== false,
enableSecurity: defaults.enableSecurity,
noInstall: options.install === false,
repo: options.repo || 'Ebyte-Lab/opusify-templates',
token: options.token || process.env.OPUSIFY_GITHUB_TOKEN || process.env.GITHUB_TOKEN,
};

console.log(chalk.green('✔ Using defaults (--yes mode)'));
Expand Down Expand Up @@ -286,6 +288,8 @@ async function createAction(projectName, options) {
initGit: options.git === false ? false : (answers.initGit !== undefined ? answers.initGit : true),
enableSecurity: answers.enableSecurity !== undefined ? answers.enableSecurity : true,
noInstall: options.install === false,
repo: options.repo || 'Ebyte-Lab/opusify-templates',
token: options.token || process.env.OPUSIFY_GITHUB_TOKEN || process.env.GITHUB_TOKEN,
};

console.log('\n' + chalk.green('✔ Configuration collected successfully!'));
Expand Down Expand Up @@ -376,6 +380,8 @@ program
.option('--sidebar', 'Include a sidebar layout')
.option('--no-git', 'Skip Git initialization')
.option('--no-install', 'Skip npm install')
.option('-r, --repo <repository>', 'Custom GitHub repository (e.g., "username/repo")')
.option('--token <token>', 'GitHub Personal Access Token for private repositories')
.option('-y, --yes', 'Accept all defaults (non-interactive)')
.action(createAction);

Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions src/generate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
import ora from 'ora';
import tiged from 'tiged';
import Handlebars from 'handlebars';
import { execSync } from 'child_process';
import { resolveDependencies } from './dependencies.js';

// Setup __dirname for ES Modules to fix the local template path bug
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Register custom Handlebars helpers
Handlebars.registerHelper('eq', function (a, b) {
return a === b;
Expand All @@ -29,6 +34,11 @@ function getAllFiles(dirPath, arrayOfFiles = []) {
export async function generateProject(config) {
console.log(chalk.cyan('\n⚙️ Starting the File Generation Engine...'));

// Inject token into environment for tiged to access private repos
if (config.token) {
process.env.GITHUB_TOKEN = config.token;
}

let projectName = config.projectName;
let projectPath = path.join(process.cwd(), projectName);

Expand All @@ -41,8 +51,10 @@ export async function generateProject(config) {
config.projectName = projectName; // Update config with final name

// 2. Check for Local vs GitHub
// FIX: Look in the CLI's installation directory, not the user's cwd
const localTemplatePath = path.join(
process.cwd(),
__dirname,
'..', // Go up one level from 'src' to reach the root where 'templates' is
'templates',
config.template,
config.architecture,
Expand All @@ -60,7 +72,9 @@ export async function generateProject(config) {
spinner.succeed(`Files copied to ./${projectName}`);
} else {
// 🔵 PRODUCTION MODE: Fetch from GitHub
const repoURI = `Ebyte-Lab/opusify-templates/${config.template}/${config.architecture}`;
const targetRepo = config.repo || 'Ebyte-Lab/opusify-templates';
const repoURI = `${targetRepo}/${config.template}/${config.architecture}`;

const spinner = ora({
text: `Fetching template from GitHub (${repoURI})...`,
spinner: 'squareCorners',
Expand All @@ -72,7 +86,10 @@ export async function generateProject(config) {
await emitter.clone(projectPath);
spinner.succeed(`Files copied to ./${projectName}`);
} catch (fetchError) {
spinner.fail('Failed to fetch template from GitHub.');
spinner.fail(`Failed to fetch template from GitHub: ${repoURI}`);
if (!config.token) {
console.log(chalk.yellow('\n⚠️ Hint: If this repository is private, you must provide a GitHub token using --token or set the OPUSIFY_GITHUB_TOKEN environment variable.'));
}
throw fetchError;
}
}
Expand Down Expand Up @@ -143,7 +160,7 @@ export async function generateProject(config) {
console.log(chalk.gray('\n⏭️ Skipping Git initialization.'));
}

// 7. Final Success Message
// 8. Final Success Message
console.log(chalk.magenta(`\n🎉 Project ${projectName} is ready!`));
console.log(chalk.white('\nNext steps:'));
console.log(chalk.cyan(` cd ${projectName}`));
Expand Down
Loading