diff --git a/.gitignore b/.gitignore index dbcbeb867c..11287bc028 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ # npm specific node_modules +npm-debug.log diff --git a/.markdownlintrc b/.markdownlintrc new file mode 100644 index 0000000000..26260b73a8 --- /dev/null +++ b/.markdownlintrc @@ -0,0 +1,10 @@ +{ + "default": true, + "MD003": { "style": "atx" }, + "MD007": { "indent": 4 }, + "MD013": { "line_length": 200 }, + "MD033": false, + "MD034": false, + "no-hard-tabs": false, + "whitespace": false +} diff --git a/.travis.yml b/.travis.yml index 5b1bfd24f8..8f4055fb77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,13 @@ sudo: false -cache: bundler +language: node_js -language: ruby +node_js: + - 'stable' -rvm: -- 2.2.2 - -install: -- bundle -- . $HOME/.nvm/nvm.sh -- nvm install 5.0 -- nvm use 5.0 -- npm install rubenvereecken/tldr-lint - -gemfile: -- Gemfile - -script: -- make lint +cache: + directories: + - node_modules after_success: - bash scripts/build.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08f0036b16..44091c1362 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,13 +74,11 @@ Detailed explanation: git remote add upstream https://github.com/tldr-pages/tldr ``` -2. Setup Ruby, Rubygems, bundler, Git pre-commit hooks with Markdown linter. +2. Setup pre-commit hooks with Markdown and TLDR linter. ```bash - # Assuming Ruby is set up - # Install bundler Ruby gem - gem install bundler - make setup + # Assuming you have NodeJS + npm install ``` 3. If you cloned a while ago, get the latest changes from upstream: diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 20c82bd333..0000000000 --- a/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -group :development, :test do - gem 'mdl' -end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 59328c9094..0000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,19 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - kramdown (1.9.0) - mdl (0.2.1) - kramdown (~> 1.5, >= 1.5.0) - mixlib-cli (~> 1.5, >= 1.5.0) - mixlib-config (~> 2.1, >= 2.1.0) - mixlib-cli (1.5.0) - mixlib-config (2.2.1) - -PLATFORMS - ruby - -DEPENDENCIES - mdl - -BUNDLED WITH - 1.11.2 diff --git a/Makefile b/Makefile deleted file mode 100644 index 38d3ab2f2c..0000000000 --- a/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -default: lint - -index: - @echo "WARNING!" - @echo "Index rebuilding is deprecated." - @echo "You should not do it, unless you understand why you doing this." - @echo - @TLDRHOME=`pwd` ./scripts/build_index.rb - @echo "Index rebuilt." - -setup: prerequisites hooks deps - -prerequisites: - @echo - @echo "IMPORTANT!" - @echo "Before setting up hooks, make sure you have read Contributing Guidelines" - @echo "https://github.com/tldr-pages/tldr/blob/master/CONTRIBUTING.md#submitting-a-pull-request" - @echo - @echo "TL;DR:" - @echo "1. Install Ruby suitable for your system" - @echo "2. Run 'gem install bundler'" - @echo "3. Install node 5.x" - @echo "4. Install npm" - @echo - -hooks: - @cp ./scripts/pre-commit .git/hooks - @chmod +x .git/hooks/pre-commit - @echo "Git pre-commit hook installed." - -deps: - @bundle - @npm install rubenvereecken/tldr-lint - @echo "OK" - -lint: - @`pwd`/node_modules/.bin/tldr-lint ./pages - @bundle exec mdl --style ./scripts/markdown-style.rb pages - -.PHONY: default index setup prerequisites hooks deps lint diff --git a/package.json b/package.json new file mode 100644 index 0000000000..8f47fbfecf --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "tldr", + "version": "1.0.0", + "description": "Simplified, community-driven man pages", + "dependencies": { + "glob": "^6.0.4", + "markdownlint-cli": "^0.0.2", + "tldr-lint": "^0.0.7", + "husky": "^0.10.2" + }, + "scripts": { + "precommit": "npm test", + "lint-markdown": "markdownlint pages/**/*.md", + "lint-tldr": "tldr-lint ./pages", + "test": "markdownlint pages/**/*.md && tldr-lint ./pages", + "build-index": "node ./scripts/build-index.js > pages/index.json" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tldr-pages/tldr.git" + }, + "author": "Romain Prieto", + "private": true, + "license": "MIT", + "bugs": { + "url": "https://github.com/tldr-pages/tldr/issues" + }, + "homepage": "http://tldr-pages.github.io" +} diff --git a/scripts/build-index.js b/scripts/build-index.js new file mode 100644 index 0000000000..1a890ff01d --- /dev/null +++ b/scripts/build-index.js @@ -0,0 +1,47 @@ +'use strict'; + +var glob = require("glob"); + +function parsePlatform(pagefile) { + return pagefile.split(/\//)[1]; +} + +function parsePagename(pagefile) { + return pagefile.split(/\//)[2].replace(/\.md$/, ''); +} + +function buildShortPagesIndex(files) { + var reducer = function(index, file) { + var os = parsePlatform(file); + var page = parsePagename(file); + if (index[page]) { + index[page].push(os); + } else { + index[page] = [os]; + } + return index; + }; + + return files.reduce(reducer, {}); +} + +function buildPagesIndex(shortIndex) { + return Object.keys(shortIndex) + .sort() + .map(function(page) { + return { + name: page, + platform: shortIndex[page] + }; + }); +} + +function saveIndex(index) { + console.log(JSON.stringify(index)); +} + +glob("pages/**/*.md", function (er, files) { + var shortIndex = buildShortPagesIndex(files); + var index = buildPagesIndex(shortIndex); + saveIndex(index); +}); diff --git a/scripts/build.sh b/scripts/build.sh index 4630748ef0..daaa754630 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -17,7 +17,7 @@ function initialize { } function rebuild_index { - $TLDRHOME/scripts/build_index.rb + npm run build-index } function build_archive { diff --git a/scripts/build_index.rb b/scripts/build_index.rb deleted file mode 100755 index 839ca039a9..0000000000 --- a/scripts/build_index.rb +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env ruby - -require "json" - -commands = {} - -Dir["#{ENV["TLDRHOME"]}/pages/**/*.md"].each do |file| - # "./pages/osx/xsltproc.md", - file = file.split("/") - name = file.pop().gsub(".md","") - platform = file.pop() - - unless commands.key?(name) - commands[name] = { - name: name, - platform: [platform] - } - else - commands[name][:platform] << platform - end -end - -commands = commands.sort.map do |k,v| v end - -File.write("#{ENV["TLDRHOME"]}/pages/index.json", {commands: commands}.to_json) diff --git a/scripts/markdown-style.rb b/scripts/markdown-style.rb deleted file mode 100644 index 8710e0fc26..0000000000 --- a/scripts/markdown-style.rb +++ /dev/null @@ -1,5 +0,0 @@ -# This file contains the markdown rules markdownlint will check for -all - -exclude_rule 'MD013' # Lengthy lines (80+ chars) -exclude_rule 'MD034' # Allow bare URLs diff --git a/scripts/pre-commit b/scripts/pre-commit deleted file mode 100644 index 53769a2552..0000000000 --- a/scripts/pre-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -make lint