History

Merge pull request #1421 from MasterEnoc/npm

Update Npm to 7.1.2

Simon Legner committed 5 years ago

Commit 5ca311f2 parents 1af4a97 2386c4d3 files · +70 −56Browse files

Unified · Split

3 files
  1. lib/docs/filters/npm/clean_html.rb +5 −24
  2. lib/docs/filters/npm/entries.rb +16 −26
  3. lib/docs/scrapers/npm.rb +49 −6
lib/docs/filters/npm/clean_html.rb+5−24
@@ -2,36 +2,17 @@ module Docs · 1 unmodified line
2 class Npm2 class Npm
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 if root_page?
6 css('#enterprise', '#policies', '#viewAll').remove
7 else
8 @doc = doc.at_css('#page')
9 css('meta', '.colophon').remove
10 end
11 5
12 css('a.deep-link[id]', 'a.anchor[id]').each do |node|6 css('.dZYhXG', '.fONtKn').remove
13 node.parent['id'] = node['id']
14 node.remove
15 end
16 7
17 css('> section').each do |node|8 css('.kSYjyK').remove
18 node.before(node.children).remove
19 end
20 9
21 css('pre.editor').each do |node|10 css('.cDvIaH').remove
22 node.inner_html = node.inner_html.gsub(/<\/div>(?!\n|\z)/, "</div>\n")
23 end
24 11
25 css('h1 + h1.subtitle').each do |node|12 css('.jRndWL').remove_attribute('style')
26 node.name = 'p'
27 node.inner_html += '.'
28 end
29
30 css('pre').each do |node|
31 node.content = node.content
32 end
33 13
34 doc14 doc
15
35 end16 end
36 end17 end
37 end18 end
lib/docs/filters/npm/entries.rb+16−26
@@ -1,43 +1,33 @@
1module Docs1module Docs
2 class Npm2 class Npm
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name
5 if slug.start_with?('api') && at_css('pre').content =~ /\A\s*npm\.([\w\-]+\.)*[\w\-]+/
6 name = $&.strip
7 else
8 name = at_css('nav > section.active a.active').content
9 end
10 4
11 name << ' (CLI)' if slug.start_with?('cli')5 def get_name
12 name6 at_css('h1').content
13 end7 end
14 8
15 def get_type9 def get_type
16 case slug10 at_css('.active').content
17 when 'files/package.json'
18 'package.json'
19 when 'misc/config'
20 'Config'
21 else
22 at_css('nav > section.active > h2').content
23 end
24 end11 end
25 12
26 def additional_entries13 def additional_entries
27 case slug14 entries = []
28 when 'files/package.json'15
29 css('#page > h2').each_with_object [] do |node, entries|16 if name == 'config'
30 next if node.content =~ /\A[A-Z]/17 css('h4').each do |node|
31 entries << ["package.json: #{node.content}", node.at_css('.anchor')['id']]18 entries << [node['id'], slug + '#' + node['id'], 'Config Settings']
32 end19 end
33 when 'misc/config'20 end
34 css('h2:contains("Config Settings") ~ h3').map do |node|21
35 ["config: #{node.content}", node.at_css('.anchor')['id']]22 if name == 'package.json'
23 css('h3').each do |node|
24 entries << [node['id'], slug + '#' + node['id'], 'Package.json Settings']
36 end25 end
37 else
38 []
39 end26 end
27
28 entries
40 end29 end
30
41 end31 end
42 end32 end
43end33end
lib/docs/scrapers/npm.rb+49−6
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
2 class Npm < UrlScraper2 class Npm < UrlScraper
3 self.name = 'npm'3 self.name = 'npm'
4 self.type = 'npm'4 self.type = 'npm'
5 self.release = '6.4.0'5 self.release = '7.1.2'
6 self.base_url = 'https://docs.npmjs.com/'6 self.base_url = 'https://docs.npmjs.com/'
7 self.force_gzip = true7 self.force_gzip = true
8 self.links = {8 self.links = {
@@ -10,14 +10,20 @@ module Docs · 1 unmodified line
10 code: 'https://github.com/npm/npm'10 code: 'https://github.com/npm/npm'
11 }11 }
12 12
13 html_filters.push 'npm/entries', 'npm/clean_html', 'title'13 html_filters.push 'npm/entries', 'npm/clean_html'
14 14
15 options[:max_image_size] = 130_00015 options[:max_image_size] = 130_000
16 options[:container] = ->(filter) { filter.root_page? ? '.toc' : nil }
17 options[:title] = false
18 options[:root_title] = 'npm'
19 16
20 options[:skip] = %w(all misc/index)17 options[:skip] = [
18 'all',
19 'misc/index',
20 'cli',
21 'orgs/',
22 'removing-members-from-your-org',
23 'adding-members-to-your-org',
24 'downloading-and-installing-packages'
25 ]
26
21 options[:skip_patterns] = [27 options[:skip_patterns] = [
22 /\Aenterprise/,28 /\Aenterprise/,
23 /\Acompany/,29 /\Acompany/,
@@ -30,8 +36,45 @@ module Docs · 6 unmodified lines
30 npm is a trademark of npm, Inc.36 npm is a trademark of npm, Inc.
31 HTML37 HTML
32 38
39 # fix duplicates
40 options[:fix_urls] = -> (url) do
41 url.sub!('private-modules/intro', 'creating-and-publishing-private-packages')
42 url.sub!('cli/audit', 'cli/v6/commands/npm-audit')
43 url.sub!('cli/uninstall', 'cli/v6/commands/npm-uninstall')
44 url.sub!('cli/npm', 'cli/v6/commands/npm')
45 url.sub!('cli-documentation', 'cli/v6')
46 url.sub!('misc/registry', 'cli/v6/using-npm/registry')
47 url.sub!('cli/adduser', 'cli/v6/commands/npm-adduser')
48 url.sub!('cli/profile', 'cli/v6/commands/npm-profile')
49 url.sub!('cli/token', 'cli/v6/commands/npm-token')
50 url.sub!('cli/publish', 'cli/v6/commands/npm-publish')
51 url.sub!('cli/unpublish', 'cli/v6/commands/npm-unpublish')
52 url.sub!('cli/deprecate', 'cli/v6/commands/npm-deprecate')
53 url.sub!('cli/access', 'cli/v6/commands/npm-access')
54 url.sub!('misc/config', 'cli/v6/using-npm/config')
55 url.sub!('misc/developers', 'cli/v6/using-npm/developers')
56 url.sub!('managing-team-access-to-packages', 'managing-team-access-to-organization-packages')
57 url.sub!('accepting-or-rejecting-an-org-invitation', 'accepting-or-rejecting-an-organization-invitation')
58 url.sub!('org-roles-and-permissions', 'organization-roles-and-permissions')
59 url.sub!('upgrading-to-a-paid-org-plan', 'upgrading-to-a-paid-organization-plan')
60 url.sub!('files/package.json', 'cli/v6/configuring-npm/package-json')
61 url.sub!('managing-team-access-to-org-packages', 'managing-team-access-to-organization-packages')
62 url.sub!('about-package-json-and-package-lock-json-files', 'creating-a-package-json-file')
63 url.sub!('cli/team', 'cli/v6/commands/npm-team')
64 url.sub!('cli/version', 'cli/v6/commands/npm-version')
65 url.sub!('creating-a-packge-json-file', 'cli/v6/configuring-npm/package-json')
66 url.sub!('cli/outdated', 'cli/v6/commands/npm-outdated')
67 url.sub!('cli/owner', 'cli/v6/commands/npm-owner')
68 url.sub!('cli/install', 'cli/v6/commands/npm-install')
69 url.sub!('cli/update', 'cli/v6/commands/npm-update')
70 url.sub!('cli/config', 'cli/v6/commands/npm-config')
71 url.sub!('cli/dist-tag', 'cli/v6/commands/npm-dist-tag')
72 url
73 end
74
33 def get_latest_version(opts)75 def get_latest_version(opts)
34 get_latest_github_release('npm', 'cli', opts)76 get_latest_github_release('npm', 'cli', opts)
35 end77 end
78
36 end79 end
37end80end