claudeguide-engineer 1.15.0 → 1.16.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.
Files changed (2) hide show
  1. package/index.js +90 -46
  2. package/package.json +7 -1
package/index.js CHANGED
@@ -3,61 +3,75 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const { execSync } = require('child_process');
6
+ const os = require('os');
6
7
 
7
- const args = process.argv.slice(2);
8
- const command = args[0];
8
+ // Professional CLI dependencies
9
+ const chalk = require('chalk');
10
+ const ora = require('ora');
11
+ const inquirer = require('inquirer');
12
+ const { program } = require('commander');
9
13
 
10
- // Cấu hình Repo Private của bạn
14
+ // Configuration
11
15
  const PRIVATE_REPO_URL = "https://github.com/nstung463/claude-guide.git";
12
-
13
- if (!command || command === '--help' || command === '-h') {
14
- console.log(`
15
- Usage: cg <command>
16
-
17
- Commands:
18
- init, new Initialize a new project with ClaudeGuide Engineer Kit
19
- update Update the kit from the private repository
20
- version, -v Show version
21
- help, -h Show this help
22
- `);
23
- process.exit(0);
16
+ const CONFIG_FILE = path.join(os.homedir(), '.claudeguide-config.json');
17
+
18
+ /**
19
+ * Load or save GitHub Token
20
+ */
21
+ function getSavedToken() {
22
+ if (fs.existsSync(CONFIG_FILE)) {
23
+ try {
24
+ const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
25
+ return config.GITHUB_TOKEN;
26
+ } catch (e) {
27
+ return null;
28
+ }
29
+ }
30
+ return null;
24
31
  }
25
32
 
26
- if (command === 'version' || command === '-v') {
27
- const pkg = require('./package.json');
28
- console.log(`claudeguide-engineer CLI v${pkg.version}`);
29
- process.exit(0);
33
+ function saveToken(token) {
34
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify({ GITHUB_TOKEN: token }, null, 2));
30
35
  }
31
36
 
32
- if (command === 'init' || command === 'new' || command === 'update') {
33
- console.log('🚀 Checking access to ClaudeGuide Private Kit...');
34
-
35
- // Lấy Token từ môi trường hoặc yêu cầu người dùng
36
- const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
37
-
38
- if (!GITHUB_TOKEN) {
39
- console.error('❌ Lỗi: Không tìm thấy GITHUB_TOKEN.');
40
- console.log('\nHướng dẫn:');
41
- console.log('1. Tạo Personal Access Token (PAT) tại: https://github.com/settings/tokens');
42
- console.log('2. quyền "repo" (để truy cập private repo).');
43
- console.log('3. Chạy lệnh: export GITHUB_TOKEN=your_token (Linux/macOS) hoặc set GITHUB_TOKEN=your_token (Windows)');
44
- console.log('4. Thử lại lệnh "cg init".');
45
- process.exit(1);
37
+ /**
38
+ * Main Initialization Logic
39
+ */
40
+ async function initializeKit(options) {
41
+ console.log(chalk.cyan.bold('\n🚀 ClaudeGuide Engineer Kit Initializer\n'));
42
+
43
+ let token = process.env.GITHUB_TOKEN || getSavedToken();
44
+
45
+ // Prompt for token if missing
46
+ if (!token) {
47
+ console.log(chalk.yellow('💡 No GitHub Token found. You need a Personal Access Token (PAT) with "repo" scope.'));
48
+ const answers = await inquirer.prompt([
49
+ {
50
+ type: 'password',
51
+ name: 'token',
52
+ message: 'Enter your GitHub Personal Access Token:',
53
+ validate: (input) => input.length > 0 || 'Token is required'
54
+ }
55
+ ]);
56
+ token = answers.token;
57
+ saveToken(token);
58
+ console.log(chalk.green('✅ Token saved to ' + CONFIG_FILE + '\n'));
46
59
  }
47
60
 
61
+ const spinner = ora('Checking access to Private Kit...').start();
48
62
  const targetDir = process.cwd();
49
63
  const tempDir = path.join(targetDir, '.cg-temp-' + Date.now());
50
64
 
51
65
  try {
52
- // Thử clone bằng token
53
- console.log('🔑 Authenticating with GitHub...');
54
- const authRepoUrl = PRIVATE_REPO_URL.replace("https://", `https://${GITHUB_TOKEN}@`);
66
+ // Authenticate and Clone
67
+ const authRepoUrl = PRIVATE_REPO_URL.replace("https://", `https://${token}@`);
55
68
 
69
+ spinner.text = 'Authenticating and downloading from GitHub...';
56
70
  execSync(`git clone --depth 1 ${authRepoUrl} "${tempDir}"`, { stdio: 'ignore' });
57
71
 
58
- console.log('Access Granted! Initializing files...');
72
+ spinner.succeed(chalk.green('Access Granted! Repository downloaded.'));
73
+ spinner.start('Initializing files in ' + targetDir + '...');
59
74
 
60
- // Danh sách các file/folder cần lấy từ repo private
61
75
  const filesToCopy = [
62
76
  ".claude",
63
77
  ".opencode",
@@ -81,26 +95,56 @@ if (command === 'init' || command === 'new' || command === 'update') {
81
95
  } else {
82
96
  fs.copyFileSync(src, dest);
83
97
  }
84
- console.log(` ➕ Added: ${file}`);
85
98
  }
86
99
  });
87
100
 
88
- // Dọn dẹp thư mục tạm
101
+ spinner.succeed(chalk.green('Files initialized successfully.'));
102
+
103
+ // Clean up
89
104
  fs.rmSync(tempDir, { recursive: true, force: true });
90
105
 
91
- console.log('\n✨ Done! Project initialized successfully.');
92
- console.log('\nNext steps:');
93
- console.log('1. Run "npm install"');
94
- console.log('2. Type "claude" to start building.');
106
+ console.log(chalk.blue.bold('\n✨ All set! ClaudeGuide is ready.'));
107
+ console.log(chalk.white('\nNext steps:'));
108
+ console.log(chalk.gray(' 1. ') + chalk.white('Run ') + chalk.cyan('npm install'));
109
+ console.log(chalk.gray(' 2. ') + chalk.white('Type ') + chalk.cyan('claude') + chalk.white(' to start building.\n'));
95
110
 
96
111
  } catch (err) {
97
- console.error('Access Denied: Bạn không có quyền truy cập bộ Kit này.');
98
- console.error(' Hãy đảm bảo Token của bạn có quyền "repo" và bạn đã được mời vào repo.');
112
+ spinner.fail(chalk.red('Access Denied or Connection Error.'));
113
+ console.error(chalk.red('\nError Details: ') + chalk.white(err.message));
114
+ console.log(chalk.yellow('\nTips:'));
115
+ console.log(' - Ensure your PAT has "repo" scope.');
116
+ console.log(' - Ensure you are a contributor to ' + PRIVATE_REPO_URL);
117
+ console.log(' - To reset your token, delete ' + CONFIG_FILE);
118
+
99
119
  if (fs.existsSync(tempDir)) fs.rmSync(tempDir, { recursive: true, force: true });
100
120
  process.exit(1);
101
121
  }
102
122
  }
103
123
 
124
+ /**
125
+ * CLI Configuration
126
+ */
127
+ program
128
+ .name('cg')
129
+ .description('CLI tool for ClaudeGuide AI Agent Framework')
130
+ .version(require('./package.json').version, '-v, --version');
131
+
132
+ program
133
+ .command('init')
134
+ .alias('new')
135
+ .description('Initialize a new project with the Engineer Kit')
136
+ .action(initializeKit);
137
+
138
+ program
139
+ .command('update')
140
+ .description('Update the framework files from the private repository')
141
+ .action(initializeKit);
142
+
143
+ program.parse(process.argv);
144
+
145
+ /**
146
+ * Helper: Recursive Copy
147
+ */
104
148
  function copyRecursiveSync(src, dest) {
105
149
  if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
106
150
  fs.readdirSync(src).forEach(childItemName => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudeguide-engineer",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "A comprehensive boilerplate template for building professional software projects with CLI Coding Agents (Claude Code and Open Code).",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -35,6 +35,12 @@
35
35
  "LICENSE",
36
36
  ".claude/metadata.json"
37
37
  ],
38
+ "dependencies": {
39
+ "chalk": "^4.1.2",
40
+ "ora": "^5.4.1",
41
+ "inquirer": "^8.2.4",
42
+ "commander": "^9.4.1"
43
+ },
38
44
  "devDependencies": {
39
45
  "@commitlint/cli": "^18.4.3",
40
46
  "@commitlint/config-conventional": "^18.4.3",