Skip to content

Commit

Permalink
update: generation cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
TOsmanov committed Nov 29, 2024
1 parent 7ffe44e commit bec9c9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
27 changes: 24 additions & 3 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
const { Command } = require('commander')
const path = require('path')
const fs = require('fs')
const childProcess = require('child_process')

const program = new Command()
const cwd = process.cwd().toString()
const vscodeSettings = '.vscode/settings.json'
Expand Down Expand Up @@ -247,13 +249,15 @@ function createConfig (mode = 'full', source = '', project = '', configPath = ''
validateIntLinksConf.workingDir = undefined
const includesMapPath = path.relative('./', includesMap)
const content = []
json.globs = listOfFiles
content.push('// @ts-check\n\n"use strict";\n\n')
content.push("const path = require('path')")
content.push("const repoName = require('git-repo-name')")
content.push(`const json = ${JSON.stringify(json, null, 4)}`)
content.push('json.config[\'validate-internal-links\'].project = repoName.sync({cwd: __dirname})')
content.push('json.config[\'validate-internal-links\'].workingDir = __dirname')
content.push(`json.config['validate-internal-links'].includesMap = require("./${includesMapPath}")`)
content.push(`json.config['validate-internal-links'].includesMap = "./${includesMapPath}"`)

content.push('\n\nmodule.exports = json')

try {
Expand All @@ -275,14 +279,31 @@ function createConfig (mode = 'full', source = '', project = '', configPath = ''
console.log(`${mode} markdownlint config '.markdownlint-cli2.jsonc' created successfully!`)
}

if (listOfFiles && vscode) {
const configExist = initVSCodeSettings(listOfFiles)
if (vscode) {
// disabling globs used by the markdownlint extension
const configExist = initVSCodeSettings([])
if (configExist) {
console.log(`${vscodeSettings} config updated successfully!`)
} else {
console.log(`${vscodeSettings} config created successfully!`)
}
}

// write package.json
const packageJSONforCJS = {
dependencies: {
'markdownlint-rules-foliant': 'latest',
'git-repo-name': '^1.0.1'
}
}
fs.writeFileSync(path.resolve(cwd, 'package.json'), JSON.stringify(packageJSONforCJS, null, 4), { mode: 0o777 })

// install dependencies
childProcess.execSync('npm i .', { stdio: [0, 1, 2] })

// remove package.json
fs.rmSync(path.resolve(cwd, 'package.json'))
fs.rmSync(path.resolve(cwd, 'package-lock.json'))
}

function initVSCodeSettings (listOfFiles = []) {
Expand Down
2 changes: 1 addition & 1 deletion linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const workingDirOption = new Option('-w --working-dir <working-dir>',
.default('')
const vsCodeOption = new Option('--vs-code',
'generate settings.json for vs code').default(false)
const formatOptions = new Option('--format',
const formatOptions = new Option('--format <format>',
'format of the config file')
.default('jsonc')

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"scripts": {
"lint": "eslint .",
"test": "jest --runInBand",
"prepare": "husky install",
"validate": "npm run lint && npm test"
},
"dependencies": {
Expand Down

0 comments on commit bec9c9d

Please sign in to comment.