@fredlackey/devutils 0.0.19 → 0.1.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 +223 -32
- package/package.json +7 -5
- package/src/api/loader.js +229 -0
- package/src/api/registry.json +62 -0
- package/src/cli.js +305 -0
- package/src/commands/ai/index.js +16 -0
- package/src/commands/ai/launch.js +112 -0
- package/src/commands/ai/list.js +54 -0
- package/src/commands/ai/resume.js +70 -0
- package/src/commands/ai/sessions.js +121 -0
- package/src/commands/ai/set.js +131 -0
- package/src/commands/ai/show.js +74 -0
- package/src/commands/ai/tools.js +46 -0
- package/src/commands/alias/add.js +93 -0
- package/src/commands/alias/helpers.js +107 -0
- package/src/commands/alias/index.js +14 -0
- package/src/commands/alias/list.js +55 -0
- package/src/commands/alias/remove.js +62 -0
- package/src/commands/alias/sync.js +109 -0
- package/src/commands/api/disable.js +73 -0
- package/src/commands/api/enable.js +148 -0
- package/src/commands/api/index.js +15 -0
- package/src/commands/api/list.js +66 -0
- package/src/commands/api/update.js +87 -0
- package/src/commands/auth/index.js +15 -0
- package/src/commands/auth/list.js +49 -0
- package/src/commands/auth/login.js +384 -0
- package/src/commands/auth/logout.js +111 -0
- package/src/commands/auth/refresh.js +184 -0
- package/src/commands/auth/services.js +169 -0
- package/src/commands/auth/status.js +104 -0
- package/src/commands/config/export.js +224 -0
- package/src/commands/config/get.js +52 -0
- package/src/commands/config/import.js +308 -0
- package/src/commands/config/index.js +17 -0
- package/src/commands/config/init.js +143 -0
- package/src/commands/config/reset.js +57 -0
- package/src/commands/config/set.js +93 -0
- package/src/commands/config/show.js +35 -0
- package/src/commands/help.js +338 -0
- package/src/commands/identity/add.js +133 -0
- package/src/commands/identity/index.js +17 -0
- package/src/commands/identity/link.js +76 -0
- package/src/commands/identity/list.js +48 -0
- package/src/commands/identity/remove.js +72 -0
- package/src/commands/identity/show.js +65 -0
- package/src/commands/identity/sync.js +172 -0
- package/src/commands/identity/unlink.js +57 -0
- package/src/commands/ignore/add.js +165 -0
- package/src/commands/ignore/index.js +14 -0
- package/src/commands/ignore/list.js +89 -0
- package/src/commands/ignore/markers.js +43 -0
- package/src/commands/ignore/remove.js +164 -0
- package/src/commands/ignore/show.js +169 -0
- package/src/commands/machine/detect.js +122 -0
- package/src/commands/machine/index.js +14 -0
- package/src/commands/machine/list.js +74 -0
- package/src/commands/machine/set.js +106 -0
- package/src/commands/machine/show.js +35 -0
- package/src/commands/schema.js +152 -0
- package/src/commands/search/collections.js +134 -0
- package/src/commands/search/get.js +71 -0
- package/src/commands/search/index-cmd.js +54 -0
- package/src/commands/search/index.js +21 -0
- package/src/commands/search/keyword.js +60 -0
- package/src/commands/search/qmd.js +70 -0
- package/src/commands/search/query.js +64 -0
- package/src/commands/search/semantic.js +62 -0
- package/src/commands/search/status.js +46 -0
- package/src/commands/status.js +276 -0
- package/src/commands/tools/check.js +79 -0
- package/src/commands/tools/index.js +14 -0
- package/src/commands/tools/install.js +110 -0
- package/src/commands/tools/list.js +91 -0
- package/src/commands/tools/search.js +60 -0
- package/src/commands/update.js +113 -0
- package/src/commands/util/add.js +151 -0
- package/src/commands/util/index.js +15 -0
- package/src/commands/util/list.js +97 -0
- package/src/commands/util/remove.js +76 -0
- package/src/commands/util/run.js +79 -0
- package/src/commands/util/show.js +67 -0
- package/src/commands/version.js +33 -0
- package/src/installers/_template.js +104 -0
- package/src/installers/git.js +150 -0
- package/src/installers/homebrew.js +190 -0
- package/src/installers/node.js +223 -0
- package/src/installers/registry.json +29 -0
- package/src/lib/config.js +125 -0
- package/src/lib/detect.js +74 -0
- package/src/lib/errors.js +114 -0
- package/src/lib/github.js +315 -0
- package/src/lib/installer.js +225 -0
- package/src/lib/output.js +239 -0
- package/src/lib/platform.js +112 -0
- package/src/lib/platforms/amazon-linux.js +41 -0
- package/src/lib/platforms/gitbash.js +46 -0
- package/src/lib/platforms/macos.js +45 -0
- package/src/lib/platforms/raspbian.js +41 -0
- package/src/lib/platforms/ubuntu.js +39 -0
- package/src/lib/platforms/windows.js +45 -0
- package/src/lib/prompt.js +161 -0
- package/src/lib/schema.js +211 -0
- package/src/lib/shell.js +75 -0
- package/src/patterns/gitignore/claude-code.txt +25 -0
- package/src/patterns/gitignore/docker.txt +15 -0
- package/src/patterns/gitignore/go.txt +24 -0
- package/src/patterns/gitignore/java.txt +38 -0
- package/src/patterns/gitignore/jetbrains.txt +26 -0
- package/src/patterns/gitignore/linux.txt +18 -0
- package/src/patterns/gitignore/macos.txt +27 -0
- package/src/patterns/gitignore/node.txt +51 -0
- package/src/patterns/gitignore/python.txt +55 -0
- package/src/patterns/gitignore/rust.txt +14 -0
- package/src/patterns/gitignore/terraform.txt +30 -0
- package/src/patterns/gitignore/vscode.txt +15 -0
- package/src/patterns/gitignore/windows.txt +25 -0
- package/src/utils/clone/index.js +165 -0
- package/src/utils/git-push/index.js +230 -0
- package/src/utils/git-status/index.js +116 -0
- package/src/utils/git-status/unix.sh +75 -0
- package/src/utils/registry.json +41 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.devutils', 'config.json');
|
|
8
|
+
|
|
9
|
+
const meta = {
|
|
10
|
+
description: 'Show details of a specific identity.',
|
|
11
|
+
arguments: [
|
|
12
|
+
{ name: 'name', description: 'Name of the identity to show', required: true },
|
|
13
|
+
],
|
|
14
|
+
flags: [],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async function run(args, context) {
|
|
18
|
+
const name = args.positional[0];
|
|
19
|
+
if (!name) {
|
|
20
|
+
context.errors.throwError(400, 'Missing identity name. Usage: dev identity show <name>', 'identity');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
25
|
+
context.errors.throwError(404, 'Config not found. Run "dev config init" first.', 'identity');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
29
|
+
const identities = config.identities || [];
|
|
30
|
+
|
|
31
|
+
const identity = identities.find(id => id.name.toLowerCase() === name.toLowerCase());
|
|
32
|
+
if (!identity) {
|
|
33
|
+
context.errors.throwError(404, `Identity '${name}' not found. Run 'dev identity list' to see available identities.`, 'identity');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// For JSON callers, output the raw object
|
|
38
|
+
if (context.flags.format === 'json') {
|
|
39
|
+
context.output.out(identity);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Formatted display for humans
|
|
44
|
+
const sshStatus = identity.sshKey
|
|
45
|
+
? `${identity.sshKey} ${fs.existsSync(identity.sshKey) ? '(exists)' : '(missing!)'}`
|
|
46
|
+
: '(not configured)';
|
|
47
|
+
const gpgStatus = identity.gpgKey || '(not configured)';
|
|
48
|
+
const folders = identity.folders || [];
|
|
49
|
+
|
|
50
|
+
context.output.info(`Identity: ${identity.name}`);
|
|
51
|
+
context.output.info('');
|
|
52
|
+
context.output.info(` Email: ${identity.email}`);
|
|
53
|
+
context.output.info(` SSH Key: ${sshStatus}`);
|
|
54
|
+
context.output.info(` GPG Key: ${gpgStatus}`);
|
|
55
|
+
context.output.info(` Linked Folders (${folders.length}):`);
|
|
56
|
+
if (folders.length === 0) {
|
|
57
|
+
context.output.info(' (none)');
|
|
58
|
+
} else {
|
|
59
|
+
for (const f of folders) {
|
|
60
|
+
context.output.info(` ${f.path || f}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { meta, run };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.devutils', 'config.json');
|
|
8
|
+
|
|
9
|
+
const SSH_START = '# >>> DevUtils Managed SSH Config - DO NOT EDIT BETWEEN MARKERS >>>';
|
|
10
|
+
const SSH_END = '# <<< DevUtils Managed SSH Config <<<';
|
|
11
|
+
const GIT_START = '# >>> DevUtils Managed Git Config - DO NOT EDIT BETWEEN MARKERS >>>';
|
|
12
|
+
const GIT_END = '# <<< DevUtils Managed Git Config <<<';
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
description: 'Regenerate SSH config and git config from identity definitions.',
|
|
16
|
+
arguments: [],
|
|
17
|
+
flags: [
|
|
18
|
+
{ name: 'dry-run', description: 'Show what would be written without making changes' },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds SSH config blocks for an identity.
|
|
24
|
+
* @param {object} identity - The identity object.
|
|
25
|
+
* @returns {string} The SSH config block text.
|
|
26
|
+
*/
|
|
27
|
+
function buildSshConfigBlock(identity) {
|
|
28
|
+
const remotes = [...new Set((identity.folders || []).map(f => f.remote || 'github.com'))];
|
|
29
|
+
const blocks = [];
|
|
30
|
+
|
|
31
|
+
for (const remote of remotes) {
|
|
32
|
+
blocks.push([
|
|
33
|
+
`# DevUtils managed - ${identity.name}`,
|
|
34
|
+
`Host ${remote}-${identity.name}`,
|
|
35
|
+
` HostName ${remote}`,
|
|
36
|
+
` User git`,
|
|
37
|
+
` IdentityFile ${identity.sshKey}`,
|
|
38
|
+
` IdentitiesOnly yes`,
|
|
39
|
+
].join('\n'));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return blocks.join('\n\n');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Updates a config file by replacing content between markers or appending.
|
|
47
|
+
* @param {string} filePath - The file to update.
|
|
48
|
+
* @param {string} startMarker - The start marker.
|
|
49
|
+
* @param {string} endMarker - The end marker.
|
|
50
|
+
* @param {string} newContent - The new content between markers.
|
|
51
|
+
* @param {boolean} dryRun - If true, don't write the file.
|
|
52
|
+
* @param {object} [writeOpts] - Options for writeFileSync (e.g., mode).
|
|
53
|
+
* @returns {string} The full file content.
|
|
54
|
+
*/
|
|
55
|
+
function updateManagedSection(filePath, startMarker, endMarker, newContent, dryRun, writeOpts = {}) {
|
|
56
|
+
let existing = '';
|
|
57
|
+
if (fs.existsSync(filePath)) {
|
|
58
|
+
existing = fs.readFileSync(filePath, 'utf8');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const startIdx = existing.indexOf(startMarker);
|
|
62
|
+
const endIdx = existing.indexOf(endMarker);
|
|
63
|
+
|
|
64
|
+
let updated;
|
|
65
|
+
if (startIdx !== -1 && endIdx !== -1) {
|
|
66
|
+
updated = existing.substring(0, startIdx) +
|
|
67
|
+
startMarker + '\n' + newContent + '\n' + endMarker +
|
|
68
|
+
existing.substring(endIdx + endMarker.length);
|
|
69
|
+
} else {
|
|
70
|
+
updated = existing.trimEnd() + '\n\n' +
|
|
71
|
+
startMarker + '\n' + newContent + '\n' + endMarker + '\n';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!dryRun) {
|
|
75
|
+
const dir = path.dirname(filePath);
|
|
76
|
+
if (!fs.existsSync(dir)) {
|
|
77
|
+
fs.mkdirSync(dir, { mode: 0o700, recursive: true });
|
|
78
|
+
}
|
|
79
|
+
fs.writeFileSync(filePath, updated, writeOpts);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return updated;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function run(args, context) {
|
|
86
|
+
const dryRun = args.flags['dry-run'] || context.flags.dryRun;
|
|
87
|
+
|
|
88
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
89
|
+
context.errors.throwError(404, 'Config not found. Run "dev config init" first.', 'identity');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
93
|
+
const identities = config.identities || [];
|
|
94
|
+
|
|
95
|
+
if (identities.length === 0) {
|
|
96
|
+
context.output.info('No identities configured. Nothing to sync.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Build SSH config
|
|
101
|
+
const sshBlocks = [];
|
|
102
|
+
for (const id of identities) {
|
|
103
|
+
if (!id.sshKey) {
|
|
104
|
+
context.output.info(`Warning: Skipping SSH config for '${id.name}' (no SSH key configured).`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if ((id.folders || []).length === 0) {
|
|
108
|
+
context.output.info(`Warning: Identity '${id.name}' has no linked folders.`);
|
|
109
|
+
}
|
|
110
|
+
sshBlocks.push(buildSshConfigBlock(id));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
|
|
114
|
+
const sshContent = sshBlocks.join('\n\n');
|
|
115
|
+
|
|
116
|
+
if (dryRun) {
|
|
117
|
+
context.output.info('=== SSH Config (dry run) ===');
|
|
118
|
+
context.output.info(sshContent || '(no SSH entries)');
|
|
119
|
+
} else if (sshContent) {
|
|
120
|
+
updateManagedSection(sshConfigPath, SSH_START, SSH_END, sshContent, false, { mode: 0o600 });
|
|
121
|
+
context.output.info(`SSH config updated: ${sshConfigPath}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Build git config includes
|
|
125
|
+
const gitConfigPath = path.join(os.homedir(), '.gitconfig');
|
|
126
|
+
const includeLines = [];
|
|
127
|
+
|
|
128
|
+
for (const id of identities) {
|
|
129
|
+
const folders = id.folders || [];
|
|
130
|
+
if (folders.length === 0) continue;
|
|
131
|
+
|
|
132
|
+
// Write per-identity gitconfig
|
|
133
|
+
const idConfigPath = path.join(os.homedir(), `.gitconfig-${id.name}`);
|
|
134
|
+
const lines = ['[user]', ` email = ${id.email}`];
|
|
135
|
+
if (id.gpgKey) {
|
|
136
|
+
lines.push(` signingkey = ${id.gpgKey}`);
|
|
137
|
+
lines.push('[commit]');
|
|
138
|
+
lines.push(' gpgsign = true');
|
|
139
|
+
}
|
|
140
|
+
const idContent = lines.join('\n') + '\n';
|
|
141
|
+
|
|
142
|
+
if (dryRun) {
|
|
143
|
+
context.output.info(`\n=== ${idConfigPath} (dry run) ===`);
|
|
144
|
+
context.output.info(idContent);
|
|
145
|
+
} else {
|
|
146
|
+
fs.writeFileSync(idConfigPath, idContent);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Build includeIf entries for each unique folder
|
|
150
|
+
for (const f of folders) {
|
|
151
|
+
const folderPath = f.path.endsWith('/') ? f.path : f.path + '/';
|
|
152
|
+
includeLines.push(`[includeIf "gitdir:${folderPath}"]`);
|
|
153
|
+
includeLines.push(` path = ${idConfigPath}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const gitIncludeContent = includeLines.join('\n');
|
|
158
|
+
|
|
159
|
+
if (dryRun) {
|
|
160
|
+
context.output.info('\n=== Git Config includes (dry run) ===');
|
|
161
|
+
context.output.info(gitIncludeContent || '(no git config entries)');
|
|
162
|
+
} else if (gitIncludeContent) {
|
|
163
|
+
updateManagedSection(gitConfigPath, GIT_START, GIT_END, gitIncludeContent, false);
|
|
164
|
+
context.output.info(`Git config updated: ${gitConfigPath}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!dryRun) {
|
|
168
|
+
context.output.info('Sync complete.');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = { meta, run };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.devutils', 'config.json');
|
|
8
|
+
|
|
9
|
+
const meta = {
|
|
10
|
+
description: 'Remove a folder link from an identity.',
|
|
11
|
+
arguments: [
|
|
12
|
+
{ name: 'name', description: 'Identity name', required: true },
|
|
13
|
+
{ name: 'folder', description: 'Folder path to unlink', required: true },
|
|
14
|
+
],
|
|
15
|
+
flags: [],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async function run(args, context) {
|
|
19
|
+
const name = args.positional[0];
|
|
20
|
+
const folder = args.positional[1];
|
|
21
|
+
|
|
22
|
+
if (!name || !folder) {
|
|
23
|
+
context.errors.throwError(400, 'Usage: dev identity unlink <name> <folder>', 'identity');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const absolutePath = path.resolve(folder);
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
30
|
+
context.errors.throwError(404, 'Config not found. Run "dev config init" first.', 'identity');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
34
|
+
const identities = config.identities || [];
|
|
35
|
+
|
|
36
|
+
const identity = identities.find(id => id.name.toLowerCase() === name.toLowerCase());
|
|
37
|
+
if (!identity) {
|
|
38
|
+
context.errors.throwError(404, `Identity '${name}' not found.`, 'identity');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const folders = identity.folders || [];
|
|
43
|
+
const found = folders.find(f => f.path === absolutePath);
|
|
44
|
+
if (!found) {
|
|
45
|
+
context.output.info(`Folder '${absolutePath}' is not linked to identity '${identity.name}'. Nothing to do.`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
identity.folders = folders.filter(f => f.path !== absolutePath);
|
|
50
|
+
config.identities = identities;
|
|
51
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n');
|
|
52
|
+
|
|
53
|
+
context.output.info(`Unlinked '${absolutePath}' from identity '${identity.name}'.`);
|
|
54
|
+
context.output.info("Run 'dev identity sync' to update SSH and git config.");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { meta, run };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { MARKER_START, MARKER_END } = require('./markers');
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
description: 'Add gitignore patterns for a technology',
|
|
9
|
+
arguments: [
|
|
10
|
+
{ name: 'technology', description: 'Technology name (e.g., node, macos, docker)', required: true }
|
|
11
|
+
],
|
|
12
|
+
flags: [
|
|
13
|
+
{ name: 'path', description: 'Target directory (defaults to current directory)', type: 'string', default: '.' }
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the absolute path to a pattern file for a given technology.
|
|
19
|
+
* Uses __dirname so the path is relative to the installed package, not the
|
|
20
|
+
* user's working directory.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} technology - Technology name (e.g., 'node').
|
|
23
|
+
* @returns {string} Absolute path to the pattern file.
|
|
24
|
+
*/
|
|
25
|
+
function getPatternFilePath(technology) {
|
|
26
|
+
return path.resolve(__dirname, '../../patterns/gitignore', `${technology}.txt`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Adds gitignore patterns for a technology to the .gitignore in the target
|
|
31
|
+
* directory. If the section already exists, it is replaced in place (idempotent).
|
|
32
|
+
* If the .gitignore does not exist, it is created.
|
|
33
|
+
*
|
|
34
|
+
* @param {object} args - Parsed command arguments ({ positional, flags }).
|
|
35
|
+
* @param {object} context - The DevUtils context object.
|
|
36
|
+
*/
|
|
37
|
+
async function run(args, context) {
|
|
38
|
+
const technology = args.positional[0];
|
|
39
|
+
|
|
40
|
+
// Validate: technology name is required
|
|
41
|
+
if (!technology) {
|
|
42
|
+
context.errors.throwError(400, 'Missing required argument: <technology>. Example: dev ignore add node', 'ignore');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Step A: Validate the technology name and read the pattern file
|
|
47
|
+
const patternFilePath = getPatternFilePath(technology);
|
|
48
|
+
if (!fs.existsSync(patternFilePath)) {
|
|
49
|
+
context.errors.throwError(404, `Unknown technology "${technology}". Run "dev ignore list" to see available options.`, 'ignore');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const patternContent = fs.readFileSync(patternFilePath, 'utf8').trimEnd();
|
|
54
|
+
|
|
55
|
+
// Step B: Resolve the target .gitignore path
|
|
56
|
+
const flagPath = args.flags.path || '.';
|
|
57
|
+
const gitignorePath = path.resolve(flagPath, '.gitignore');
|
|
58
|
+
|
|
59
|
+
// Step C: Read existing .gitignore or start empty
|
|
60
|
+
let existingContent = '';
|
|
61
|
+
let fileExists = false;
|
|
62
|
+
if (fs.existsSync(gitignorePath)) {
|
|
63
|
+
existingContent = fs.readFileSync(gitignorePath, 'utf8');
|
|
64
|
+
fileExists = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Step D: Build the new section
|
|
68
|
+
const section = [
|
|
69
|
+
MARKER_START(technology),
|
|
70
|
+
patternContent,
|
|
71
|
+
MARKER_END(technology)
|
|
72
|
+
].join('\n');
|
|
73
|
+
|
|
74
|
+
// Step E: Check if the section already exists
|
|
75
|
+
const lines = existingContent.split(/\r?\n/);
|
|
76
|
+
const startMarker = MARKER_START(technology);
|
|
77
|
+
const endMarker = MARKER_END(technology);
|
|
78
|
+
const startIndex = lines.findIndex(line => line.trim() === startMarker);
|
|
79
|
+
const endIndex = lines.findIndex(line => line.trim() === endMarker);
|
|
80
|
+
|
|
81
|
+
let updatedContent;
|
|
82
|
+
let action;
|
|
83
|
+
|
|
84
|
+
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
|
|
85
|
+
// Both markers found: replace the existing section in place
|
|
86
|
+
const before = lines.slice(0, startIndex);
|
|
87
|
+
const after = lines.slice(endIndex + 1);
|
|
88
|
+
const sectionLines = section.split('\n');
|
|
89
|
+
const newLines = [...before, ...sectionLines, ...after];
|
|
90
|
+
updatedContent = newLines.join('\n');
|
|
91
|
+
action = 'updated';
|
|
92
|
+
} else if (startIndex !== -1 || endIndex !== -1) {
|
|
93
|
+
// Only one marker found: corrupted state. Warn and append.
|
|
94
|
+
if (!context.flags.quiet) {
|
|
95
|
+
context.output.info(`Warning: Found partial markers for "${technology}" in .gitignore. Appending new section at end.`);
|
|
96
|
+
}
|
|
97
|
+
updatedContent = existingContent;
|
|
98
|
+
// Ensure a blank line before the new section
|
|
99
|
+
if (updatedContent.length > 0 && !updatedContent.endsWith('\n\n') && !updatedContent.endsWith('\n')) {
|
|
100
|
+
updatedContent += '\n';
|
|
101
|
+
}
|
|
102
|
+
if (updatedContent.length > 0 && !updatedContent.endsWith('\n\n')) {
|
|
103
|
+
updatedContent += '\n';
|
|
104
|
+
}
|
|
105
|
+
updatedContent += section;
|
|
106
|
+
action = 'added';
|
|
107
|
+
} else {
|
|
108
|
+
// No markers found: fresh add, append to end
|
|
109
|
+
updatedContent = existingContent;
|
|
110
|
+
// Step F: Ensure a blank line before the new section
|
|
111
|
+
if (updatedContent.length > 0) {
|
|
112
|
+
if (!updatedContent.endsWith('\n')) {
|
|
113
|
+
updatedContent += '\n';
|
|
114
|
+
}
|
|
115
|
+
if (!updatedContent.endsWith('\n\n')) {
|
|
116
|
+
updatedContent += '\n';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
updatedContent += section;
|
|
120
|
+
action = 'added';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Make sure the file ends with a trailing newline
|
|
124
|
+
if (!updatedContent.endsWith('\n')) {
|
|
125
|
+
updatedContent += '\n';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Count pattern lines (lines between markers, not including markers)
|
|
129
|
+
const sectionLines = section.split('\n');
|
|
130
|
+
const patternLineCount = sectionLines.length - 2; // minus start and end markers
|
|
131
|
+
|
|
132
|
+
// Step G: Handle --dry-run
|
|
133
|
+
if (context.flags.dryRun) {
|
|
134
|
+
if (context.flags.format === 'json') {
|
|
135
|
+
context.output.out({
|
|
136
|
+
technology,
|
|
137
|
+
action,
|
|
138
|
+
path: gitignorePath,
|
|
139
|
+
lines: patternLineCount,
|
|
140
|
+
dryRun: true
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
context.output.info(`[dry-run] Would have ${action} ${technology} patterns in ${gitignorePath} (${patternLineCount} lines)`);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Step G: Write the result
|
|
149
|
+
fs.writeFileSync(gitignorePath, updatedContent);
|
|
150
|
+
|
|
151
|
+
// Step H: Output the result
|
|
152
|
+
if (context.flags.format === 'json') {
|
|
153
|
+
context.output.out({
|
|
154
|
+
technology,
|
|
155
|
+
action,
|
|
156
|
+
path: gitignorePath,
|
|
157
|
+
lines: patternLineCount
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
const verb = action === 'updated' ? 'Updated' : 'Added';
|
|
161
|
+
context.output.info(`${verb} ${technology} patterns ${action === 'updated' ? 'in' : 'to'} .gitignore`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { meta, run };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ignore service registration.
|
|
3
|
+
* .gitignore pattern management.
|
|
4
|
+
*/
|
|
5
|
+
module.exports = {
|
|
6
|
+
name: 'ignore',
|
|
7
|
+
description: '.gitignore pattern management',
|
|
8
|
+
commands: {
|
|
9
|
+
add: () => require('./add'),
|
|
10
|
+
remove: () => require('./remove'),
|
|
11
|
+
list: () => require('./list'),
|
|
12
|
+
show: () => require('./show'),
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
description: 'List available gitignore pattern technologies',
|
|
8
|
+
arguments: [],
|
|
9
|
+
flags: []
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the absolute path to the gitignore patterns directory.
|
|
14
|
+
* Uses __dirname so the path is relative to the installed package.
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} Absolute path to the patterns directory.
|
|
17
|
+
*/
|
|
18
|
+
function getPatternsDir() {
|
|
19
|
+
return path.resolve(__dirname, '../../patterns/gitignore');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Lists all available gitignore pattern technologies by scanning the
|
|
24
|
+
* patterns directory. Each .txt file represents one technology. The
|
|
25
|
+
* technology name is the filename without the .txt extension.
|
|
26
|
+
*
|
|
27
|
+
* @param {object} args - Parsed command arguments ({ positional, flags }).
|
|
28
|
+
* @param {object} context - The DevUtils context object.
|
|
29
|
+
*/
|
|
30
|
+
async function run(args, context) {
|
|
31
|
+
const patternsDir = getPatternsDir();
|
|
32
|
+
|
|
33
|
+
// Step A: Read the patterns directory
|
|
34
|
+
if (!fs.existsSync(patternsDir)) {
|
|
35
|
+
context.errors.throwError(500, 'Patterns directory not found. The DevUtils installation may be corrupted.', 'ignore');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const files = fs.readdirSync(patternsDir)
|
|
40
|
+
.filter(f => f.endsWith('.txt'))
|
|
41
|
+
.sort();
|
|
42
|
+
|
|
43
|
+
if (files.length === 0) {
|
|
44
|
+
context.errors.throwError(500, 'No pattern files found. The DevUtils installation may be corrupted.', 'ignore');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Step B: Read the first comment line from each file as a description
|
|
49
|
+
const technologies = files.map(file => {
|
|
50
|
+
const name = file.replace(/\.txt$/, '');
|
|
51
|
+
let description = name;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const content = fs.readFileSync(path.join(patternsDir, file), 'utf8');
|
|
55
|
+
const firstLine = content.split(/\r?\n/)[0];
|
|
56
|
+
if (firstLine && firstLine.startsWith('# ')) {
|
|
57
|
+
description = firstLine.slice(2).trim();
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// If we can't read the file, fall back to the name
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { name, description };
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Step C: Build the result
|
|
67
|
+
const result = {
|
|
68
|
+
technologies,
|
|
69
|
+
count: technologies.length
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Step D: Format the output
|
|
73
|
+
if (context.flags.format === 'json') {
|
|
74
|
+
context.output.out(result);
|
|
75
|
+
} else {
|
|
76
|
+
// Calculate padding for aligned columns
|
|
77
|
+
const maxNameLength = Math.max(...technologies.map(t => t.name.length));
|
|
78
|
+
|
|
79
|
+
context.output.info('Available technologies:');
|
|
80
|
+
for (const tech of technologies) {
|
|
81
|
+
const paddedName = tech.name.padEnd(maxNameLength + 2);
|
|
82
|
+
context.output.info(` ${paddedName}${tech.description}`);
|
|
83
|
+
}
|
|
84
|
+
context.output.info('');
|
|
85
|
+
context.output.info('Use "dev ignore add <technology>" to add patterns to .gitignore.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { meta, run };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared marker constants for DevUtils-managed .gitignore sections.
|
|
5
|
+
*
|
|
6
|
+
* These markers wrap each technology's patterns so that the ignore commands
|
|
7
|
+
* can identify, replace, and remove sections without disturbing manually
|
|
8
|
+
* added patterns. The format is:
|
|
9
|
+
*
|
|
10
|
+
* # >>> devutils:<name>
|
|
11
|
+
* ... patterns ...
|
|
12
|
+
* # <<< devutils:<name>
|
|
13
|
+
*
|
|
14
|
+
* @module commands/ignore/markers
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the start marker for a given technology name.
|
|
19
|
+
* @param {string} name - Technology name (e.g., 'node', 'macos').
|
|
20
|
+
* @returns {string} The start marker line.
|
|
21
|
+
*/
|
|
22
|
+
const MARKER_START = (name) => `# >>> devutils:${name}`;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the end marker for a given technology name.
|
|
26
|
+
* @param {string} name - Technology name (e.g., 'node', 'macos').
|
|
27
|
+
* @returns {string} The end marker line.
|
|
28
|
+
*/
|
|
29
|
+
const MARKER_END = (name) => `# <<< devutils:${name}`;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The prefix used to identify start markers when parsing .gitignore files.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
const MARKER_START_PREFIX = '# >>> devutils:';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The prefix used to identify end markers when parsing .gitignore files.
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
const MARKER_END_PREFIX = '# <<< devutils:';
|
|
42
|
+
|
|
43
|
+
module.exports = { MARKER_START, MARKER_END, MARKER_START_PREFIX, MARKER_END_PREFIX };
|