├── .gitignore
├── test
├── file.json
├── file.css
└── file.html
├── bin
└── see
├── .eslintrc
├── logo.png
├── screenshots
├── see-html.png
├── see-js.png
└── see-json.png
├── prettier.config.js
├── README.md
├── package.json
├── index.js
└── .circleci
└── config.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/test/file.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | }
4 |
--------------------------------------------------------------------------------
/bin/see:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | require('../')
4 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@rwu823"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rwu823/see-cli/HEAD/logo.png
--------------------------------------------------------------------------------
/test/file.css:
--------------------------------------------------------------------------------
1 | body {
2 | font: 100% Helvetica, sans-serif;
3 | color: #000;
4 | }
5 |
--------------------------------------------------------------------------------
/screenshots/see-html.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rwu823/see-cli/HEAD/screenshots/see-html.png
--------------------------------------------------------------------------------
/screenshots/see-js.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rwu823/see-cli/HEAD/screenshots/see-js.png
--------------------------------------------------------------------------------
/screenshots/see-json.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rwu823/see-cli/HEAD/screenshots/see-json.png
--------------------------------------------------------------------------------
/prettier.config.js:
--------------------------------------------------------------------------------
1 | const base = require('@rwu823/base/prettier.config')
2 |
3 | module.exports = Object.assign(base, {})
4 |
--------------------------------------------------------------------------------
/test/file.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Document
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | ## Installation
17 |
18 | ```sh
19 | $ npm i -g see-cli
20 | ```
21 |
22 | ## Usage
23 |
24 | ```sh
25 | $ see --help
26 | ```
27 |
28 | ## Screenshots
29 | 
30 |
31 | 
32 |
33 | 
34 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "see-cli",
3 | "version": "0.0.1",
4 | "description": "A colorful 🌈 cat - syntax highlight print CLI",
5 | "main": "index.js",
6 | "bin": {
7 | "see": "bin/see"
8 | },
9 | "scripts": {
10 | "test": "echo 'jest'",
11 | "lint": "eslint `git diff origin/master..HEAD --name-only -- '*.js'`",
12 | "lint:all": "eslint . --ignore-path .gitignore"
13 | },
14 | "keywords": [
15 | "cli",
16 | "syntax",
17 | "cat",
18 | "highlight",
19 | "colorful",
20 | "print"
21 | ],
22 | "author": "Rocky Wu ",
23 | "license": "MIT",
24 | "dependencies": {
25 | "chalk": "^2.4.1",
26 | "cli-highlight": "^2.0.0",
27 | "isbinaryfile": "^3.0.2",
28 | "meow": "^5.0.0"
29 | },
30 | "devDependencies": {
31 | "@rwu823/base": "github:rwu823/base"
32 | },
33 | "lint-staged": {
34 | "*.{js,jsx,css,md}": [
35 | "prettier --write --parser babylon",
36 | "git add"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs')
2 | // const path = require('path')
3 | const c = require('chalk')
4 | const meow = require('meow')
5 | const isBinary = require('isbinaryfile')
6 | const { highlight } = require('cli-highlight')
7 |
8 | const log = (logs = '') => console.log(`${c.cyan('see')}: ${logs}`)
9 |
10 | const cli = meow(
11 | `
12 | Usage
13 | $ ${c.cyan('see')} /path/file.ext
14 | `,
15 | {
16 | flags: {
17 | type: {
18 | type: 'string',
19 | alias: 't',
20 | },
21 | },
22 | },
23 | )
24 |
25 | const [filePath] = cli.input
26 |
27 | fs.stat(filePath, (err, stats) => {
28 | if (!stats) {
29 | return log(`${c.gray(filePath)} does not exists.`)
30 | }
31 |
32 | if (!stats.isFile()) {
33 | return log(`${c.gray(filePath)} is not a File.`)
34 | }
35 |
36 | if (isBinary.sync(filePath)) {
37 | return log(`${c.gray(filePath)} is not a TEXT File.`)
38 | }
39 |
40 | // const basename = path.basename(filePath)
41 | // const ext = (basename.match(/\.([^.]+)$/) || [])[1]
42 |
43 | const rs = fs.createReadStream(filePath)
44 |
45 | let text = ''
46 | rs.on('data', (chunk) => {
47 | text += chunk
48 | }).on('end', () => {
49 | try {
50 | console.log(highlight(text))
51 | } catch (er) {
52 | console.log(text)
53 | }
54 | })
55 | })
56 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | vars:
4 | init: &init
5 | environment:
6 | TZ: 'Asia/Taipei'
7 | docker:
8 | - image: circleci/node
9 |
10 | save_node_modules: &save_node_modules
11 | save_cache:
12 | key: node_modules#{{ checksum "package-lock.json" }}
13 | paths:
14 | - node_modules
15 |
16 | restore_node_modules: &restore_node_modules
17 | restore_cache:
18 | key: node_modules#{{ checksum "package-lock.json" }}
19 |
20 | branch_not_deploy: &branch_not_deploy
21 | filters:
22 | branches:
23 | ignore:
24 | - master
25 |
26 | branch_is_deploy: &branch_is_deploy
27 | filters:
28 | branches:
29 | only:
30 | - master
31 |
32 | setup_docker: &setup_docker
33 | setup_remote_docker:
34 | docker_layer_caching: true
35 |
36 | setup_npm: &setup_npm
37 | run:
38 | name: Setup NPM
39 | command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
40 |
41 | set_env: &set_env
42 | run:
43 | name: Set Env
44 | command: |
45 | echo 'export IMAGE=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_SHA1' >> $BASH_ENV
46 | source $BASH_ENV
47 |
48 | echo $IMAGE
49 |
50 | docker_build: &docker_build
51 | run:
52 | name: Docker build
53 | command: |
54 | docker build . -t $IMAGE
55 | docker images $IMAGE
56 | docker history $IMAGE
57 |
58 | setup_gcloud: &setup_gcloud
59 | run:
60 | name: Setup GCloud
61 | command: |
62 | export GCLOUD_SDK_VERSION=204
63 | export GCLOUD_PROJECT=gcp-project-id
64 | curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-$GCLOUD_SDK_VERSION.0.0-linux-x86_64.tar.gz -o ./gcloud-sdk.tar.gz
65 | tar xzf gcloud-sdk.tar.gz -C ~
66 | rm gcloud-sdk.tar.gz
67 | export PATH=~/google-cloud-sdk/bin:$PATH
68 | echo $GCLOUD_KEY | base64 --decode > ~/gcloud.key.json
69 | gcloud components install kubectl
70 | gcloud auth activate-service-account --key-file ~/gcloud.key.json
71 | gcloud config set project $GCLOUD_PROJECT
72 | gcloud container clusters get-credentials event-k8s --zone asia-northeast1-a
73 |
74 | echo 'export IMAGE=gcr.io/$GCLOUD_PROJECT/www:$CIRCLE_SHA1' >> $BASH_ENV
75 | echo 'export PATH=~/google-cloud-sdk/bin:$PATH' >> $BASH_ENV
76 |
77 | source $BASH_ENV
78 |
79 | echo $IMAGE
80 | jobs:
81 | lint:
82 | <<: *init
83 | steps:
84 | - checkout
85 | - *restore_node_modules
86 | - run: npm i
87 | - *save_node_modules
88 | - run: npm run lint
89 |
90 | test:
91 | <<: *init
92 | steps:
93 | - checkout
94 | - *restore_node_modules
95 | - run: npm i
96 | - *save_node_modules
97 | - run: npm test
98 |
99 | github tags:
100 | <<: *init
101 | steps:
102 | - checkout
103 | - run: git config --global user.name "CircleCI"
104 | - run: git config --global user.email "auto_deploy@circleci.com"
105 | - run: git tag v`cat package.json | grep version | cut -d '"' -f4`
106 | - run: git push https://$GH_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git --tags
107 |
108 | npm publish:
109 | <<: *init
110 | steps:
111 | - checkout
112 | - *setup_npm
113 | - run:
114 | name: Create publish folder out/
115 | command: mkdir out && cp -r bin package.json index.js README.md out/
116 | - run: npm publish out
117 |
118 | workflows:
119 | version: 2
120 | deploy to npm:
121 | jobs:
122 | - github tags:
123 | <<: *branch_is_deploy
124 | - npm publish:
125 | <<: *branch_is_deploy
126 | testing:
127 | jobs:
128 | - test:
129 | <<: *branch_not_deploy
130 | - lint:
131 | <<: *branch_not_deploy
132 |
--------------------------------------------------------------------------------