@markuplint/create-rule-helper
Advanced tools
Comparing version 4.0.0-alpha.3 to 4.0.0-alpha.4
import { stat } from 'node:fs/promises'; | ||
export async function fsExists(path) { | ||
const res = await stat(path).catch(e => { | ||
if (e?.code === 'ENOENT') { | ||
const res = await stat(path).catch(error => { | ||
if (error?.code === 'ENOENT') { | ||
return null; | ||
} | ||
throw e; | ||
throw error; | ||
}); | ||
return !!res; | ||
} |
@@ -46,3 +46,3 @@ import fs from 'node:fs/promises'; | ||
} | ||
await fs.writeFile(packageJson, JSON.stringify(packageContent, null, 2), { encoding: 'utf-8' }); | ||
await fs.writeFile(packageJson, JSON.stringify(packageContent, null, 2), { encoding: 'utf8' }); | ||
transferred.push({ | ||
@@ -49,0 +49,0 @@ ext: '.json', |
@@ -6,9 +6,9 @@ import fs from 'node:fs/promises'; | ||
try { | ||
const json = await fs.readFile(filePath, { encoding: 'utf-8' }); | ||
const json = await fs.readFile(filePath, { encoding: 'utf8' }); | ||
const data = JSON.parse(json); | ||
return data?.name ?? null; | ||
} | ||
catch (_) { | ||
catch { | ||
return null; | ||
} | ||
} |
@@ -28,15 +28,15 @@ import { statSync } from 'node:fs'; | ||
} | ||
let contents = await fs.readFile(file.filePath, { encoding: 'utf-8' }); | ||
let contents = await fs.readFile(file.filePath, { encoding: 'utf8' }); | ||
if (options?.replacer) { | ||
Object.entries(options?.replacer).forEach(([before, after]) => { | ||
for (const [before, after] of Object.entries(options?.replacer)) { | ||
if (!after) { | ||
return; | ||
continue; | ||
} | ||
// Hyphenation to camel-case for variables | ||
// `rule-name` => `ruleName` | ||
contents = contents.replace(new RegExp(`__${before}__c`, 'g'), | ||
contents = contents.replaceAll(new RegExp(`__${before}__c`, 'g'), | ||
// Camelize | ||
after.replace(/-+([a-z])/gi, (_, $1) => $1.toUpperCase()).replace(/^[a-z]/, $0 => $0.toLowerCase())); | ||
contents = contents.replace(new RegExp(`__${before}__`, 'g'), after); | ||
}); | ||
after.replaceAll(/-+([a-z])/gi, (_, $1) => $1.toUpperCase()).replace(/^[a-z]/, $0 => $0.toLowerCase())); | ||
contents = contents.replaceAll(new RegExp(`__${before}__`, 'g'), after); | ||
} | ||
} | ||
@@ -62,5 +62,5 @@ // Remove prettier ignore comment | ||
// Insert new line before comments and the export keyword | ||
contents = contents.replace(/(\n)(\s+\/\*\*|export)/g, '$1\n$2'); | ||
contents = contents.replaceAll(/(\n)(\s+\/\*\*|export)/g, '$1\n$2'); | ||
} | ||
const candidateName = options?.replacer?.[newFile.name.replace(/_/g, '')]; | ||
const candidateName = options?.replacer?.[newFile.name.replaceAll('_', '')]; | ||
if (candidateName) { | ||
@@ -85,3 +85,3 @@ newFile.name = candidateName; | ||
} | ||
await fs.writeFile(dest, contents, { encoding: 'utf-8' }); | ||
await fs.writeFile(dest, contents, { encoding: 'utf8' }); | ||
return newFile; | ||
@@ -88,0 +88,0 @@ } |
{ | ||
"name": "@markuplint/create-rule-helper", | ||
"version": "4.0.0-alpha.3", | ||
"version": "4.0.0-alpha.4", | ||
"description": "Create rule helper", | ||
@@ -25,14 +25,13 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"dependencies": { | ||
"@markuplint/ml-core": "4.0.0-alpha.3", | ||
"@markuplint/ml-core": "4.0.0-alpha.4", | ||
"glob": "^10.3.6", | ||
"prettier": "^3.0.3", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^11.0.2", | ||
"@types/fs-extra": "^11.0.3", | ||
"fs-extra": "^11.1.1" | ||
}, | ||
"gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e" | ||
"gitHead": "991b3aef77fde42c79343ee8c807257a35c589d7" | ||
} |
5
27450
+ Added@markuplint/config-presets@4.0.0-alpha.4(transitive)
+ Added@markuplint/html-parser@4.0.0-alpha.4(transitive)
+ Added@markuplint/html-spec@4.0.0-alpha.4(transitive)
+ Added@markuplint/i18n@4.0.0-alpha.4(transitive)
+ Added@markuplint/ml-ast@4.0.0-alpha.4(transitive)
+ Added@markuplint/ml-config@4.0.0-alpha.4(transitive)
+ Added@markuplint/ml-core@4.0.0-alpha.4(transitive)
+ Added@markuplint/ml-spec@4.0.0-alpha.4(transitive)
+ Added@markuplint/parser-utils@4.0.0-alpha.4(transitive)
+ Added@markuplint/selector@4.0.0-alpha.4(transitive)
+ Added@markuplint/shared@4.0.0-alpha.4(transitive)
+ Added@markuplint/types@4.0.0-alpha.4(transitive)
+ Added@types/whatwg-mimetype@3.0.1(transitive)
- Removedtslib@^2.6.2
- Removed@markuplint/config-presets@4.0.0-alpha.3(transitive)
- Removed@markuplint/html-parser@4.0.0-alpha.3(transitive)
- Removed@markuplint/html-spec@4.0.0-alpha.3(transitive)
- Removed@markuplint/i18n@4.0.0-alpha.3(transitive)
- Removed@markuplint/ml-ast@4.0.0-alpha.3(transitive)
- Removed@markuplint/ml-config@4.0.0-alpha.3(transitive)
- Removed@markuplint/ml-core@4.0.0-alpha.3(transitive)
- Removed@markuplint/ml-spec@4.0.0-alpha.3(transitive)
- Removed@markuplint/parser-utils@4.0.0-alpha.3(transitive)
- Removed@markuplint/selector@4.0.0-alpha.3(transitive)
- Removed@markuplint/shared@4.0.0-alpha.3(transitive)
- Removed@markuplint/types@4.0.0-alpha.3(transitive)
- Removed@types/bcp-47@2.0.4(transitive)
- Removed@types/whatwg-mimetype@3.0.0(transitive)
- Removedtslib@2.8.1(transitive)