xgqfrms-GitHub / Node-CLI-Tools

一个 Node.js CLI 工具,查看指定 git 仓库的 commit history ; 能对 commit history 进行搜索; 能查看指定时间范围的 commit history.
https://node-cli-tools.xgqfrms.xyz
MIT License
6 stars 2 forks source link

npm scripts & auto open default browser & run multi commands #17

Open xgqfrms-GitHub opened 6 years ago

xgqfrms-GitHub commented 6 years ago

npm scripts & auto open default browser & run multi commands

macOS

{
  "auto": "npm run dev & open http://localhost:8000",
}

Windows

// bad
{
  "start": "npm run dev & start http://localhost:8000",
}
// good 
{
  "start": "start http://localhost:8000 & npm run dev",
}
// bad
{
  "start": "npm run dev & npm run open",
  "open": "start http://localhost:8000",
}

demo

{
    "private": true,
    "entry": {
        "index": "./src/index.js"
    },
    "scripts": {
        "dev": "dora --plugins \"webpack?config=conf/webpack.config.js&publicPath=/,webpack-hmr,browser-history?index=/src/index.html\"",
        "build-dev": "atool-build --config conf/webpack.config.js --publicPath /",
        "build-staging": "atool-build --config conf/webpack.config.staging.js --publicPath /",
        "build-release": "atool-build --config conf/webpack.config.release.js --publicPath /",
        "start": "start http://localhost:8000 && npm run dev",
        "lint": "eslint --fix --ext .js,.jsx src/components/layout"
    },
    "dependencies": {
        "antd": "^2.11.0",
        "classnames": "^2.2.5",
        "dva": "^1.1.0",
        "dva-loading": "^0.2.0",
        "immutable": "^3.8.1",
        "js-cookie": "^2.1.3",
        "lodash": "^4.17.4",
        "moment": "^2.17.1",
        "prop-types": "^15.5.10",
        "qs": "^6.2.0",
        "rc-queue-anim": "^0.13.0",
        "rc-tween-one": "^1.0.0",
        "react": "^15.4.1",
        "react-countup": "^1.3.0",
        "react-dom": "^15.4.1",
        "react-lz-editor": "^0.10.15",
        "react-media-player": "^0.6.1",
        "react-motion-ui-pack": "^0.10.2",
        "recharts": "^0.19.0",
        "reselect": "^2.5.4"
    },
    "devDependencies": {
        "atool-build": "^0.7.6",
        "axios": "^0.15.3",
        "babel-eslint": "^6.0.4",
        "babel-plugin-dev-expression": "^0.2.1",
        "babel-plugin-dva-hmr": "^0.1.0",
        "babel-plugin-import": "^1.0.1",
        "babel-plugin-transform-runtime": "^6.9.0",
        "babel-polyfill": "^6.23.0",
        "babel-runtime": "^6.9.2",
        "dora": "^0.4.3",
        "dora-plugin-browser-history": "^0.2.0",
        "dora-plugin-proxy": "^0.8.5",
        "dora-plugin-webpack": "^0.8.1",
        "dora-plugin-webpack-hmr": "^0.2.1",
        "eslint": "^2.13.1",
        "eslint-config-airbnb": "^9.0.1",
        "eslint-plugin-import": "^1.8.1",
        "eslint-plugin-jsx-a11y": "^1.4.2",
        "eslint-plugin-react": "^5.1.1",
        "glob": "^7.0.5",
        "mockjs": "^1.0.1-beta3",
        "path-to-regexp": "^1.7.0",
        "redbox-react": "^1.2.10",
        "robe-ajax": "^1.0.0",
        "watchjs": "^0.0.0"
    },
    "theme": "./src/theme.js",
    "standard": {
        "parser": "babel-eslint",
        "globals": [
            "location",
            "localStorage"
        ]
    }
}
xgqfrms-GitHub commented 6 years ago

开发:

npm run dev    # 使用mock拦截请求,数据存储在localStroge里

# 打开 http://localhost:8000

npm start (bad)

https://github.com/pmg1989/dva-admin/issues/22#issuecomment-317683518

C:\Users\xray.anyproxy_certs

rootCA.key

-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----

rootCA.key error

https://github.com/pmg1989/dva-admin/issues/22


$ set OPENSSL_CONF=C:/OpenSSL/bin/openssl.cnf

构建:


npm run build-dev local环境发布
npm run build-staging staging 环境发布
npm run build-release release 环境发布

build后的文件将会生成dist目录

注意事项

关于为什么使用axios而不是fetch :在一个无服务器的环境中模拟数据请求, Mock不能拦截Fetch,只能拦截XHR,所以我选了一个纯Ajax的库 axios


    "scripts": {
        "dev": "dora --plugins \"webpack?config=conf/webpack.config.js&publicPath=/,webpack-hmr,browser-history?index=/src/index.html\"",
        "build-dev": "atool-build --config conf/webpack.config.js --publicPath /",
        "build-staging": "atool-build --config conf/webpack.config.staging.js --publicPath /",
        "build-release": "atool-build --config conf/webpack.config.release.js --publicPath /",
        "start": "dora --plugins \"proxy,webpack,webpack-hmr\"",
        "lint": "eslint --fix --ext .js,.jsx src/components/layout"
    },
