markuplint 3.13.0 → 4.0.0-alpha.2

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.
Files changed (53) hide show
  1. package/bin/markuplint.mjs +3 -0
  2. package/lib/api/index.d.ts +2 -2
  3. package/lib/api/index.js +2 -10
  4. package/lib/api/lint.d.ts +2 -2
  5. package/lib/api/lint.js +5 -10
  6. package/lib/api/ml-engine.d.ts +7 -2
  7. package/lib/api/ml-engine.js +99 -99
  8. package/lib/api/types.js +1 -2
  9. package/lib/api/v1.d.ts +1 -1
  10. package/lib/api/v1.js +12 -20
  11. package/lib/cli/bootstrap.d.ts +4 -5
  12. package/lib/cli/bootstrap.js +7 -10
  13. package/lib/cli/command.d.ts +2 -2
  14. package/lib/cli/command.js +19 -25
  15. package/lib/cli/create-rule/index.js +26 -32
  16. package/lib/cli/index.js +26 -29
  17. package/lib/cli/init/create-config.d.ts +1 -1
  18. package/lib/cli/init/create-config.js +3 -8
  19. package/lib/cli/init/get-default-rules.d.ts +1 -1
  20. package/lib/cli/init/get-default-rules.js +8 -13
  21. package/lib/cli/init/index.js +30 -34
  22. package/lib/cli/init/install-module.d.ts +1 -1
  23. package/lib/cli/init/install-module.js +12 -18
  24. package/lib/cli/init/types.js +1 -2
  25. package/lib/cli/output.d.ts +2 -2
  26. package/lib/cli/output.js +8 -14
  27. package/lib/cli/prompt.js +15 -25
  28. package/lib/cli/search/index.d.ts +1 -1
  29. package/lib/cli/search/index.js +7 -11
  30. package/lib/debug.js +8 -13
  31. package/lib/get-json-module.d.ts +1 -0
  32. package/lib/get-json-module.js +10 -0
  33. package/lib/global-settings.js +2 -7
  34. package/lib/i18n.js +8 -15
  35. package/lib/index.d.ts +6 -5
  36. package/lib/index.js +6 -10
  37. package/lib/reporter/github-reporter.d.ts +1 -1
  38. package/lib/reporter/github-reporter.js +3 -7
  39. package/lib/reporter/index.d.ts +3 -3
  40. package/lib/reporter/index.js +3 -6
  41. package/lib/reporter/simple-reporter.d.ts +2 -2
  42. package/lib/reporter/simple-reporter.js +11 -16
  43. package/lib/reporter/standard-reporter.d.ts +2 -2
  44. package/lib/reporter/standard-reporter.js +17 -23
  45. package/lib/testing-tool/index.js +17 -25
  46. package/lib/types.js +1 -2
  47. package/lib/util.js +21 -33
  48. package/lib/v1.d.ts +1 -1
  49. package/lib/v1.js +1 -5
  50. package/lib/version.d.ts +1 -0
  51. package/lib/version.js +3 -0
  52. package/package.json +34 -26
  53. package/bin/markuplint +0 -3
