bitcompass 0.2.7 → 0.2.8
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/dist/commands/rules.js +2 -1
- package/dist/commands/solutions.js +2 -1
- package/dist/lib/slug.d.ts +15 -0
- package/dist/lib/slug.js +33 -0
- package/package.json +1 -1
package/dist/commands/rules.js
CHANGED
|
@@ -6,6 +6,7 @@ import { join } from 'path';
|
|
|
6
6
|
import { loadCredentials } from '../auth/config.js';
|
|
7
7
|
import { getProjectConfig } from '../auth/project-config.js';
|
|
8
8
|
import { searchRules, fetchRules, getRuleById, insertRule } from '../api/client.js';
|
|
9
|
+
import { ruleFilename } from '../lib/slug.js';
|
|
9
10
|
export const runRulesSearch = async (query) => {
|
|
10
11
|
if (!loadCredentials()) {
|
|
11
12
|
console.error(chalk.red('Not logged in. Run bitcompass login.'));
|
|
@@ -72,7 +73,7 @@ export const runRulesPull = async (id) => {
|
|
|
72
73
|
const { outputPath } = getProjectConfig({ warnIfMissing: true });
|
|
73
74
|
const outDir = join(process.cwd(), outputPath);
|
|
74
75
|
mkdirSync(outDir, { recursive: true });
|
|
75
|
-
const filename = join(outDir,
|
|
76
|
+
const filename = join(outDir, ruleFilename(rule.title, rule.id));
|
|
76
77
|
const content = `# ${rule.title}\n\n${rule.description}\n\n${rule.body}\n`;
|
|
77
78
|
writeFileSync(filename, content);
|
|
78
79
|
console.log(chalk.green('Wrote'), filename);
|
|
@@ -6,6 +6,7 @@ import { join } from 'path';
|
|
|
6
6
|
import { loadCredentials } from '../auth/config.js';
|
|
7
7
|
import { getProjectConfig } from '../auth/project-config.js';
|
|
8
8
|
import { searchRules, fetchRules, getRuleById, insertRule } from '../api/client.js';
|
|
9
|
+
import { solutionFilename } from '../lib/slug.js';
|
|
9
10
|
export const runSolutionsSearch = async (query) => {
|
|
10
11
|
if (!loadCredentials()) {
|
|
11
12
|
console.error(chalk.red('Not logged in. Run bitcompass login.'));
|
|
@@ -60,7 +61,7 @@ export const runSolutionsPull = async (id) => {
|
|
|
60
61
|
const { outputPath } = getProjectConfig({ warnIfMissing: true });
|
|
61
62
|
const outDir = join(process.cwd(), outputPath);
|
|
62
63
|
mkdirSync(outDir, { recursive: true });
|
|
63
|
-
const filename = join(outDir,
|
|
64
|
+
const filename = join(outDir, solutionFilename(rule.title, rule.id));
|
|
64
65
|
const content = `# ${rule.title}\n\n${rule.description}\n\n## Solution\n\n${rule.body}\n`;
|
|
65
66
|
writeFileSync(filename, content);
|
|
66
67
|
console.log(chalk.green('Wrote'), filename);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a rule/solution title to a standardized filename slug.
|
|
3
|
+
* e.g. "# Strava API Authentication Flow" -> "strava-api-authentication-flow"
|
|
4
|
+
*/
|
|
5
|
+
export declare const titleToSlug: (title: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the rule filename (e.g. rule-strava-api-authentication-flow.md).
|
|
8
|
+
* Falls back to id if slug is empty.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ruleFilename: (title: string, id: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the solution filename (e.g. solution-strava-api-authentication-flow.md).
|
|
13
|
+
* Falls back to id if slug is empty.
|
|
14
|
+
*/
|
|
15
|
+
export declare const solutionFilename: (title: string, id: string) => string;
|
package/dist/lib/slug.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a rule/solution title to a standardized filename slug.
|
|
3
|
+
* e.g. "# Strava API Authentication Flow" -> "strava-api-authentication-flow"
|
|
4
|
+
*/
|
|
5
|
+
export const titleToSlug = (title) => {
|
|
6
|
+
const trimmed = (title ?? '').trim().replace(/^#\s*/, '');
|
|
7
|
+
if (!trimmed)
|
|
8
|
+
return '';
|
|
9
|
+
return trimmed
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.replace(/\s+/g, '-')
|
|
12
|
+
.replace(/[^a-z0-9-]/g, '')
|
|
13
|
+
.replace(/-+/g, '-')
|
|
14
|
+
.replace(/^-|-$/g, '');
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Returns the rule filename (e.g. rule-strava-api-authentication-flow.md).
|
|
18
|
+
* Falls back to id if slug is empty.
|
|
19
|
+
*/
|
|
20
|
+
export const ruleFilename = (title, id) => {
|
|
21
|
+
const slug = titleToSlug(title);
|
|
22
|
+
const base = slug ? `rule-${slug}` : `rule-${id}`;
|
|
23
|
+
return `${base}.md`;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Returns the solution filename (e.g. solution-strava-api-authentication-flow.md).
|
|
27
|
+
* Falls back to id if slug is empty.
|
|
28
|
+
*/
|
|
29
|
+
export const solutionFilename = (title, id) => {
|
|
30
|
+
const slug = titleToSlug(title);
|
|
31
|
+
const base = slug ? `solution-${slug}` : `solution-${id}`;
|
|
32
|
+
return `${base}.md`;
|
|
33
|
+
};
|