devfast 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # devfast CLI
2
+
3
+ A fast scaffolding tool to generate projects from the devfast platform.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npx devfast create <template-id>
9
+ ```
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { createAction } from '../src/commands/create.js';
4
+ const program = new Command();
5
+ program
6
+ .name('devfast')
7
+ .description('CLI to scaffold projects from devfast')
8
+ .version('1.0.0');
9
+ program
10
+ .command('create <template-id>')
11
+ .action(createAction);
12
+ program.parse(process.argv);
@@ -0,0 +1,18 @@
1
+ import axios from 'axios';
2
+ const API_BASE = process.env.NODE_ENV === 'development'
3
+ ? 'http://localhost:3000'
4
+ : 'https://devfastv1.vercel.app';
5
+ export async function fetchTemplate(id) {
6
+ try {
7
+ const { data } = await axios.get(`${API_BASE}/api/cli/template`, {
8
+ params: { id }
9
+ });
10
+ return data;
11
+ }
12
+ catch (err) {
13
+ return {
14
+ status: err.response?.status || 500,
15
+ error: err.response?.data?.message || 'Server unreachable'
16
+ };
17
+ }
18
+ }
@@ -0,0 +1,55 @@
1
+ import prompts from 'prompts';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+ import ora from 'ora';
5
+ import degit from 'degit';
6
+ import { fetchTemplate } from '../api.js';
7
+ import { isValidProjectPath, isValidFolderName, isDirEmpty, formatMessage } from '../utils.js';
8
+ export async function createAction(templateId) {
9
+ const template = await fetchTemplate(templateId);
10
+ if (template.status !== 200 || !template.data) {
11
+ console.error(chalk.red(`Error: ${template.error || 'Invalid template ID'}`));
12
+ process.exit(1);
13
+ }
14
+ const response = await prompts({
15
+ type: 'text',
16
+ name: 'projectPath',
17
+ message: 'Project name or path:',
18
+ initial: templateId,
19
+ validate: (val) => {
20
+ if (!isValidProjectPath(val))
21
+ return 'Invalid characters in path';
22
+ const resolvedPath = path.resolve(process.cwd(), val);
23
+ const folderName = path.basename(resolvedPath);
24
+ if (val === '.')
25
+ return true;
26
+ return isValidFolderName(folderName) ? true : 'Folder name must be small letters, numbers, and dashes';
27
+ }
28
+ });
29
+ if (!response.projectPath)
30
+ process.exit(1);
31
+ const targetDir = path.resolve(process.cwd(), response.projectPath);
32
+ const relativePath = path.relative(process.cwd(), targetDir) || '.';
33
+ const appName = response.projectPath === '.' ? path.basename(process.cwd()) : path.basename(targetDir);
34
+ if (!isDirEmpty(targetDir)) {
35
+ console.error(chalk.red(`Directory "${response.projectPath}" is not empty.`));
36
+ process.exit(1);
37
+ }
38
+ const templateData = { APP_NAME: appName, RELATIVE_PATH: relativePath };
39
+ // Format and Log Welcome Message
40
+ console.log(`\n${formatMessage(template.data.welcomeMessage, templateData)}`);
41
+ const spinner = ora('Setting up project...').start();
42
+ try {
43
+ const emitter = degit(template.data.repository, { force: true });
44
+ await emitter.clone(targetDir);
45
+ spinner.succeed(chalk.green('Done!'));
46
+ // Format and Log Next Steps
47
+ console.log(`\n${chalk.bold('Next steps:')}`);
48
+ console.log(formatMessage(template.data.nextSteps, templateData));
49
+ process.exit(0);
50
+ }
51
+ catch (err) {
52
+ spinner.fail(chalk.red('Setup failed.'));
53
+ process.exit(1);
54
+ }
55
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import fs from 'fs-extra';
2
+ import chalk from 'chalk';
3
+ export function isValidProjectPath(input) {
4
+ return /^[a-z0-9-./\\]+$/.test(input);
5
+ }
6
+ export function isValidFolderName(name) {
7
+ return /^[a-z0-9-]+$/.test(name);
8
+ }
9
+ export function isDirEmpty(path) {
10
+ return !fs.existsSync(path) || fs.readdirSync(path).length === 0;
11
+ }
12
+ export function formatMessage(message, data) {
13
+ // 1. Replace Placeholders
14
+ let formatted = message
15
+ .replace(/{{APP_NAME}}/g, data.APP_NAME)
16
+ .replace(/{{RELATIVE_PATH}}/g, data.RELATIVE_PATH);
17
+ // 2. Replace [color] tags using Regex
18
+ // Matches [colorName]content[/colorName]
19
+ const colorRegex = /\[(\w+)\]([\s\S]*?)\[\/\1\]/g;
20
+ return formatted.replace(colorRegex, (_, color, content) => {
21
+ const chalkMethod = chalk[color];
22
+ return typeof chalkMethod === 'function' ? chalkMethod(content) : content;
23
+ });
24
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "devfast",
3
+ "version": "1.0.0",
4
+ "description": "Devfast template setup library",
5
+ "type": "module",
6
+ "main": "dist/src/api.js",
7
+ "bin": {
8
+ "devfast": "dist/bin/cli.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "type-check": "tsc --noEmit",
16
+ "dev": "NODE_ENV=development node dist/bin/cli.js",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "dependencies": {
20
+ "axios": "^1.13.6",
21
+ "chalk": "^5.6.2",
22
+ "commander": "^14.0.3",
23
+ "degit": "^2.8.4",
24
+ "fs-extra": "^11.3.4",
25
+ "ora": "^9.3.0",
26
+ "prompts": "^2.4.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/degit": "^2.8.6",
30
+ "@types/fs-extra": "^11.0.4",
31
+ "@types/node": "^25.5.0",
32
+ "@types/prompts": "^2.4.9",
33
+ "typescript": "^5.9.3"
34
+ }
35
+ }