@walruswebdev/daily-devhabit-cli 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lauren Bridges
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # daily-devhabit-cli
2
+ Package for Daily Dev Habit CLI Tool
package/dist/index.js ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const inquirer_1 = __importDefault(require("inquirer"));
9
+ const axios_1 = __importDefault(require("axios"));
10
+ const conf_1 = __importDefault(require("conf"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const fs_1 = __importDefault(require("fs"));
13
+ // 1. Initialize Configuration Store (Saves to user's computer)
14
+ const config = new conf_1.default({ projectName: 'daily-devhabit-cli' });
15
+ const program = new commander_1.Command();
16
+ // 2. DEFINE THE CONNECTION
17
+ const DEFAULT_API_URL = 'https://ddh-core-production.up.railway.app';
18
+ const API_URL = process.env.API_URL || DEFAULT_API_URL;
19
+ program
20
+ .version('1.1.0')
21
+ .description('Daily Dev Habit: Engineering Intelligence CLI');
22
+ // --- COMMAND: LOGIN ---
23
+ program
24
+ .command('login')
25
+ .description('Log in to your DDH account')
26
+ .action(async () => {
27
+ console.log(`šŸ”Œ Connecting to ${API_URL}...`);
28
+ const credentials = await inquirer_1.default.prompt([
29
+ { type: 'input', name: 'email', message: 'Email:' },
30
+ { type: 'password', name: 'password', message: 'Password:' }
31
+ ]);
32
+ try {
33
+ const response = await axios_1.default.post(`${API_URL}/auth/login`, credentials);
34
+ const token = response.data.token;
35
+ // Save Token and User Info to global config
36
+ config.set('auth.token', token);
37
+ config.set('auth.email', credentials.email);
38
+ console.log('āœ… Login Successful! Token saved locally.');
39
+ }
40
+ catch (error) {
41
+ console.error('āŒ Login Failed:', error.response?.data?.message || error.message);
42
+ }
43
+ });
44
+ // --- COMMAND: REGISTER ---
45
+ program
46
+ .command('register')
47
+ .description('Create a new DDH account')
48
+ .action(async () => {
49
+ console.log(`šŸ”Œ Connecting to ${API_URL}...`);
50
+ const data = await inquirer_1.default.prompt([
51
+ { type: 'input', name: 'email', message: 'Email:' },
52
+ { type: 'password', name: 'password', message: 'Password:' }
53
+ ]);
54
+ try {
55
+ await axios_1.default.post(`${API_URL}/auth/register`, data);
56
+ console.log('āœ… Account Created! Please run "ddh login" to sign in.');
57
+ }
58
+ catch (error) {
59
+ console.error('āŒ Registration Failed:', error.response?.data?.message || error.message);
60
+ }
61
+ });
62
+ // --- COMMAND: LOG (The Main Event) ---
63
+ program
64
+ .command('log')
65
+ .alias('l')
66
+ .description('Create a new engineering log entry')
67
+ .action(async () => {
68
+ // 1. Get Token from Config (or Env as backup)
69
+ const token = config.get('auth.token') || process.env.DEV_CLI_TOKEN;
70
+ if (!token) {
71
+ console.log('āŒ You are not logged in. Please run: ddh login');
72
+ // We don't return here because you might want to log offline even if logged out
73
+ }
74
+ // 2. Interactive Prompt
75
+ const answers = await inquirer_1.default.prompt([
76
+ {
77
+ type: 'list',
78
+ name: 'scope',
79
+ message: 'What is the scope of this work?',
80
+ choices: ['api', 'cli', 'database', 'docker', 'auth', 'refactor', 'docs', 'feature']
81
+ },
82
+ {
83
+ type: 'input',
84
+ name: 'content',
85
+ message: 'Short Summary (What did you do?):',
86
+ validate: (input) => input ? true : 'Summary cannot be empty.'
87
+ },
88
+ {
89
+ type: 'input',
90
+ name: 'decision',
91
+ message: 'Key Decision (Optional):',
92
+ },
93
+ {
94
+ type: 'input',
95
+ name: 'rationale',
96
+ message: 'Rationale (Why? Optional):',
97
+ when: (answers) => answers.decision
98
+ },
99
+ {
100
+ type: 'input',
101
+ name: 'friction',
102
+ message: 'Friction/Blockers (Optional):',
103
+ },
104
+ {
105
+ type: 'input',
106
+ name: 'tags',
107
+ message: 'Tags (comma separated):'
108
+ }
109
+ ]);
110
+ const payload = {
111
+ ...answers,
112
+ tags: answers.tags ? answers.tags.split(',').map((t) => t.trim()) : [],
113
+ origin: 'cli'
114
+ };
115
+ try {
116
+ // 3. Try to Send to API
117
+ if (!token) {
118
+ throw new Error('No token available (Login required for Cloud Sync).');
119
+ }
120
+ const response = await axios_1.default.post(`${API_URL}/entries`, payload, {
121
+ headers: { Authorization: `Bearer ${token}` }
122
+ });
123
+ console.log(`\nāœ… Log Saved! (ID: ${response.data.id})`);
124
+ console.log(` Stored in: Cloud Database (${API_URL})`);
125
+ }
126
+ catch (error) {
127
+ // 4. FALLBACK: Handle Offline State
128
+ const isOffline = error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND';
129
+ const isAuthError = !token || (error.response && error.response.status === 401);
130
+ if (isOffline || isAuthError) {
131
+ console.log('\nāš ļø Could not sync to Cloud. Switching to Local Backup...');
132
+ // Format for Markdown
133
+ const timestamp = new Date().toISOString();
134
+ const backupEntry = `
135
+ ## [OFFLINE] ${timestamp}
136
+ - **Scope:** ${payload.scope}
137
+ - **Content:** ${payload.content}
138
+ - **Decision:** ${payload.decision || 'N/A'}
139
+ - **Rationale:** ${payload.rationale || 'N/A'}
140
+ - **Friction:** ${payload.friction || 'N/A'}
141
+ - **Tags:** ${payload.tags.join(', ')}
142
+ ---
143
+ `;
144
+ // Append to OFFLINE_LOGS.md in project root
145
+ // We use process.cwd() to find the user's current project folder, not the CLI's folder
146
+ const backupPath = path_1.default.join(process.cwd(), 'OFFLINE_LOGS.md');
147
+ fs_1.default.appendFileSync(backupPath, backupEntry);
148
+ console.log(`āœ… Log saved locally to: ${backupPath}`);
149
+ if (isAuthError)
150
+ console.log('šŸ‘‰ Reason: You are not logged in.');
151
+ if (isOffline)
152
+ console.log('šŸ‘‰ Reason: Server is unreachable.');
153
+ }
154
+ else {
155
+ // Real Error (e.g. 500 Server Error)
156
+ console.error('āŒ Error:', error.response?.data?.message || error.message);
157
+ }
158
+ }
159
+ });
160
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@walruswebdev/daily-devhabit-cli",
3
+ "version": "1.0.0",
4
+ "description": "Package for Daily Dev Habit CLI Tool",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "ddh": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/walrusWebDev/daily-devhabit-cli.git"
19
+ },
20
+ "keywords": ["cli", "journal", "developer-tools"],
21
+ "author": "Lauren Bridges",
22
+ "license": "ISC",
23
+ "type": "commonjs",
24
+ "bugs": {
25
+ "url": "https://github.com/walrusWebDev/daily-devhabit-cli/issues"
26
+ },
27
+ "homepage": "https://github.com/walrusWebDev/daily-devhabit-cli#readme",
28
+ "dependencies": {
29
+ "axios": "^1.7.9",
30
+ "commander": "^12.0.0",
31
+ "conf": "^9.0.2",
32
+ "dotenv": "^16.4.7",
33
+ "inquirer": "^8.2.6"
34
+ },
35
+ "devDependencies": {
36
+ "@types/inquirer": "^9.0.9",
37
+ "@types/node": "^25.0.3",
38
+ "typescript": "^5.9.3"
39
+ }
40
+ }