Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Karrys <luke@lukekarrys.com>2022-03-31 03:39:21 +0300
committerGar <wraithgar@github.com>2022-04-06 19:26:45 +0300
commit03f36bf8c30b713e86f8e0b7e6643b68d74f7d91 (patch)
treeafc33df0328cfda57f8cb5e4a7126fc615f00281 /scripts
parent840c338aa6aba7dc39d9d3afba075701e3979362 (diff)
chore(docs): move scripts and refactor
All docs related scripts are now located in the docs workspace
Diffstat (limited to 'scripts')
-rw-r--r--scripts/config-doc-command.js140
-rw-r--r--scripts/config-doc.js54
-rw-r--r--scripts/docs-build.js45
3 files changed, 0 insertions, 239 deletions
diff --git a/scripts/config-doc-command.js b/scripts/config-doc-command.js
deleted file mode 100644
index efc831561..000000000
--- a/scripts/config-doc-command.js
+++ /dev/null
@@ -1,140 +0,0 @@
-const { definitions } = require('../lib/utils/config/index.js')
-const cmdAliases = require('../lib/utils/cmd-list').aliases
-const { writeFileSync, readFileSync } = require('fs')
-const { resolve } = require('path')
-
-const configDoc = process.argv[2]
-const commandFile = process.argv[3]
-
-const TAGS = {
- CONFIG: {
- START: '<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->',
- END: '<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->',
- },
- USAGE: {
- START: '<!-- AUTOGENERATED USAGE DESCRIPTIONS START -->',
- END: '<!-- AUTOGENERATED USAGE DESCRIPTIONS END -->',
- },
-}
-
-// Note: commands without params skip this whole process.
-const {
- params,
- usage,
-} = require(resolve(commandFile))
-
-const describeAll = (content) =>
- content.map(name => definitions[name].describe()).join(
- '\n\n<!-- automatically generated, do not edit manually -->\n' +
- '<!-- see lib/utils/config/definitions.js -->\n\n'
- )
-
-const describeUsage = ({ usage }) => {
- const synopsis = []
-
- // Grab the command name from the *.md filename
- // NOTE: We cannot use the name property command file because in the case of
- // `npx` the file being used is `lib/commands/exec.js`
- const commandName = configDoc.split('/').pop().split('.')[0].replace('npm-', '')
- synopsis.push('\n```bash')
-
- if (commandName) {
- // special case for `npx`:
- // `npx` is not technically a command in and of itself,
- // so it just needs the usage and parameters of npm exec, and none of the aliases
- if (commandName === 'npx') {
- synopsis.push(usage.map(usageInfo => `npx ${usageInfo}`).join('\n'))
- } else {
- const baseCommand = `npm ${commandName}`
- if (!usage) {
- synopsis.push(baseCommand)
- } else {
- synopsis.push(usage.map(usageInfo => `${baseCommand} ${usageInfo}`).join('\n'))
- }
-
- const aliases = Object.keys(cmdAliases).reduce((p, c) => {
- if (cmdAliases[c] === commandName) {
- p.push(c)
- }
- return p
- }, [])
-
- if (aliases.length === 1) {
- synopsis.push('')
- synopsis.push(`alias: ${aliases[0]}`)
- } else if (aliases.length > 1) {
- synopsis.push('')
- synopsis.push(`aliases: ${aliases.join(', ')}`)
- }
- }
- } else {
- console.error(`could not determine command name from ${commandFile}`)
- }
-
- synopsis.push('```')
- return synopsis.join('\n')
-}
-
-const addBetweenTags = (
- doc,
- startTag,
- endTag,
- body,
- sourceFilepath = 'lib/utils/config/definitions.js') => {
- const startSplit = doc.split(startTag)
-
- if (startSplit.length !== 2) {
- throw new Error('Did not find exactly one start tag')
- }
-
- const endSplit = startSplit[1].split(endTag)
- if (endSplit.length !== 2) {
- throw new Error('Did not find exactly one end tag')
- }
-
- return [
- startSplit[0],
- startTag,
- '\n<!-- automatically generated, do not edit manually -->\n' +
- '<!-- see ' + sourceFilepath + ' -->\n',
- body,
- '\n\n<!-- automatically generated, do not edit manually -->\n' +
- '<!-- see ' + sourceFilepath + ' -->',
- '\n\n',
- endTag,
- endSplit[1],
- ].join('')
-}
-
-const addDescriptions = doc =>
- addBetweenTags(doc, TAGS.CONFIG.START, TAGS.CONFIG.END, describeAll(params))
-
-const addUsageDescriptions = doc =>
- addBetweenTags(doc, TAGS.USAGE.START, TAGS.USAGE.END,
- describeUsage({ usage }),
- commandFile
- )
-
-try {
- // always write SOMETHING so that Make sees the file is up to date.
- const doc = readFileSync(configDoc, 'utf8')
- const hasTag = doc.includes(TAGS.CONFIG.START)
- const hasUsageTag = doc.includes(TAGS.USAGE.START)
-
- if (params && params.length) {
- let newDoc = hasTag ? addDescriptions(doc) : doc
- newDoc = hasUsageTag ? addUsageDescriptions(newDoc) : newDoc
-
- if (!hasTag) {
- console.error('WARNING: did not find config description section', configDoc)
- }
-
- if ((usage && usage.length) && !hasUsageTag) {
- console.error('WARNING: did not find usage description section', configDoc)
- }
- writeFileSync(configDoc, newDoc)
- }
-} catch (err) {
- console.error(`WARNING: file cannot be open: ${configDoc}`)
- console.error(err)
-}
diff --git a/scripts/config-doc.js b/scripts/config-doc.js
deleted file mode 100644
index b14baa381..000000000
--- a/scripts/config-doc.js
+++ /dev/null
@@ -1,54 +0,0 @@
-const { shorthands, describeAll } = require('../lib/utils/config/index.js')
-const { writeFileSync, readFileSync } = require('fs')
-const { resolve } = require('path')
-const configDoc = resolve(__dirname, '../docs/content/using-npm/config.md')
-
-const addBetweenTags = (doc, startTag, endTag, body) => {
- const startSplit = doc.split(startTag)
- if (startSplit.length !== 2) {
- throw new Error('Did not find exactly one start tag')
- }
-
- const endSplit = startSplit[1].split(endTag)
- if (endSplit.length !== 2) {
- throw new Error('Did not find exactly one end tag')
- }
-
- return [
- startSplit[0],
- startTag,
- '\n<!-- automatically generated, do not edit manually -->\n' +
- '<!-- see lib/utils/config/definitions.js -->\n',
- body,
- '\n\n<!-- automatically generated, do not edit manually -->\n' +
- '<!-- see lib/utils/config/definitions.js -->\n',
- endTag,
- endSplit[1],
- ].join('')
-}
-
-const addDescriptions = doc => {
- const startTag = '<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->'
- const endTag = '<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->'
- return addBetweenTags(doc, startTag, endTag, describeAll())
-}
-
-const addShorthands = doc => {
- const startTag = '<!-- AUTOGENERATED CONFIG SHORTHANDS START -->'
- const endTag = '<!-- AUTOGENERATED CONFIG SHORTHANDS END -->'
- const body = Object.entries(shorthands)
- .sort(([shorta, expansiona], [shortb, expansionb]) => {
- // sort by what they're short FOR
- return expansiona.join(' ').localeCompare(expansionb.join(' '), 'en') ||
- shorta.localeCompare(shortb, 'en')
- })
- .map(([short, expansion]) => {
- const dash = short.length === 1 ? '-' : '--'
- return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
- }).join('\n')
- return addBetweenTags(doc, startTag, endTag, body)
-}
-
-const doc = readFileSync(configDoc, 'utf8')
-writeFileSync(configDoc, addDescriptions(addShorthands(doc)))
-console.log(`updated docs/content/using-npm/config.md`)
diff --git a/scripts/docs-build.js b/scripts/docs-build.js
deleted file mode 100644
index c380b4b76..000000000
--- a/scripts/docs-build.js
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env node
-
-var fs = require('fs')
-var marked = require('marked-man')
-var npm = require('../lib/npm.js')
-var args = process.argv.slice(2)
-var src = args[0]
-var dest = args[1] || src
-
-fs.readFile(src, 'utf8', function (err, data) {
- if (err) {
- return console.log(err)
- }
-
- function frontmatter (match, p1) {
- const fm = { }
-
- p1.split(/\r?\n/).forEach((kv) => {
- const result = kv.match(/^([^\s:]+):\s*(.*)/)
- if (result) {
- fm[result[1]] = result[2]
- }
- })
-
- return `# ${fm.title}(${fm.section}) - ${fm.description}`
- }
-
- function replacer (match, p1) {
- return 'npm help ' + p1.replace(/npm /, '')
- }
-
- var result = data.replace(/@VERSION@/g, npm.version)
- .replace(/^<!--.*-->$/gm, '')
- .replace(/^---\n([\s\S]+\n)---/, frontmatter)
- .replace(/\[([^\]]+)\]\(\/commands\/([^)]+)\)/g, replacer)
- .replace(/\[([^\]]+)\]\(\/configuring-npm\/([^)]+)\)/g, replacer)
- .replace(/\[([^\]]+)\]\(\/using-npm\/([^)]+)\)/g, replacer)
- .trim()
-
- fs.writeFile(dest, marked(result), 'utf8', function (err) {
- if (err) {
- return console.log(err)
- }
- })
-})