@markuplint/create-rule-helper
Advanced tools
Comparing version 3.0.0-dev.186 to 3.0.0-dev.290
export declare class CreateRuleHelperError extends Error { | ||
name: string; | ||
name: string; | ||
} |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CreateRuleHelperError = void 0; | ||
class CreateRuleHelperError extends Error { | ||
export class CreateRuleHelperError extends Error { | ||
constructor() { | ||
@@ -10,2 +7,1 @@ super(...arguments); | ||
} | ||
exports.CreateRuleHelperError = CreateRuleHelperError; |
@@ -1,2 +0,2 @@ | ||
import type { CreateRuleHelperParams, CreateRuleHelperResult } from './types'; | ||
import type { CreateRuleHelperParams, CreateRuleHelperResult } from './types.js'; | ||
export declare function createRuleHelper(params: CreateRuleHelperParams): Promise<CreateRuleHelperResult>; |
@@ -1,20 +0,16 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRuleHelper = void 0; | ||
const create_rule_package_1 = require("./create-rule-package"); | ||
const create_rule_to_core_1 = require("./create-rule-to-core"); | ||
const create_rule_to_project_1 = require("./create-rule-to-project"); | ||
async function createRuleHelper(params) { | ||
import { createRulePackage } from './create-rule-package.js'; | ||
import { createRuleToCore } from './create-rule-to-core.js'; | ||
import { createRuleToProject } from './create-rule-to-project.js'; | ||
export async function createRuleHelper(params) { | ||
switch (params.purpose) { | ||
case 'ADD_TO_PROJECT': { | ||
return await (0, create_rule_to_project_1.createRuleToProject)(params); | ||
return await createRuleToProject(params); | ||
} | ||
case 'PUBLISH_AS_PACKAGE': { | ||
return await (0, create_rule_package_1.createRulePackage)(params); | ||
return await createRulePackage(params); | ||
} | ||
case 'CONTRIBUTE_TO_CORE': { | ||
return await (0, create_rule_to_core_1.createRuleToCore)(params); | ||
return await createRuleToCore(params); | ||
} | ||
} | ||
} | ||
exports.createRuleHelper = createRuleHelper; |
@@ -1,7 +0,2 @@ | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types'; | ||
export declare function createRulePackage({ | ||
pluginName, | ||
ruleName, | ||
lang, | ||
needTest, | ||
}: CreateRuleCreatorParams): Promise<CreateRuleHelperResult>; | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types.js'; | ||
export declare function createRulePackage({ pluginName, ruleName, lang, needTest, }: CreateRuleCreatorParams): Promise<CreateRuleHelperResult>; |
@@ -1,16 +0,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRulePackage = void 0; | ||
const tslib_1 = require("tslib"); | ||
const node_path_1 = tslib_1.__importDefault(require("node:path")); | ||
const create_rule_helper_error_1 = require("./create-rule-helper-error"); | ||
const glob_1 = tslib_1.__importDefault(require("./glob")); | ||
const install_scaffold_1 = require("./install-scaffold"); | ||
async function createRulePackage({ pluginName, ruleName, lang, needTest, }) { | ||
const newRuleDir = node_path_1.default.resolve(process.cwd(), '*'); | ||
const files = await (0, glob_1.default)(newRuleDir); | ||
import path from 'node:path'; | ||
import { CreateRuleHelperError } from './create-rule-helper-error.js'; | ||
import glob from './glob.js'; | ||
import { installScaffold } from './install-scaffold.js'; | ||
export async function createRulePackage({ pluginName, ruleName, lang, needTest, }) { | ||
const newRuleDir = path.resolve(process.cwd(), '*'); | ||
const files = await glob(newRuleDir); | ||
if (files.length > 0) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError('The directory is not empty'); | ||
throw new CreateRuleHelperError('The directory is not empty'); | ||
} | ||
return await (0, install_scaffold_1.installScaffold)('package', process.cwd(), { | ||
return await installScaffold('package', process.cwd(), { | ||
pluginName, | ||
@@ -23,2 +19,1 @@ ruleName, | ||
} | ||
exports.createRulePackage = createRulePackage; |
@@ -1,3 +0,3 @@ | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types'; | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types.js'; | ||
export declare function createRuleToCore({ ruleName, core }: CreateRuleCreatorParams): Promise<CreateRuleHelperResult>; | ||
export declare function getRulesDir(): Promise<string>; |
@@ -1,22 +0,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRulesDir = exports.createRuleToCore = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const create_rule_helper_error_1 = require("./create-rule-helper-error"); | ||
const fs_exists_1 = require("./fs-exists"); | ||
const install_scaffold_1 = require("./install-scaffold"); | ||
const search_core_repository_1 = require("./search-core-repository"); | ||
import path from 'node:path'; | ||
import { CreateRuleHelperError } from './create-rule-helper-error.js'; | ||
import { fsExists } from './fs-exists.js'; | ||
import { installScaffold } from './install-scaffold.js'; | ||
import { searchCoreRepository } from './search-core-repository.js'; | ||
const rulesRelDir = ['packages', '@markuplint', 'rules', 'src']; | ||
async function createRuleToCore({ ruleName, core }) { | ||
export async function createRuleToCore({ ruleName, core }) { | ||
if (!core) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError('Core options are not defined'); | ||
throw new CreateRuleHelperError('Core options are not defined'); | ||
} | ||
const rulesDir = await getRulesDir(); | ||
const newRuleDir = path_1.default.resolve(rulesDir, ruleName); | ||
const exists = await (0, fs_exists_1.fsExists)(newRuleDir); | ||
const newRuleDir = path.resolve(rulesDir, ruleName); | ||
const exists = await fsExists(newRuleDir); | ||
if (exists) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError(`A new rule "${ruleName}" already exists`); | ||
throw new CreateRuleHelperError(`A new rule "${ruleName}" already exists`); | ||
} | ||
return await (0, install_scaffold_1.installScaffold)('core', newRuleDir, { | ||
return await installScaffold('core', newRuleDir, { | ||
pluginName: '', | ||
@@ -29,15 +25,13 @@ ruleName, | ||
} | ||
exports.createRuleToCore = createRuleToCore; | ||
async function getRulesDir() { | ||
const rootDir = await (0, search_core_repository_1.searchCoreRepository)(); | ||
export async function getRulesDir() { | ||
const rootDir = await searchCoreRepository(); | ||
if (!rootDir) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError('The repository of markuplint is not found'); | ||
throw new CreateRuleHelperError('The repository of markuplint is not found'); | ||
} | ||
const rulesDir = path_1.default.resolve(rootDir, ...rulesRelDir); | ||
const exists = await (0, fs_exists_1.fsExists)(rulesDir); | ||
const rulesDir = path.resolve(rootDir, ...rulesRelDir); | ||
const exists = await fsExists(rulesDir); | ||
if (!exists) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError(`Core rules directory (${rulesDir}) is not found`); | ||
throw new CreateRuleHelperError(`Core rules directory (${rulesDir}) is not found`); | ||
} | ||
return rulesDir; | ||
} | ||
exports.getRulesDir = getRulesDir; |
@@ -1,7 +0,2 @@ | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types'; | ||
export declare function createRuleToProject({ | ||
pluginName, | ||
ruleName, | ||
lang, | ||
needTest, | ||
}: CreateRuleCreatorParams): Promise<CreateRuleHelperResult>; | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types.js'; | ||
export declare function createRuleToProject({ pluginName, ruleName, lang, needTest, }: CreateRuleCreatorParams): Promise<CreateRuleHelperResult>; |
@@ -1,14 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRuleToProject = void 0; | ||
const node_path_1 = require("node:path"); | ||
const create_rule_helper_error_1 = require("./create-rule-helper-error"); | ||
const fs_exists_1 = require("./fs-exists"); | ||
const install_scaffold_1 = require("./install-scaffold"); | ||
async function createRuleToProject({ pluginName, ruleName, lang, needTest, }) { | ||
const pluginDir = (0, node_path_1.resolve)(process.cwd(), pluginName); | ||
if (await (0, fs_exists_1.fsExists)(pluginDir)) { | ||
throw new create_rule_helper_error_1.CreateRuleHelperError(`The directory exists: ${pluginDir}`); | ||
import { resolve } from 'node:path'; | ||
import { CreateRuleHelperError } from './create-rule-helper-error.js'; | ||
import { fsExists } from './fs-exists.js'; | ||
import { installScaffold } from './install-scaffold.js'; | ||
export async function createRuleToProject({ pluginName, ruleName, lang, needTest, }) { | ||
const pluginDir = resolve(process.cwd(), pluginName); | ||
if (await fsExists(pluginDir)) { | ||
throw new CreateRuleHelperError(`The directory exists: ${pluginDir}`); | ||
} | ||
return await (0, install_scaffold_1.installScaffold)('project', pluginDir, { | ||
return await installScaffold('project', pluginDir, { | ||
pluginName, | ||
@@ -20,2 +17,1 @@ ruleName, | ||
} | ||
exports.createRuleToProject = createRuleToProject; |
@@ -1,8 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fsExists = void 0; | ||
const promises_1 = require("node:fs/promises"); | ||
async function fsExists(path) { | ||
const res = await (0, promises_1.stat)(path).catch(e => { | ||
if ((e === null || e === void 0 ? void 0 : e.code) === 'ENOENT') { | ||
import { stat } from 'node:fs/promises'; | ||
export async function fsExists(path) { | ||
const res = await stat(path).catch(e => { | ||
if (e?.code === 'ENOENT') { | ||
return null; | ||
@@ -14,2 +11,1 @@ } | ||
} | ||
exports.fsExists = fsExists; |
@@ -1,9 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const node_path_1 = require("node:path"); | ||
const glob_1 = require("glob"); | ||
import { sep } from 'node:path'; | ||
import { glob as origin } from 'glob'; | ||
const glob = async (pattern) => { | ||
const normalized = pattern.split(node_path_1.sep).join('/'); | ||
return await (0, glob_1.glob)(normalized); | ||
const normalized = pattern.split(sep).join('/'); | ||
return await origin(normalized); | ||
}; | ||
exports.default = glob; | ||
export default glob; |
@@ -1,3 +0,3 @@ | ||
export * from './create-rule-helper'; | ||
export * from './types'; | ||
export { isMarkuplintRepo } from './is-markuplint-repo'; | ||
export * from './create-rule-helper.js'; | ||
export * from './types.js'; | ||
export { isMarkuplintRepo } from './is-markuplint-repo.js'; |
@@ -1,8 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isMarkuplintRepo = void 0; | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./create-rule-helper"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
var is_markuplint_repo_1 = require("./is-markuplint-repo"); | ||
Object.defineProperty(exports, "isMarkuplintRepo", { enumerable: true, get: function () { return is_markuplint_repo_1.isMarkuplintRepo; } }); | ||
export * from './create-rule-helper.js'; | ||
export * from './types.js'; | ||
export { isMarkuplintRepo } from './is-markuplint-repo.js'; |
@@ -1,8 +0,4 @@ | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types'; | ||
export declare function installScaffold( | ||
scaffoldType: 'core' | 'project' | 'package', | ||
dest: string, | ||
params: CreateRuleCreatorParams & { | ||
readonly packageJson?: boolean; | ||
}, | ||
): Promise<CreateRuleHelperResult>; | ||
import type { CreateRuleCreatorParams, CreateRuleHelperResult } from './types.js'; | ||
export declare function installScaffold(scaffoldType: 'core' | 'project' | 'package', dest: string, params: CreateRuleCreatorParams & { | ||
readonly packageJson?: boolean; | ||
}): Promise<CreateRuleHelperResult>; |
@@ -1,17 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.installScaffold = void 0; | ||
const tslib_1 = require("tslib"); | ||
const promises_1 = tslib_1.__importDefault(require("node:fs/promises")); | ||
const node_path_1 = require("node:path"); | ||
const fs_exists_1 = require("./fs-exists"); | ||
const transfer_1 = require("./transfer"); | ||
async function installScaffold(scaffoldType, dest, params) { | ||
var _a, _b, _c; | ||
const exists = await (0, fs_exists_1.fsExists)(dest); | ||
import fs from 'node:fs/promises'; | ||
import { resolve, dirname } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { fsExists } from './fs-exists.js'; | ||
import { transfer } from './transfer.js'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
export async function installScaffold(scaffoldType, dest, params) { | ||
const exists = await fsExists(dest); | ||
if (!exists) { | ||
await promises_1.default.mkdir(dest); | ||
await fs.mkdir(dest); | ||
} | ||
const scaffoldDir = (0, node_path_1.resolve)(__dirname, '..', 'scaffold', scaffoldType); | ||
const transferred = await (0, transfer_1.transfer)(scaffoldType, scaffoldDir, dest, { | ||
const scaffoldDir = resolve(__dirname, '..', 'scaffold', scaffoldType); | ||
const transferred = await transfer(scaffoldType, scaffoldDir, dest, { | ||
transpile: params.lang === 'JAVASCRIPT', | ||
@@ -22,39 +20,15 @@ test: params.needTest, | ||
ruleName: params.ruleName, | ||
description: (_a = params.core) === null || _a === void 0 ? void 0 : _a.description, | ||
category: (_b = params.core) === null || _b === void 0 ? void 0 : _b.category, | ||
severity: (_c = params.core) === null || _c === void 0 ? void 0 : _c.severity, | ||
description: params.core?.description, | ||
category: params.core?.category, | ||
severity: params.core?.severity, | ||
}, | ||
}); | ||
const packageJson = params.packageJson ? (0, node_path_1.resolve)(dest, 'package.json') : null; | ||
const packageJson = params.packageJson ? resolve(dest, 'package.json') : null; | ||
const dependencies = []; | ||
const devDependencies = []; | ||
if (packageJson) { | ||
const ext = params.lang === 'JAVASCRIPT' ? 'js' : 'ts'; | ||
// const ext = params.lang === 'JAVASCRIPT' ? 'js' : 'ts'; | ||
const packageContent = { | ||
name: params.ruleName, | ||
scripts: {}, | ||
jest: { | ||
moduleFileExtensions: ['js', ...(params.lang === 'TYPESCRIPT' ? ['ts'] : [])], | ||
testRegex: `(\\.|/)(spec|test)\\.${ext}$`, | ||
testEnvironment: 'node', | ||
transform: params.lang === 'TYPESCRIPT' | ||
? { | ||
'^.+\\.ts$': 'ts-jest', | ||
} | ||
: undefined, | ||
}, | ||
babel: params.needTest && params.lang === 'JAVASCRIPT' | ||
? { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
], | ||
} | ||
: undefined, | ||
}; | ||
@@ -67,13 +41,4 @@ if (params.lang === 'TYPESCRIPT') { | ||
if (params.needTest) { | ||
packageContent.scripts.test = 'jest'; | ||
devDependencies.push('jest'); | ||
if (params.lang === 'TYPESCRIPT') { | ||
devDependencies.push('@types/jest'); | ||
devDependencies.push('ts-jest'); | ||
} | ||
else { | ||
devDependencies.push('babel-jest'); | ||
devDependencies.push('@babel/core'); | ||
devDependencies.push('@babel/preset-env'); | ||
} | ||
packageContent.scripts.test = 'vitest'; | ||
devDependencies.push('vitest'); | ||
} | ||
@@ -83,3 +48,3 @@ if (params.lang === 'TYPESCRIPT') { | ||
} | ||
await promises_1.default.writeFile(packageJson, JSON.stringify(packageContent, null, 2), { encoding: 'utf-8' }); | ||
await fs.writeFile(packageJson, JSON.stringify(packageContent, null, 2), { encoding: 'utf-8' }); | ||
transferred.push({ | ||
@@ -100,2 +65,1 @@ ext: '.json', | ||
} | ||
exports.installScaffold = installScaffold; |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isMarkuplintRepo = void 0; | ||
const search_core_repository_1 = require("./search-core-repository"); | ||
async function isMarkuplintRepo() { | ||
const rootDir = await (0, search_core_repository_1.searchCoreRepository)(); | ||
import { searchCoreRepository } from './search-core-repository.js'; | ||
export async function isMarkuplintRepo() { | ||
const rootDir = await searchCoreRepository(); | ||
return !!rootDir; | ||
} | ||
exports.isMarkuplintRepo = isMarkuplintRepo; |
@@ -1,14 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readPackageJson = void 0; | ||
const tslib_1 = require("tslib"); | ||
const promises_1 = tslib_1.__importDefault(require("node:fs/promises")); | ||
const node_path_1 = tslib_1.__importDefault(require("node:path")); | ||
async function readPackageJson(dir) { | ||
var _a; | ||
const filePath = node_path_1.default.resolve(dir, 'package.json'); | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
export async function readPackageJson(dir) { | ||
const filePath = path.resolve(dir, 'package.json'); | ||
try { | ||
const json = await promises_1.default.readFile(filePath, { encoding: 'utf-8' }); | ||
const json = await fs.readFile(filePath, { encoding: 'utf-8' }); | ||
const data = JSON.parse(json); | ||
return (_a = data === null || data === void 0 ? void 0 : data.name) !== null && _a !== void 0 ? _a : null; | ||
return data?.name ?? null; | ||
} | ||
@@ -19,2 +14,1 @@ catch (_) { | ||
} | ||
exports.readPackageJson = readPackageJson; |
@@ -1,13 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.searchCoreRepository = void 0; | ||
const tslib_1 = require("tslib"); | ||
const node_path_1 = tslib_1.__importDefault(require("node:path")); | ||
const read_package_json_1 = require("./read-package-json"); | ||
async function searchCoreRepository() { | ||
const paths = node_path_1.default.resolve(process.cwd()).split(node_path_1.default.sep); | ||
import path from 'node:path'; | ||
import { readPackageJson } from './read-package-json.js'; | ||
export async function searchCoreRepository() { | ||
const paths = path.resolve(process.cwd()).split(path.sep); | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const currentDir = paths.join(node_path_1.default.sep); | ||
const name = await (0, read_package_json_1.readPackageJson)(currentDir); | ||
const currentDir = paths.join(path.sep); | ||
const name = await readPackageJson(currentDir); | ||
if (name === 'markuplint-packages') { | ||
@@ -22,2 +18,1 @@ return currentDir; | ||
} | ||
exports.searchCoreRepository = searchCoreRepository; |
@@ -1,13 +0,8 @@ | ||
import type { File } from './types'; | ||
import type { File } from './types.js'; | ||
type TransferOptions = { | ||
readonly transpile?: boolean; | ||
readonly test?: boolean; | ||
readonly replacer?: Readonly<Record<string, string | void>>; | ||
readonly transpile?: boolean; | ||
readonly test?: boolean; | ||
readonly replacer?: Readonly<Record<string, string | void>>; | ||
}; | ||
export declare function transfer( | ||
scaffoldType: 'core' | 'project' | 'package', | ||
baseDir: string, | ||
destDir: string, | ||
options?: TransferOptions, | ||
): Promise<File[]>; | ||
export declare function transfer(scaffoldType: 'core' | 'project' | 'package', baseDir: string, destDir: string, options?: TransferOptions): Promise<File[]>; | ||
export {}; |
@@ -1,13 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transfer = void 0; | ||
const tslib_1 = require("tslib"); | ||
const node_fs_1 = require("node:fs"); | ||
const promises_1 = tslib_1.__importDefault(require("node:fs/promises")); | ||
const node_path_1 = require("node:path"); | ||
const prettier_1 = require("prettier"); | ||
const typescript_1 = require("typescript"); | ||
const fs_exists_1 = require("./fs-exists"); | ||
const glob_1 = tslib_1.__importDefault(require("./glob")); | ||
async function transfer(scaffoldType, baseDir, destDir, options) { | ||
import { statSync } from 'node:fs'; | ||
import fs from 'node:fs/promises'; | ||
import { resolve, extname, basename, relative, dirname, sep } from 'node:path'; | ||
import { format } from 'prettier'; | ||
import tsc from 'typescript'; | ||
import { fsExists } from './fs-exists.js'; | ||
import glob from './glob.js'; | ||
// eslint-disable-next-line import/no-named-as-default-member | ||
const { transpile, ScriptTarget } = tsc; | ||
export async function transfer(scaffoldType, baseDir, destDir, options) { | ||
const files = await scan(baseDir, destDir); | ||
@@ -23,14 +21,12 @@ const results = []; | ||
} | ||
exports.transfer = transfer; | ||
async function transferFile(scaffoldType, file, options) { | ||
var _a, _b; | ||
if (!(await (0, fs_exists_1.fsExists)(file.filePath))) { | ||
if (!(await fsExists(file.filePath))) { | ||
return null; | ||
} | ||
if (file.test && !(options === null || options === void 0 ? void 0 : options.test)) { | ||
if (file.test && !options?.test) { | ||
return null; | ||
} | ||
let contents = await promises_1.default.readFile(file.filePath, { encoding: 'utf-8' }); | ||
if (options === null || options === void 0 ? void 0 : options.replacer) { | ||
Object.entries(options === null || options === void 0 ? void 0 : options.replacer).forEach(([before, after]) => { | ||
let contents = await fs.readFile(file.filePath, { encoding: 'utf-8' }); | ||
if (options?.replacer) { | ||
Object.entries(options?.replacer).forEach(([before, after]) => { | ||
if (!after) { | ||
@@ -52,14 +48,14 @@ return; | ||
if (scaffoldType === 'core' && file.test) { | ||
const name = (_a = options === null || options === void 0 ? void 0 : options.replacer) === null || _a === void 0 ? void 0 : _a.ruleName; | ||
const name = options?.replacer?.ruleName; | ||
if (!name) { | ||
throw new Error('Rule name is empty'); | ||
} | ||
newFile.destDir = newFile.destDir.replace(`${node_path_1.sep}rules${node_path_1.sep}src${node_path_1.sep}`, `${node_path_1.sep}rules${node_path_1.sep}test${node_path_1.sep}`); | ||
newFile.destDir = newFile.destDir.replace(`${sep}rules${sep}src${sep}`, `${sep}rules${sep}test${sep}`); | ||
contents = contents.replace("require('./').default", `require('../../lib/${name}').default`); | ||
} | ||
// TypeScript transpiles to JS | ||
if (newFile.ext === '.ts' && (options === null || options === void 0 ? void 0 : options.transpile)) { | ||
if (newFile.ext === '.ts' && options?.transpile) { | ||
newFile.ext = '.js'; | ||
contents = (0, typescript_1.transpile)(contents, { | ||
target: typescript_1.ScriptTarget.ESNext, | ||
contents = transpile(contents, { | ||
target: ScriptTarget.ESNext, | ||
}, newFile.filePath); | ||
@@ -69,3 +65,3 @@ // Insert new line before comments and the export keyword | ||
} | ||
const candidateName = (_b = options === null || options === void 0 ? void 0 : options.replacer) === null || _b === void 0 ? void 0 : _b[newFile.name.replace(/_/g, '')]; | ||
const candidateName = options?.replacer?.[newFile.name.replace(/_/g, '')]; | ||
if (candidateName) { | ||
@@ -75,3 +71,3 @@ newFile.name = candidateName; | ||
} | ||
const dest = (0, node_path_1.resolve)(newFile.destDir, newFile.fileName + newFile.ext); | ||
const dest = resolve(newFile.destDir, newFile.fileName + newFile.ext); | ||
// Prettier | ||
@@ -83,28 +79,28 @@ const parser = newFile.ext === '.md' | ||
: newFile.ext === '.ts' | ||
? (options === null || options === void 0 ? void 0 : options.transpile) | ||
? options?.transpile | ||
? 'babel' | ||
: 'typescript' | ||
: undefined; | ||
contents = (0, prettier_1.format)(contents, { parser, filepath: dest }); | ||
if (!(await (0, fs_exists_1.fsExists)(newFile.destDir))) { | ||
await promises_1.default.mkdir(newFile.destDir, { recursive: true }); | ||
contents = await format(contents, { parser, filepath: dest }); | ||
if (!(await fsExists(newFile.destDir))) { | ||
await fs.mkdir(newFile.destDir, { recursive: true }); | ||
} | ||
await promises_1.default.writeFile(dest, contents, { encoding: 'utf-8' }); | ||
await fs.writeFile(dest, contents, { encoding: 'utf-8' }); | ||
return newFile; | ||
} | ||
async function scan(baseDir, destDir) { | ||
const fileList = await (0, glob_1.default)((0, node_path_1.resolve)(baseDir, '**', '*')); | ||
const fileList = await glob(resolve(baseDir, '**', '*')); | ||
const destList = fileList | ||
.map(filePath => { | ||
const stat = (0, node_fs_1.statSync)(filePath); | ||
const stat = statSync(filePath); | ||
if (!stat.isFile()) { | ||
return null; | ||
} | ||
const relPath = (0, node_path_1.relative)(baseDir, filePath); | ||
const destPath = (0, node_path_1.resolve)(destDir, relPath); | ||
const ext = (0, node_path_1.extname)(destPath); | ||
const fileName = (0, node_path_1.basename)(destPath, ext); | ||
const test = (0, node_path_1.extname)(fileName) === '.spec'; | ||
const name = (0, node_path_1.basename)(fileName, '.spec'); | ||
const destFileDir = (0, node_path_1.dirname)(destPath); | ||
const relPath = relative(baseDir, filePath); | ||
const destPath = resolve(destDir, relPath); | ||
const ext = extname(destPath); | ||
const fileName = basename(destPath, ext); | ||
const test = extname(fileName) === '.spec'; | ||
const name = basename(fileName, '.spec'); | ||
const destFileDir = dirname(destPath); | ||
return { | ||
@@ -111,0 +107,0 @@ ext, |
export type CreateRuleHelperParams = CreateRuleCreatorParams & { | ||
readonly purpose: CreateRulePurpose; | ||
readonly purpose: CreateRulePurpose; | ||
}; | ||
export type CreateRuleCreatorParams = { | ||
readonly pluginName: string; | ||
readonly ruleName: string; | ||
readonly lang: CreateRuleLanguage; | ||
readonly needTest: boolean; | ||
readonly core?: CreateRuleCreatorCoreParams; | ||
readonly pluginName: string; | ||
readonly ruleName: string; | ||
readonly lang: CreateRuleLanguage; | ||
readonly needTest: boolean; | ||
readonly core?: CreateRuleCreatorCoreParams; | ||
}; | ||
export type CreateRuleCreatorCoreParams = { | ||
readonly description: string; | ||
readonly category: string; | ||
readonly severity: string; | ||
readonly description: string; | ||
readonly category: string; | ||
readonly severity: string; | ||
}; | ||
export type CreateRuleHelperResult = { | ||
readonly files: readonly File[]; | ||
readonly dependencies: readonly string[]; | ||
readonly devDependencies: readonly string[]; | ||
readonly files: readonly File[]; | ||
readonly dependencies: readonly string[]; | ||
readonly devDependencies: readonly string[]; | ||
}; | ||
@@ -24,8 +24,8 @@ export type CreateRuleLanguage = 'JAVASCRIPT' | 'TYPESCRIPT'; | ||
export type File = { | ||
readonly ext: string; | ||
readonly name: string; | ||
readonly fileName: string; | ||
readonly test: boolean; | ||
readonly destDir: string; | ||
readonly filePath: string; | ||
readonly ext: string; | ||
readonly name: string; | ||
readonly fileName: string; | ||
readonly test: boolean; | ||
readonly destDir: string; | ||
readonly filePath: string; | ||
}; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
{ | ||
"name": "@markuplint/create-rule-helper", | ||
"version": "3.0.0-dev.186+37ceba57", | ||
"version": "3.0.0-dev.290+af676442", | ||
"description": "Create rule helper", | ||
@@ -9,4 +9,9 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"private": false, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.js" | ||
} | ||
}, | ||
"types": "./lib/index.d.ts", | ||
"publishConfig": { | ||
@@ -21,14 +26,14 @@ "access": "public" | ||
"dependencies": { | ||
"@markuplint/ml-core": "3.0.0-dev.186+37ceba57", | ||
"glob": "^10.2.2", | ||
"prettier": "^2.8.8", | ||
"@markuplint/ml-core": "3.0.0-dev.290+af676442", | ||
"glob": "^10.3.6", | ||
"prettier": "^3.0.3", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.4.1", | ||
"typescript": "^5.0.4" | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/fs-extra": "^11.0.2", | ||
"fs-extra": "^11.1.1" | ||
}, | ||
"gitHead": "37ceba578aff49e0326c5e374cef3da6be303b25" | ||
"gitHead": "af6764422feecb56d1d84659028f53daf685bb78" | ||
} |
@@ -55,4 +55,4 @@ # The `__pluginName__` rule | ||
| -------- | ---------- | -------- | ------------- | ------------------------- | | ||
| `foo` | `string` | ✔ | `undefined` | TODO: Write a description | | ||
| `bar` | `number[]` | ✔ | `undefined` | TODO: Write a description | | ||
| `foo` | `string` | ✔ | `undefined` | TODO: Write a description | | ||
| `bar` | `number[]` | ✔ | `undefined` | TODO: Write a description | | ||
@@ -59,0 +59,0 @@ ### Default severity |
import { createPlugin } from '@markuplint/ml-core'; | ||
import { __ruleName__c } from './rules/__ruleName__'; | ||
import { __ruleName__c } from './rules/__ruleName__.js'; | ||
@@ -5,0 +5,0 @@ export default createPlugin({ |
import { createPlugin } from '@markuplint/ml-core'; | ||
import { __ruleName__c } from './rules/__ruleName__'; | ||
import { __ruleName__c } from './rules/__ruleName__.js'; | ||
@@ -5,0 +5,0 @@ export default createPlugin({ |
import { mlRuleTest } from 'markuplint'; | ||
import { test, expect } from 'vitest'; | ||
import { __ruleName__c } from './__ruleName__'; | ||
import { __ruleName__c } from './__ruleName__.js'; | ||
@@ -8,3 +9,3 @@ /** | ||
*/ | ||
it('is test', async () => { | ||
test('It is test', async () => { | ||
const { violations } = await mlRuleTest( | ||
@@ -11,0 +12,0 @@ __ruleName__c({ |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Yes
27469
43
721
+ Addedprettier@3.5.2(transitive)
- Removedprettier@2.8.8(transitive)
Updatedglob@^10.3.6
Updatedprettier@^3.0.3
Updatedtslib@^2.6.2
Updatedtypescript@^5.2.2