@@ -1,38 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.command = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = require("fs");
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const file_resolver_1 = require("@markuplint/file-resolver");
8
- const api_1 = require("../api");
9
- const debug_1 = require("../debug");
10
- const output_1 = require("./output");
11
- async function command(files, options, apiOptions) {
12
- var _a;
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { resolveFiles } from '@markuplint/file-resolver';
4
+ import { MLEngine } from '../api/index.js';
5
+ import { log } from '../debug.js';
6
+ import { output } from './output.js';
7
+ export async function command(files, options, apiOptions) {
13
8
  const fix = options.fix;
14
- const configFile = options.config && path_1.default.join(process.cwd(), options.config);
9
+ const configFile = options.config && path.join(process.cwd(), options.config);
15
10
  const locale = options.locale;
16
11
  const searchConfig = options.searchConfig;
17
12
  const ignoreExt = options.ignoreExt;
18
13
  const importPresetRules = options.importPresetRules;
19
14
  const verbose = options.verbose;
20
- const fileList = await (0, file_resolver_1.resolveFiles)(files);
15
+ const fileList = await resolveFiles(files);
21
16
  if (fileList.length === 0 && !options.allowEmptyInput) {
22
17
  process.stderr.write('Markuplint: No target files.\n');
23
18
  // Error
24
19
  return true;
25
20
  }
26
- if (debug_1.log.enabled) {
27
- (0, debug_1.log)('File list: %O', fileList.map(f => f.path));
28
- (0, debug_1.log)('Config: %s', configFile !== null && configFile !== void 0 ? configFile : 'N/A');
29
- (0, debug_1.log)('Fix option: %s', fix);
21
+ if (log.enabled) {
22
+ log('File list: %O', fileList.map(f => f.path));
23
+ log('Config: %s', configFile ?? 'N/A');
24
+ log('Fix option: %s', fix);
30
25
  }
31
- const format = (_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
26
+ const format = options.format?.toLowerCase().trim();
32
27
  let hasError = false;
33
28
  const jsonOutput = [];
34
29
  for (const file of fileList) {
35
- const engine = new api_1.MLEngine(file, {
30
+ const engine = new MLEngine(file, {
36
31
  configFile,
37
32
  fix,
38
33
  locale,
@@ -52,8 +47,8 @@ async function command(files, options, apiOptions) {
52
47
  hasError = true;
53
48
  }
54
49
  if (fix) {
55
- (0, debug_1.log)('Overwrite file: %s', result.filePath);
56
- await fs_1.promises.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
50
+ log('Overwrite file: %s', result.filePath);
51
+ await fs.writeFile(result.filePath, result.fixedCode, { encoding: 'utf8' });
57
52
  process.stdout.write(`markuplint: Fix "${result.filePath}"\n`);
58
53
  }
59
54
  else {
@@ -64,8 +59,8 @@ async function command(files, options, apiOptions) {
64
59
  })));
65
60
  continue;
66
61
  }
67
- (0, debug_1.log)('Output reports');
68
- (0, output_1.output)(result, options);
62
+ log('Output reports');
63
+ output(result, options);
69
64
  }
70
65
  }
71
66
  if (format === 'json') {
@@ -74,4 +69,3 @@ async function command(files, options, apiOptions) {
74
69
  }
75
70
  return hasError;
76
71
  }
77
- exports.command = command;
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRule = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_path_1 = require("node:path");
6
- const create_rule_helper_1 = require("@markuplint/create-rule-helper");
7
- const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
8
- const util_1 = require("../../util");
9
- const install_module_1 = require("../init/install-module");
10
- const prompt_1 = require("../prompt");
1
+ import { resolve } from 'node:path';
2
+ import { isMarkuplintRepo, createRuleHelper } from '@markuplint/create-rule-helper';
3
+ import c from 'cli-color';
4
+ import { write, head } from '../../util.js';
5
+ import { installModule } from '../init/install-module.js';
6
+ import { input, select, confirm } from '../prompt.js';
11
7
  const icons = {
12
8
  README: '📝',
13
9
  index: '📜',
@@ -15,28 +11,27 @@ const icons = {
15
11
  package: '🎁',
16
12
  tsconfig: '💎',
17
13
  };
18
- async function createRule() {
19
- var _a;
20
- (0, util_1.write)((0, util_1.head)('Create a rule'));
21
- util_1.write.break();
14
+ export async function createRule() {
15
+ write(head('Create a rule'));
16
+ write.break();
22
17
  const firstChoices = [
23
18
  { name: 'Add the rule to this project', value: 'ADD_TO_PROJECT' },
24
19
  { name: 'Create the rule and publish it as a package', value: 'PUBLISH_AS_PACKAGE' },
25
20
  ];
26
- if (await (0, create_rule_helper_1.isMarkuplintRepo)()) {
21
+ if (await isMarkuplintRepo()) {
27
22
  firstChoices.push({ name: 'Contribute the new rule to markuplint core rules', value: 'CONTRIBUTE_TO_CORE' });
28
23
  }
29
- const purpose = await (0, prompt_1.select)({
24
+ const purpose = await select({
30
25
  message: 'What purpose do you create the rule for?',
31
26
  choices: firstChoices,
32
27
  });
33
28
  const dirQuestion = purpose === 'ADD_TO_PROJECT' ? 'What is the directory name?' : 'What is the plugin name?';
34
- const pluginName = purpose === 'CONTRIBUTE_TO_CORE' ? '' : await (0, prompt_1.input)(dirQuestion, /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
35
- const ruleName = await (0, prompt_1.input)('What is the rule name?', /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
29
+ const pluginName = purpose === 'CONTRIBUTE_TO_CORE' ? '' : await input(dirQuestion, /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
30
+ const ruleName = await input('What is the rule name?', /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/i);
36
31
  const core = purpose === 'CONTRIBUTE_TO_CORE'
37
32
  ? {
38
- description: await (0, prompt_1.input)('Description:'),
39
- category: await (0, prompt_1.select)({
33
+ description: await input('Description:'),
34
+ category: await select({
40
35
  message: 'Category:',
41
36
  choices: [
42
37
  { name: 'Conformance checking', value: 'validation' },
@@ -46,7 +41,7 @@ async function createRule() {
46
41
  { name: 'Style', value: 'style' },
47
42
  ],
48
43
  }),
49
- severity: await (0, prompt_1.select)({
44
+ severity: await select({
50
45
  message: 'Severity:',
51
46
  choices: [
52
47
  { name: 'error', value: 'error' },
@@ -57,29 +52,28 @@ async function createRule() {
57
52
  : undefined;
58
53
  const lang = purpose === 'CONTRIBUTE_TO_CORE'
59
54
  ? 'TYPESCRIPT'
60
- : await (0, prompt_1.select)({
55
+ : await select({
61
56
  message: 'Which language will you implement?',
62
57
  choices: [
63
58
  { name: 'TypeScript', value: 'TYPESCRIPT' },
64
59
  { name: 'JavaScript', value: 'JAVASCRIPT' },
65
60
  ],
66
61
  });
67
- const needTest = purpose === 'CONTRIBUTE_TO_CORE' ? true : await (0, prompt_1.confirm)('Do you need the test?', { initial: true });
68
- const result = await (0, create_rule_helper_1.createRuleHelper)({ purpose, pluginName, ruleName, lang, needTest, core });
62
+ const needTest = purpose === 'CONTRIBUTE_TO_CORE' ? true : await confirm('Do you need the test?', { initial: true });
63
+ const result = await createRuleHelper({ purpose, pluginName, ruleName, lang, needTest, core });
69
64
  for (const file of result.files) {
70
- output(pluginName || 'core', file.test ? '🖍 ' : (_a = icons[file.name]) !== null && _a !== void 0 ? _a : '🛡 ', file.fileName, (0, node_path_1.resolve)(file.destDir, file.fileName + file.ext));
65
+ output(pluginName || 'core', file.test ? '🖍 ' : icons[file.name] ?? '🛡 ', file.fileName, resolve(file.destDir, file.fileName + file.ext));
71
66
  }
72
67
  if (result.dependencies.length > 0) {
73
- await (0, install_module_1.installModule)(result.dependencies);
68
+ await installModule(result.dependencies);
74
69
  }
75
70
  if (result.devDependencies.length > 0) {
76
- await (0, install_module_1.installModule)(result.devDependencies, true);
71
+ await installModule(result.devDependencies, true);
77
72
  }
78
73
  }
79
- exports.createRule = createRule;
80
74
  function output(name, icon, title, path) {
81
- const _marker = cli_color_1.default.xterm(39)('✔') + ' ';
82
- const _title = (icon, title) => `${icon} ` + cli_color_1.default.bold(`${name}/${title}`);
83
- const _file = (path) => ' ' + cli_color_1.default.cyanBright(path);
84
- (0, util_1.write)(_marker + _title(icon, title) + _file(path));
75
+ const _marker = c.xterm(39)('✔') + ' ';
76
+ const _title = (icon, title) => `${icon} ` + c.bold(`${name}/${title}`);
77
+ const _file = (path) => ' ' + c.cyanBright(path);
78
+ write(_marker + _title(icon, title) + _file(path));
85
79
  }
package/lib/cli/index.js CHANGED
@@ -1,58 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const get_stdin_1 = tslib_1.__importDefault(require("get-stdin"));
5
- const debug_1 = require("../debug");
6
- const bootstrap_1 = require("./bootstrap");
7
- const command_1 = require("./command");
8
- const create_rule_1 = require("./create-rule");
9
- const init_1 = require("./init");
10
- const search_1 = tslib_1.__importDefault(require("./search"));
1
+ import getStdin from 'get-stdin';
2
+ import { verbosely } from '../debug.js';
3
+ import { cli } from './bootstrap.js';
4
+ import { command } from './command.js';
5
+ import { createRule } from './create-rule/index.js';
6
+ import { initialize } from './init/index.js';
7
+ import search from './search/index.js';
11
8
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
12
9
  (async () => {
13
- if (bootstrap_1.cli.flags.v) {
14
- bootstrap_1.cli.showVersion(); // And exit successfully.
10
+ if (cli.flags.v) {
11
+ cli.showVersion(); // And exit successfully.
15
12
  }
16
- if (bootstrap_1.cli.flags.h) {
17
- bootstrap_1.cli.showHelp(0); // And exit successfully.
13
+ if (cli.flags.h) {
14
+ cli.showHelp(0); // And exit successfully.
18
15
  }
19
- if (bootstrap_1.cli.flags.verbose) {
20
- (0, debug_1.verbosely)();
16
+ if (cli.flags.verbose) {
17
+ verbosely();
21
18
  }
22
- if (bootstrap_1.cli.flags.init) {
23
- await (0, init_1.initialize)().catch(err => {
19
+ if (cli.flags.init) {
20
+ await initialize().catch(err => {
24
21
  process.stderr.write(err + '\n');
25
22
  process.exit(1);
26
23
  });
27
24
  return;
28
25
  }
29
- if (bootstrap_1.cli.flags.createRule) {
30
- await (0, create_rule_1.createRule)().catch(err => {
26
+ if (cli.flags.createRule) {
27
+ await createRule().catch(err => {
31
28
  process.stderr.write(err + '\n');
32
29
  process.exit(1);
33
30
  });
34
31
  return;
35
32
  }
36
- const files = bootstrap_1.cli.input;
33
+ const files = cli.input;
37
34
  if (files.length > 0) {
38
- if (bootstrap_1.cli.flags.search) {
39
- await (0, search_1.default)(files, bootstrap_1.cli.flags, bootstrap_1.cli.flags.search).catch(err => {
35
+ if (cli.flags.search) {
36
+ await search(files, cli.flags, cli.flags.search).catch(err => {
40
37
  process.stderr.write(err + '\n');
41
38
  process.exit(1);
42
39
  });
43
40
  return;
44
41
  }
45
- const hasError = await (0, command_1.command)(files, bootstrap_1.cli.flags).catch(err => {
42
+ const hasError = await command(files, cli.flags).catch(err => {
46
43
  throw err;
47
44
  });
48
45
  process.exit(hasError ? 1 : 0);
49
46
  }
50
47
  if (usePipe()) {
51
- (0, get_stdin_1.default)()
48
+ getStdin()
52
49
  .then(async (stdin) => {
53
50
  if (stdin) {
54
- const hasError = await (0, command_1.command)([{ sourceCode: stdin }], {
55
- ...bootstrap_1.cli.flags,
51
+ const hasError = await command([{ sourceCode: stdin }], {
52
+ ...cli.flags,
56
53
  ignoreExt: true,
57
54
  }).catch(err => {
58
55
  process.stderr.write(err + '\n');
@@ -61,7 +58,7 @@ const search_1 = tslib_1.__importDefault(require("./search"));
61
58
  process.exit(hasError ? 1 : 0);
62
59
  }
63
60
  // result is empty
64
- bootstrap_1.cli.showHelp(1);
61
+ cli.showHelp(1);
65
62
  })
66
63
  .catch(reason => {
67
64
  // eslint-disable-next-line no-console
@@ -70,7 +67,7 @@ const search_1 = tslib_1.__importDefault(require("./search"));
70
67
  });
71
68
  }
72
69
  else {
73
- bootstrap_1.cli.showHelp(1);
70
+ cli.showHelp(1);
74
71
  }
75
72
  })();
76
73
  function usePipe() {
@@ -1,4 +1,4 @@
1
- import type { DefaultRules, Langs, RuleSettingMode } from './types';
1
+ import type { DefaultRules, Langs, RuleSettingMode } from './types.js';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export declare const langs: Record<Langs, string>;
4
4
  export declare function createConfig(langs: readonly Langs[], mode: RuleSettingMode, defaultRules: DefaultRules): Config;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createConfig = exports.langs = void 0;
4
1
  const extRExp = {
5
2
  jsx: '\\.[jt]sx?$',
6
3
  vue: '\\.vue$',
@@ -15,7 +12,7 @@ const extRExp = {
15
12
  nunjucks: '\\.nunjucks$',
16
13
  liquid: '\\.liquid$',
17
14
  };
18
- exports.langs = {
15
+ export const langs = {
19
16
  jsx: 'React (JSX)',
20
17
  vue: 'Vue',
21
18
  svelte: 'Svelte',
@@ -29,8 +26,7 @@ exports.langs = {
29
26
  nunjucks: 'Nunjucks',
30
27
  liquid: 'liquid (Shopify)',
31
28
  };
32
- function createConfig(langs, mode, defaultRules) {
33
- var _a;
29
+ export function createConfig(langs, mode, defaultRules) {
34
30
  let config = {};
35
31
  const parser = { ...config.parser };
36
32
  for (const lang of langs) {
@@ -75,7 +71,7 @@ function createConfig(langs, mode, defaultRules) {
75
71
  }
76
72
  }
77
73
  else if (mode === 'recommended') {
78
- config.extends = [...((_a = config.extends) !== null && _a !== void 0 ? _a : []), 'markuplint:recommended'];
74
+ config.extends = [...(config.extends ?? []), 'markuplint:recommended'];
79
75
  }
80
76
  else {
81
77
  const ruleNames = Object.keys(defaultRules);
@@ -92,4 +88,3 @@ function createConfig(langs, mode, defaultRules) {
92
88
  }
93
89
  return config;
94
90
  }
95
- exports.createConfig = createConfig;
@@ -1,3 +1,3 @@
1
1
  export declare function getDefaultRules(version: string): Promise<{
2
- [x: string]: import("./types").Rule;
2
+ [x: string]: import("./types.js").Rule;
3
3
  }>;
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultRules = void 0;
4
- const tslib_1 = require("tslib");
5
- const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
6
- const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
1
+ import matter from 'gray-matter';
2
+ import fetch from 'node-fetch';
7
3
  const RULES_SCHEMA_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/schema.json';
8
4
  const RULES_README_URL = 'https://raw.githubusercontent.com/markuplint/markuplint/[VERSION]/packages/@markuplint/rules/src/[NAME]/README.md';
9
- async function getDefaultRules(version) {
5
+ export async function getDefaultRules(version) {
10
6
  const json = await safeFetch(RULES_SCHEMA_URL, version);
11
7
  const rules = {};
12
8
  await Promise.all(Object.entries(json.definitions.rules.properties).map(async ([name, rule]) => {
13
- var _a, _b, _c, _d;
14
9
  const json = await safeFetch(rule.$ref.replace('/main/', '/[VERSION]/'), version);
15
- let severity = (_c = (_b = (_a = (Array.isArray(json.oneOf) ? json.oneOf : []).find((val) => val.properties)) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.severity) === null || _c === void 0 ? void 0 : _c.default;
10
+ let severity = (Array.isArray(json.oneOf) ? json.oneOf : []).find((val) => val.properties)?.properties
11
+ ?.severity?.default;
16
12
  let category = json._category;
17
13
  if (severity == null || category == null) {
18
14
  const data = await getCatAndSeverityFromLegacy(version, name);
19
15
  severity = data.severity;
20
16
  category = data.category;
21
17
  }
22
- const defaultValue = severity === 'warning' ? false : (_d = json.definitions.value.default) !== null && _d !== void 0 ? _d : true;
18
+ const defaultValue = severity === 'warning' ? false : json.definitions.value.default ?? true;
23
19
  rules[name] = {
24
20
  defaultValue,
25
21
  category,
@@ -27,10 +23,9 @@ async function getDefaultRules(version) {
27
23
  }));
28
24
  return rules;
29
25
  }
30
- exports.getDefaultRules = getDefaultRules;
31
26
  async function safeFetch(baseUrl, version, type = 'json') {
32
27
  const url = baseUrl.replace('[VERSION]', `v${version}`);
33
- const res = await (0, node_fetch_1.default)(url);
28
+ const res = await fetch(url);
34
29
  if (!res.ok) {
35
30
  return safeFetch(baseUrl, '3.0.0', type);
36
31
  }
@@ -38,7 +33,7 @@ async function safeFetch(baseUrl, version, type = 'json') {
38
33
  return (await res.json());
39
34
  }
40
35
  const md = await res.text();
41
- const { data } = (0, gray_matter_1.default)(md);
36
+ const { data } = matter(md);
42
37
  return data;
43
38
  }
44
39
  /**
@@ -1,16 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initialize = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const util_1 = tslib_1.__importDefault(require("util"));
8
- const util_2 = require("../../util");
9
- const prompt_1 = require("../prompt");
10
- const create_config_1 = require("./create-config");
11
- const get_default_rules_1 = require("./get-default-rules");
12
- const install_module_1 = require("./install-module");
13
- const writeFile = util_1.default.promisify(fs_1.default.writeFile);
1
+ import fs from 'node:fs';
2
+ import module from 'node:module';
3
+ import path from 'node:path';
4
+ import util from 'node:util';
5
+ import { head, write, error } from '../../util.js';
6
+ import { confirm, confirmSequence, multiSelect } from '../prompt.js';
7
+ import { createConfig, langs } from './create-config.js';
8
+ import { getDefaultRules } from './get-default-rules.js';
9
+ import { installModule, selectModules } from './install-module.js';
10
+ const require = module.createRequire(import.meta.url);
11
+ const writeFile = util.promisify(fs.writeFile);
14
12
  const ruleCategories = {
15
13
  validation: {
16
14
  message: 'Are you going to conformance check according to HTML standard?',
@@ -28,19 +26,19 @@ const ruleCategories = {
28
26
  message: 'Are you going to check for the code styles?',
29
27
  },
30
28
  };
31
- async function initialize() {
32
- (0, util_2.write)((0, util_2.head)('Initialization'));
33
- util_2.write.break();
34
- const selectedLangs = await (0, prompt_1.multiSelect)({
29
+ export async function initialize() {
30
+ write(head('Initialization'));
31
+ write.break();
32
+ const selectedLangs = await multiSelect({
35
33
  message: 'Which do you use template engines?',
36
- choices: Object.entries(create_config_1.langs).map(([key, name]) => ({ name, value: key })),
34
+ choices: Object.entries(langs).map(([key, name]) => ({ name, value: key })),
37
35
  });
38
- const autoInstall = await (0, prompt_1.confirm)('May I install them automatically?');
39
- const customize = await (0, prompt_1.confirm)('Do you customize rules?');
36
+ const autoInstall = await confirm('May I install them automatically?');
37
+ const customize = await confirm('Do you customize rules?');
40
38
  let ruleSettingMode = 'none';
41
39
  if (customize) {
42
40
  const categories = Object.keys(ruleCategories);
43
- const selectedCategories = await (0, prompt_1.confirmSequence)(categories.map(catName => {
41
+ const selectedCategories = await confirmSequence(categories.map(catName => {
44
42
  const cat = ruleCategories[catName];
45
43
  return {
46
44
  message: cat.message,
@@ -51,33 +49,31 @@ async function initialize() {
51
49
  .map(([name, enabled]) => (enabled ? name : ''))
52
50
  .filter((name) => !!name);
53
51
  }
54
- else if (await (0, prompt_1.confirm)('Does it import the recommended config?')) {
52
+ else if (await confirm('Does it import the recommended config?')) {
55
53
  ruleSettingMode = 'recommended';
56
54
  }
57
55
  let defaultRules = {};
58
56
  if (ruleSettingMode !== 'recommended') {
59
- // eslint-disable-next-line @typescript-eslint/no-var-requires
60
57
  const rulesVersion = require('../../../package.json').version;
61
- defaultRules = await (0, get_default_rules_1.getDefaultRules)(rulesVersion);
58
+ defaultRules = await getDefaultRules(rulesVersion);
62
59
  }
63
- const config = (0, create_config_1.createConfig)(selectedLangs, ruleSettingMode, defaultRules);
64
- const filePath = path_1.default.resolve(process.cwd(), '.markuplintrc');
60
+ const config = createConfig(selectedLangs, ruleSettingMode, defaultRules);
61
+ const filePath = path.resolve(process.cwd(), '.markuplintrc');
65
62
  await writeFile(filePath, JSON.stringify(config, null, 2), { encoding: 'utf-8' });
66
- (0, util_2.write)(`✨Created: ${filePath}`);
63
+ write(`✨Created: ${filePath}`);
67
64
  if (autoInstall) {
68
- (0, util_2.write)('Install automatically');
69
- const modules = (0, install_module_1.selectModules)(selectedLangs);
70
- const result = await (0, install_module_1.installModule)(modules, true).catch(e => new Error(e));
65
+ write('Install automatically');
66
+ const modules = selectModules(selectedLangs);
67
+ const result = await installModule(modules, true).catch(e => new Error(e));
71
68
  if (result instanceof Error) {
72
- util_2.error.exit();
69
+ error.exit();
73
70
  return;
74
71
  }
75
72
  if (result.alreadyExists) {
76
- (0, util_2.write)('Modules are installed already.');
73
+ write('Modules are installed already.');
77
74
  }
78
75
  else {
79
- (0, util_2.write)('✨ Success');
76
+ write('✨ Success');
80
77
  }
81
78
  }
82
79
  }
83
- exports.initialize = initialize;
@@ -1,4 +1,4 @@
1
- import type { Langs } from './types';
1
+ import type { Langs } from './types.js';
2
2
  export type InstallModuleResult = {
3
3
  success: boolean;
4
4
  alreadyExists: boolean;
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installModule = exports.selectModules = void 0;
4
- const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
- const cli_color_1 = tslib_1.__importDefault(require("cli-color"));
1
+ import { spawnSync } from 'node:child_process';
2
+ import c from 'cli-color';
7
3
  // @ts-ignore
8
- const detect_installed_1 = tslib_1.__importDefault(require("detect-installed"));
9
- const has_yarn_1 = tslib_1.__importDefault(require("has-yarn"));
10
- function selectModules(selectedLangs) {
4
+ import detectInstalled from 'detect-installed';
5
+ import hasYarn from 'has-yarn';
6
+ export function selectModules(selectedLangs) {
11
7
  const modules = ['markuplint', ...selectedLangs.map(lang => `@markuplint/${lang}-parser`)];
12
8
  if (selectedLangs.includes('vue')) {
13
9
  modules.push('@markuplint/vue-spec');
@@ -17,8 +13,7 @@ function selectModules(selectedLangs) {
17
13
  }
18
14
  return modules;
19
15
  }
20
- exports.selectModules = selectModules;
21
- async function installModule(module, dev = false) {
16
+ export async function installModule(module, dev = false) {
22
17
  module = module.map(m => m.trim());
23
18
  const uninstallMods = [];
24
19
  try {
@@ -38,19 +33,19 @@ async function installModule(module, dev = false) {
38
33
  alreadyExists: true,
39
34
  };
40
35
  }
41
- const mod = (0, has_yarn_1.default)() ? 'yarn' : 'npm';
42
- const installOpt = (0, has_yarn_1.default)() ? 'add' : 'install';
36
+ const mod = hasYarn() ? 'yarn' : 'npm';
37
+ const installOpt = hasYarn() ? 'add' : 'install';
43
38
  const opt = [installOpt];
44
39
  if (dev) {
45
40
  opt.push('-D');
46
41
  }
47
- if (!(0, has_yarn_1.default)()) {
42
+ if (!hasYarn()) {
48
43
  opt.push('--legacy-peer-deps');
49
44
  }
50
45
  opt.push(...uninstallMods);
51
46
  return new Promise((resolve, reject) => {
52
- process.stdout.write(cli_color_1.default.blackBright(`${mod} ${opt.join(' ')}\n`));
53
- const result = (0, child_process_1.spawnSync)(mod, opt, { stdio: 'inherit' });
47
+ process.stdout.write(c.blackBright(`${mod} ${opt.join(' ')}\n`));
48
+ const result = spawnSync(mod, opt, { stdio: 'inherit' });
54
49
  if (result.error || result.status !== 0) {
55
50
  const message = 'Error running command.';
56
51
  const error = new Error(message);
@@ -63,11 +58,10 @@ async function installModule(module, dev = false) {
63
58
  });
64
59
  });
65
60
  }
66
- exports.installModule = installModule;
67
61
  function isInstalled(module) {
68
62
  return new Promise((resolve, reject) => {
69
63
  try {
70
- (0, detect_installed_1.default)(module, {
64
+ detectInstalled(module, {
71
65
  local: true,
72
66
  }).then((exists) => {
73
67
  resolve(exists);
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,3 +1,3 @@
1
- import type { CLIOptions } from './bootstrap';
2
- import type { MLResultInfo } from '../types';
1
+ import type { CLIOptions } from './bootstrap.js';
2
+ import type { MLResultInfo } from '../types.js';
3
3
  export declare function output(results: MLResultInfo, options: CLIOptions): void;
package/lib/cli/output.js CHANGED
@@ -1,34 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.output = void 0;
4
- const tslib_1 = require("tslib");
5
- const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
6
- const reporter_1 = require("../reporter");
7
- function output(results, options) {
8
- var _a;
9
- const format = (_a = options.format) !== null && _a !== void 0 ? _a : 'Standard';
1
+ import stripAnsi from 'strip-ansi';
2
+ import { simpleReporter, standardReporter, githubReporter } from '../reporter/index.js';
3
+ export function output(results, options) {
4
+ const format = options.format ?? 'Standard';
10
5
  let out;
11
6
  switch (format.toLowerCase()) {
12
7
  case 'json': {
13
8
  return;
14
9
  }
15
10
  case 'simple': {
16
- out = (0, reporter_1.simpleReporter)(results, options);
11
+ out = simpleReporter(results, options);
17
12
  break;
18
13
  }
19
14
  case 'github': {
20
- out = (0, reporter_1.githubReporter)(results);
15
+ out = githubReporter(results);
21
16
  break;
22
17
  }
23
18
  default: {
24
- out = (0, reporter_1.standardReporter)(results, options);
19
+ out = standardReporter(results, options);
25
20
  }
26
21
  }
27
22
  if (out.length === 0) {
28
23
  return;
29
24
  }
30
25
  let msg = `${out.join('\n')}\n`;
31
- msg = options.color ? msg : (0, strip_ansi_1.default)(msg);
26
+ msg = options.color ? msg : stripAnsi(msg);
32
27
  // If it has errors, Write to `stderr` and failure and exit.
33
28
  if (results.violations.length > 0) {
34
29
  process.stderr.write(msg);
@@ -37,4 +32,3 @@ function output(results, options) {
37
32
  }
38
33
  process.stdout.write(msg);
39
34
  }
40
- exports.output = output;