claude-code-wakatime 2.1.3 → 3.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/.claude-plugin/marketplace.json +25 -0
- package/.claude-plugin/plugin.json +17 -0
- package/README.md +58 -11
- package/dist/index.js +41704 -119
- package/hooks/hooks.json +92 -0
- package/package.json +12 -13
- package/src/dependencies.ts +2 -2
- package/src/index.ts +91 -10
- package/src/install-hooks.ts +10 -1
- package/dist/dependencies.js +0 -416
- package/dist/install-hooks.js +0 -53
- package/dist/logger.js +0 -74
- package/dist/options.js +0 -214
- package/dist/utils.js +0 -129
- package/dist/version.js +0 -5
package/dist/options.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Options = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const utils_1 = require("./utils");
|
|
40
|
-
class Options {
|
|
41
|
-
constructor() {
|
|
42
|
-
const home = utils_1.Utils.getHomeDirectory();
|
|
43
|
-
const wakaFolder = path.join(home, '.wakatime');
|
|
44
|
-
try {
|
|
45
|
-
if (!fs.existsSync(wakaFolder)) {
|
|
46
|
-
fs.mkdirSync(wakaFolder, { recursive: true });
|
|
47
|
-
}
|
|
48
|
-
this.resourcesLocation = wakaFolder;
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
console.error(e);
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
this.configFile = path.join(home, '.wakatime.cfg');
|
|
55
|
-
this.internalConfigFile = path.join(this.resourcesLocation, 'wakatime-internal.cfg');
|
|
56
|
-
this.logFile = path.join(this.resourcesLocation, 'wakatime.log');
|
|
57
|
-
}
|
|
58
|
-
getSetting(section, key, internal) {
|
|
59
|
-
const content = fs.readFileSync(this.getConfigFile(internal ?? false), 'utf-8');
|
|
60
|
-
if (content.trim()) {
|
|
61
|
-
let currentSection = '';
|
|
62
|
-
let lines = content.split('\n');
|
|
63
|
-
for (var i = 0; i < lines.length; i++) {
|
|
64
|
-
let line = lines[i];
|
|
65
|
-
if (this.startsWith(line.trim(), '[') && this.endsWith(line.trim(), ']')) {
|
|
66
|
-
currentSection = line
|
|
67
|
-
.trim()
|
|
68
|
-
.substring(1, line.trim().length - 1)
|
|
69
|
-
.toLowerCase();
|
|
70
|
-
}
|
|
71
|
-
else if (currentSection === section) {
|
|
72
|
-
let parts = line.split('=');
|
|
73
|
-
let currentKey = parts[0].trim();
|
|
74
|
-
if (currentKey === key && parts.length > 1) {
|
|
75
|
-
return this.removeNulls(parts[1].trim());
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
setSetting(section, key, val, internal) {
|
|
83
|
-
const configFile = this.getConfigFile(internal);
|
|
84
|
-
fs.readFile(configFile, 'utf-8', (err, content) => {
|
|
85
|
-
// ignore errors because config file might not exist yet
|
|
86
|
-
if (err)
|
|
87
|
-
content = '';
|
|
88
|
-
let contents = [];
|
|
89
|
-
let currentSection = '';
|
|
90
|
-
let found = false;
|
|
91
|
-
let lines = content.split('\n');
|
|
92
|
-
for (var i = 0; i < lines.length; i++) {
|
|
93
|
-
let line = lines[i];
|
|
94
|
-
if (this.startsWith(line.trim(), '[') && this.endsWith(line.trim(), ']')) {
|
|
95
|
-
if (currentSection === section && !found) {
|
|
96
|
-
contents.push(this.removeNulls(key + ' = ' + val));
|
|
97
|
-
found = true;
|
|
98
|
-
}
|
|
99
|
-
currentSection = line
|
|
100
|
-
.trim()
|
|
101
|
-
.substring(1, line.trim().length - 1)
|
|
102
|
-
.toLowerCase();
|
|
103
|
-
contents.push(this.removeNulls(line));
|
|
104
|
-
}
|
|
105
|
-
else if (currentSection === section) {
|
|
106
|
-
let parts = line.split('=');
|
|
107
|
-
let currentKey = parts[0].trim();
|
|
108
|
-
if (currentKey === key) {
|
|
109
|
-
if (!found) {
|
|
110
|
-
contents.push(this.removeNulls(key + ' = ' + val));
|
|
111
|
-
found = true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
contents.push(this.removeNulls(line));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
contents.push(this.removeNulls(line));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (!found) {
|
|
123
|
-
if (currentSection !== section) {
|
|
124
|
-
contents.push('[' + section + ']');
|
|
125
|
-
}
|
|
126
|
-
contents.push(this.removeNulls(key + ' = ' + val));
|
|
127
|
-
}
|
|
128
|
-
fs.writeFile(configFile, contents.join('\n'), (err) => {
|
|
129
|
-
if (err)
|
|
130
|
-
throw err;
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
setSettings(section, settings, internal) {
|
|
135
|
-
const configFile = this.getConfigFile(internal);
|
|
136
|
-
fs.readFile(configFile, 'utf-8', (err, content) => {
|
|
137
|
-
// ignore errors because config file might not exist yet
|
|
138
|
-
if (err)
|
|
139
|
-
content = '';
|
|
140
|
-
let contents = [];
|
|
141
|
-
let currentSection = '';
|
|
142
|
-
const found = {};
|
|
143
|
-
let lines = content.split('\n');
|
|
144
|
-
for (var i = 0; i < lines.length; i++) {
|
|
145
|
-
let line = lines[i];
|
|
146
|
-
if (this.startsWith(line.trim(), '[') && this.endsWith(line.trim(), ']')) {
|
|
147
|
-
if (currentSection === section) {
|
|
148
|
-
settings.forEach((setting) => {
|
|
149
|
-
if (!found[setting.key]) {
|
|
150
|
-
contents.push(this.removeNulls(setting.key + ' = ' + setting.value));
|
|
151
|
-
found[setting.key] = true;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
currentSection = line
|
|
156
|
-
.trim()
|
|
157
|
-
.substring(1, line.trim().length - 1)
|
|
158
|
-
.toLowerCase();
|
|
159
|
-
contents.push(this.removeNulls(line));
|
|
160
|
-
}
|
|
161
|
-
else if (currentSection === section) {
|
|
162
|
-
let parts = line.split('=');
|
|
163
|
-
let currentKey = parts[0].trim();
|
|
164
|
-
let keepLineUnchanged = true;
|
|
165
|
-
settings.forEach((setting) => {
|
|
166
|
-
if (currentKey === setting.key) {
|
|
167
|
-
keepLineUnchanged = false;
|
|
168
|
-
if (!found[setting.key]) {
|
|
169
|
-
contents.push(this.removeNulls(setting.key + ' = ' + setting.value));
|
|
170
|
-
found[setting.key] = true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
if (keepLineUnchanged) {
|
|
175
|
-
contents.push(this.removeNulls(line));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
contents.push(this.removeNulls(line));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
settings.forEach((setting) => {
|
|
183
|
-
if (!found[setting.key]) {
|
|
184
|
-
if (currentSection !== section) {
|
|
185
|
-
contents.push('[' + section + ']');
|
|
186
|
-
currentSection = section;
|
|
187
|
-
}
|
|
188
|
-
contents.push(this.removeNulls(setting.key + ' = ' + setting.value));
|
|
189
|
-
found[setting.key] = true;
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
fs.writeFile(configFile, contents.join('\n'), (err) => {
|
|
193
|
-
if (err)
|
|
194
|
-
throw err;
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
getConfigFile(internal) {
|
|
199
|
-
return internal ? this.internalConfigFile : this.configFile;
|
|
200
|
-
}
|
|
201
|
-
getLogFile() {
|
|
202
|
-
return this.logFile;
|
|
203
|
-
}
|
|
204
|
-
startsWith(outer, inner) {
|
|
205
|
-
return outer.slice(0, inner.length) === inner;
|
|
206
|
-
}
|
|
207
|
-
endsWith(outer, inner) {
|
|
208
|
-
return inner === '' || outer.slice(-inner.length) === inner;
|
|
209
|
-
}
|
|
210
|
-
removeNulls(s) {
|
|
211
|
-
return s.replace(/\0/g, '');
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
exports.Options = Options;
|
package/dist/utils.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Utils = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const os = __importStar(require("os"));
|
|
39
|
-
class Utils {
|
|
40
|
-
static quote(str) {
|
|
41
|
-
if (str.includes(' '))
|
|
42
|
-
return `"${str.replace('"', '\\"')}"`;
|
|
43
|
-
return str;
|
|
44
|
-
}
|
|
45
|
-
static apiKeyInvalid(key) {
|
|
46
|
-
const err = 'Invalid api key... check https://wakatime.com/api-key for your key';
|
|
47
|
-
if (!key)
|
|
48
|
-
return err;
|
|
49
|
-
const re = new RegExp('^(waka_)?[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$', 'i');
|
|
50
|
-
if (!re.test(key))
|
|
51
|
-
return err;
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
static formatDate(date) {
|
|
55
|
-
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
56
|
-
let ampm = 'AM';
|
|
57
|
-
let hour = date.getHours();
|
|
58
|
-
if (hour > 11) {
|
|
59
|
-
ampm = 'PM';
|
|
60
|
-
hour = hour - 12;
|
|
61
|
-
}
|
|
62
|
-
if (hour == 0) {
|
|
63
|
-
hour = 12;
|
|
64
|
-
}
|
|
65
|
-
let minute = date.getMinutes();
|
|
66
|
-
return `${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()} ${hour}:${minute < 10 ? `0${minute}` : minute} ${ampm}`;
|
|
67
|
-
}
|
|
68
|
-
static obfuscateKey(key) {
|
|
69
|
-
let newKey = '';
|
|
70
|
-
if (key) {
|
|
71
|
-
newKey = key;
|
|
72
|
-
if (key.length > 4)
|
|
73
|
-
newKey = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX' + key.substring(key.length - 4);
|
|
74
|
-
}
|
|
75
|
-
return newKey;
|
|
76
|
-
}
|
|
77
|
-
static wrapArg(arg) {
|
|
78
|
-
if (arg.indexOf(' ') > -1)
|
|
79
|
-
return '"' + arg.replace(/"/g, '\\"') + '"';
|
|
80
|
-
return arg;
|
|
81
|
-
}
|
|
82
|
-
static formatArguments(binary, args) {
|
|
83
|
-
let clone = args.slice(0);
|
|
84
|
-
clone.unshift(this.wrapArg(binary));
|
|
85
|
-
let newCmds = [];
|
|
86
|
-
let lastCmd = '';
|
|
87
|
-
for (let i = 0; i < clone.length; i++) {
|
|
88
|
-
if (lastCmd == '--key')
|
|
89
|
-
newCmds.push(this.wrapArg(this.obfuscateKey(clone[i])));
|
|
90
|
-
else
|
|
91
|
-
newCmds.push(this.wrapArg(clone[i]));
|
|
92
|
-
lastCmd = clone[i];
|
|
93
|
-
}
|
|
94
|
-
return newCmds.join(' ');
|
|
95
|
-
}
|
|
96
|
-
static apiUrlToDashboardUrl(url) {
|
|
97
|
-
url = url
|
|
98
|
-
.replace('://api.', '://')
|
|
99
|
-
.replace('/api/v1', '')
|
|
100
|
-
.replace(/^api\./, '')
|
|
101
|
-
.replace('/api', '');
|
|
102
|
-
return url;
|
|
103
|
-
}
|
|
104
|
-
static isWindows() {
|
|
105
|
-
return os.platform() === 'win32';
|
|
106
|
-
}
|
|
107
|
-
static getHomeDirectory() {
|
|
108
|
-
let home = process.env.WAKATIME_HOME;
|
|
109
|
-
if (home && home.trim() && fs.existsSync(home.trim()))
|
|
110
|
-
return home.trim();
|
|
111
|
-
return process.env[this.isWindows() ? 'USERPROFILE' : 'HOME'] || process.cwd();
|
|
112
|
-
}
|
|
113
|
-
static buildOptions(stdin) {
|
|
114
|
-
const options = {
|
|
115
|
-
windowsHide: true,
|
|
116
|
-
};
|
|
117
|
-
if (stdin) {
|
|
118
|
-
options.stdio = ['pipe', 'pipe', 'pipe'];
|
|
119
|
-
}
|
|
120
|
-
if (!this.isWindows() && !process.env.WAKATIME_HOME && !process.env.HOME) {
|
|
121
|
-
options['env'] = { ...process.env, WAKATIME_HOME: this.getHomeDirectory() };
|
|
122
|
-
}
|
|
123
|
-
return options;
|
|
124
|
-
}
|
|
125
|
-
static timestamp() {
|
|
126
|
-
return Date.now() / 1000;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.Utils = Utils;
|