"start": "npm run dev --open",

"start": "start http://localhost:8000",

"start": "npm run dev && start http://localhost:8000",

"start": "start npm run dev && start http://localhost:8000",

https://stackoverflow.com/questions/35261535/npm-scripts-start-run-express-and-open-url

        "start": "npm run dev && npm run open",
        "open": "start http://localhost:8000",

how to run multiple npm script command in one command

https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel

"dev": "concurrently --kill-others \"npm run start-watch\" \"npm run wp-server\""

"start": "start npm run dev && start http://localhost:8000",

"dev": "npm-run-all --parallel start-watch wp-server"

"start": "\"npm run dev\" && \"start http://localhost:8000\"",

"start": "start http://localhost:8000 && npm run dev",

"start": "start http://localhost:8000 && npm run dev",

npm-run-all & concurrently

https://www.npmjs.com/package/npm-run-all

https://github.com/mysticatea/npm-run-all

$ npm i -D npm-run-all 

$ npm-run-all clean lint build:*

$ npm-run-all --parallel watch:*

https://www.npmjs.com/package/concurrently


$ npm i -S concurrently

"start": "concurrently \"command1 arg\" \"command2 arg\"",

Configure The ‘script’ tag In package.json To Run Multiple Commands

http://javascript.tutorialhorizon.com/2014/09/02/configure-the-script-tag-in-package-json-to-run-multiple-commands/

# bad

"start": "npm run dev & start http://localhost:8000",

# good 

"start": "start http://localhost:8000 & npm run dev",

        "start": "npm run dev & npm run open",
        "open": "start http://localhost:8000",

Execute multiple npm scripts through VS Code task runner

http://xabikos.com/2015/11/11/Execute-multiple-npm-scripts-through-VS-Code-task-runner/


# npm scripts

"scripts": {
  "build-dev": "webpack --bail",
  "start-dev": "webpack-dev-server"
},

tasks.json

{
  "version": "0.1.0",
  "command": "npm",
  "isShellCommand": true,
  "showOutput": "always",
  "args": ["run"],
  "isWatching": false,
  "tasks": [
    { "taskName": "build-dev" },
    { "taskName": "start-dev"   }
  ]
}

http://xabikos.com/2015/11/11/Execute-multiple-npm-scripts-through-VS-Code-task-runner/availabletasks.png

Ctrl + Shift + P

Run Task

Bonus - tasks keyboard shortcuts

Keyboard shortcutsjson


{ "key": "shift+cmd+r",  "command": "workbench.action.tasks.runTask" },
{ "key": "shift+cmd+e",  "command": "workbench.action.tasks.terminate"}

https://blog.jayway.com/2014/03/28/running-scripts-with-npm/

https://stackoverflow.com/questions/35649551/running-multiple-commands-for-npm-test

"scripts": {
  "test": "karma ; protractor ; eslint ; htmlhint ; stylelint"
},

#!/bin/bash

EXIT_STATUS=0

function check_command {
    "$@"
    local STATUS=$?
    if [ $STATUS -ne 0 ]; then
        echo "error with $1 ($STATUS)" >&2
        EXIT_STATUS=$STATUS
    fi
}

check_command karma
check_command protractor
check_command eslint
check_command htmlhint
check_command stylelint
exit $EXIT_STATUS

https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel/45316356#45316356

open-default-browser

https://stackoverflow.com/questions/8500326/how-to-use-nodejs-to-open-default-browser-and-navigate-to-a-specific-url

https://stackoverflow.com/questions/7664605/how-would-you-launch-a-browser-from-the-a-node-js-command-line-script

https://stackoverflow.com/questions/40713752/how-to-open-browser-to-localhost-through-npm-scripts

npm scripts & auto open default browser & run multi commands

Write your shell scripts in JavaScript, via Node.js

https://2ality.com/2011/12/nodejs-shell-scripting.html

https://www.npmjs.com/package/openurl

https://github.com/rauschma/openurl

require("openurl").open("https:/www.xgqfrms.xyz")

require("openurl").open("mailto:xgqfrms@xyzdata.com")

require("openurl").mailto(
    [
        "xgqfrms@xyzdata.com", 
        "xgqfrms@xyzdata.com"
    ],
    {
        subject:"Hello!",
        body:"This is\nan automatically sent email!\n"
    }
);

open browser

https://github.com/pwnall/node-open

open a file or uri with the users preferred application (browser, editor, etc), cross platform

https://www.npmjs.com/package/open

const open = require("open");

open("https://www.google.com");

open("https://www.google.com", "xgqfrms");

npm install open
xgqfrms-GitHub commented 6 years ago

E:\github\Roles

xgqfrms commented 4 years ago

https://www.cnblogs.com/xgqfrms/p/12858667.html