5.12.3 • Published 6 months ago

@yqg/cli v5.12.3

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 months ago

Yqg Command Line Tools

Getting Start

First, install from npm globally,

npm i -g @yqg/cli

Then, you can type the command to use yqg-cli,

yqg vue
yqg shell
yqg vue --debug # debug 模式

And that's all.

Introduction

yqg-cli has 8 commands in total now, which can be divided into three categories:

  • scaffold to generate components and projects of vue
    • vue
  • shell tool to help saving time
    • clean local release branch
    • clean remote release branch
    • check package json && auto install dependencies when changed
  • build tool to start a dev server or build binary code for release
    • clean
    • copy
    • bundle
    • build
    • start

Scaffold

Using scaffold is quiet simple, just type yqg vue, and follow the prompt to type in a few words, you will get your components and projects generated.

Currently supported templates:

  • vue
    • component-single: single file component recommanded by Evan You
    • project: standalone project
    • project-user: project can be used only in yqg_web_user

To be supported in the future:

  • [] react
    • [] component
    • [] modal
    • [] project
  • [] vue project
    • [] auto create soft link
    • [] support create projects standalone which not in yqd_web_admin

Shell Tool

To use shell tool, there are two ways. One is just to type yqg shell without arguments, another is using it with arguments which will be passed to the shell script.

Type yqg shell, you will see currently available shell tool, just enter a number to exec:

  1. git-clean-local-branch.sh: clean all local release branches which start with 'release'
  2. git-clean-remote-branch.sh: clean remote release to keep a few latest branches per bussiness
  3. check-package-json.sh

To using it with arguments, the '../../' will be passed to script 'check-package-json.sh', which means the path of package.json relative to PWD.

yqg shell check-package-json.sh ../../

Build Tool

Build tool come up with five scripts for clean, copy, bunlde, build and start.

  • clean: clean the binary files
  • copy: copy static files
  • bundle: bundle the client (if has) and server javascript file(s)
  • build: clean, copy && bundle
  • start: start a dev server with HMR

In order to use yqg-cli to build/develop your projects, you need to follow these three steps.

Step 1: setup config

As yqg-cli build tool is depending on node-config to get config, you need to create a folder named config in your project root, and a file named default.js, which will by used by node-config.

/*
 * @file config/default.js
 */

module.exports = {
    build: {
        framework: 'vue', // vue/react/none
        packageJsonPath: './package.json',

        copy: { // src -> dest map
            paths: {
                'src/public': 'build/public'
            }
        },

        global: { // globals used by webpack DefinePlugin
            __WEB_USER_HOST__: JSON.stringify('https://test.yangqianguan.com')
        },

        alias: { // alias used by webpack resolve
            'yqg-common': '../common/src'
        },

        htmlPlugin: { // html plugin options
            template: './src/fe/index.html',
            favicon: './src/fe/fav.png'
        },

        clientEntry: './src/fe/main.js',
        serverEntry: './src/server.js'
    },

    run: {
        port: 62570,
        webHost: 'http://localhost:8000',
        apiHost: 'http://localhost:8001'
    }
};

Step 2: setup dependencies and package.json

Install yqg-cli as a devDependencies:

npm i @yqg/cli -DE

Modify the scripts field in package.json:

"scripts": {
    "clean": "yqg clean",
    "copy": "yqg copy",
    "bundle": "yqg bundle",
    "build": "yqg build",
    "start": "yqg start",
    "prestart": "yqg shell check-package-json.sh ../../"
}

Note: using yqg build --stat can generate a webpack stat html page to help analyzing bundles.

Step 3: send ready signal in server.js

import startServer from '@yqg/cli/dist/start-server';

startServer(server, port);

Step 4(if ssr): using ssr Render

import Render from '@yqg/cli/dist/vue-ssr-render';

const templatePath = path.resolve(__dirname, './index.html');
const render = new Render(server, {templatePath});

server.use(async (ctx) => {
    const context = {title: DEFAULT_TITLE, url: ctx.req.url};
    const renderer = await render.get();
    ctx.set('Content-Type', 'text/html; charset=utf-8');
    ctx.body = await new Promise((resolve, reject) => renderer.renderToString(context, (err, html) => {
        if (err) {
            return reject(err);
        }

        return resolve(html);
    }));
});

After these steps, now cd to your project root dir, and run npm start to start the dev server, or run npm build to build your project for release.

Note: you can use a global yqg command to run yqg start or yqg build, but this is not recommanded, because different projects may use different versions of yqg-cli.

Addition: full config options list

Assum DEV is true when NODE_ENV is not one of test/feat/prod.

FieldDefault ValueRemark
build.stageDEV使用哪个 STAGE 的配置
build.devbuild.stage is DEV是否处于开发模式
build.debugDEV
build.vueDebugDEV是否开启 vue debug 模式
build.verboseDEV是否开启 webpack verbose 模式
build.modeDEV ? 'development' : 'production'webpack mode
build.framework'react'react/vue/none
build.typescriptfalse是否包含 typescript
build.hashDEV ? 'hash' : 'chunkhash'
build.cssHashDEV ? 'hash' : 'contenthash'
build.srcMapDEV
build.packageJsonPath'package.json'copy 的 package.json 的路径
build.publicPath'/'webpack output.publicPath
build.aliassee blowused by webpack.resolve
build.globalsee blowused by webpack.DefinePlugin
build.serverEntry'./server.js'
build.ssrServerEntry'./server.js'SSR Server Entry
build.server{}用于覆盖 server.config.js,不推荐使用
build.ssrServer{}用于覆盖 ssrServer.config.js,不推荐使用
build.nodeExternalsWhitelist[]提供给 webpack-node-externals 的白名单
build.providesee blowused by webpack.ProvidePlugin
build.htmlPlugin{}options for html-webpack-plugin
build.cacheGroups{}extra cacheGroups
build.clientEntry'./common/app/index.js'
build.client{}用于覆盖 client.config.js,不推荐使用
build.cleansee blowyqg clean config
build.copysee blowyqg copy config
build.devProxy'/api', '/admin', '/api-web', '/chidori'dev server proxy prefix list
run.apiHost''
run.webHost''
run.port8080

build.global

keyvalue
__STAGE__process.env.NODE_ENV
__DEBUG__DEV
__VUE_DEBUG__DEV
__CDN_HOST__''
__API_HOST__get from run.apiHost
__WEB_HOST__get from run.webHost
__CHIDORI_API_HOST__decided by stage
__CHIDORI_HOST__decided by stage

build.alias

framework: vue
keyvalue
vue$vue/dist/vue.common.js

build.provide

framework: react
keyvalue
Reactreact

build.clean

keyvalueremark
removebuildstring or array of strings
ensurebuildstring or array of strings

build.copy

keyvalueremark
pathssee blowsrc —> dest map
replacetruewhether to replace package.json scripts field

build.copy.paths

srcdest
configbuild/config
publicbuild/public
staticbuild/public/static
[PACKAGE_JSON_PATH]build/package.json
5.12.3

6 months ago

5.8.0

2 years ago

5.9.2

2 years ago

5.3.1

2 years ago

5.3.0

2 years ago

5.4.0

2 years ago

5.5.0

2 years ago

5.6.0

2 years ago

5.2.1-alpha.6

2 years ago

5.2.1-alpha.5

2 years ago

5.2.1-alpha.2

2 years ago

5.2.1-alpha.1

2 years ago

5.2.1-alpha.4

2 years ago

5.2.1-alpha.3

2 years ago

5.2.4

2 years ago

5.2.3

2 years ago

5.2.2

2 years ago

5.2.0

2 years ago

5.1.3-alpha.1

3 years ago

5.1.3-alpha.3

3 years ago

5.1.3-alpha.2

3 years ago

5.1.3-alpha.5

3 years ago

5.1.3-alpha.4

3 years ago

5.2.1-alpha

2 years ago

5.1.3-alpha.7

2 years ago

5.1.3-alpha.6

3 years ago

5.1.3-alpha.8

2 years ago

5.1.3-alpha

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0-alpha

3 years ago

5.1.0

3 years ago

5.0.9

3 years ago

5.0.8

3 years ago

5.0.7

3 years ago

5.0.6-beta

3 years ago

5.0.6-alpha

3 years ago

5.0.6

3 years ago

5.0.5

3 years ago

5.0.5-alpha

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.3-next

3 years ago

5.0.2

3 years ago

5.0.2-next.3

3 years ago

5.0.2-next.2

3 years ago

5.0.2-next.1

3 years ago

5.0.2-next

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.7

3 years ago

5.0.0-next.19

3 years ago

5.0.0-next.18

3 years ago

4.0.6

3 years ago

4.0.5

3 years ago

5.0.0-next.17

3 years ago

5.0.0-next.16

3 years ago

5.0.0-next.15

3 years ago

5.0.0-next.14

3 years ago

5.0.0-next.13

3 years ago

5.0.0-next.12

3 years ago

5.0.0-next.11

3 years ago

5.0.0-next.10

3 years ago

5.0.0-next.9

3 years ago

5.0.0-next.7

3 years ago

5.0.0-next.8

3 years ago

5.0.0-next.6

3 years ago

5.0.0-next.5

3 years ago

5.0.0-next.4

3 years ago

5.0.0-next.3

3 years ago

5.0.0-next.2

3 years ago

4.0.4

3 years ago

5.0.0-next.1

3 years ago

5.0.0-next

3 years ago

4.0.3

3 years ago

4.0.3-alpha

3 years ago

4.0.2

3 years ago

4.0.2-alpha

3 years ago

5.0.0-alpha.2

3 years ago

5.0.0-alpha.1

3 years ago

4.0.1

3 years ago

1.3.2

3 years ago

5.0.0-alpha

3 years ago

4.0.0

3 years ago

4.0.0-alpha

3 years ago

4.0.0-alpha.1

3 years ago

1.3.1-alpha.6

3 years ago

1.3.1-alpha.5

3 years ago

1.3.1-alpha.4

3 years ago

1.3.1-alpha.3

3 years ago

1.3.1-alpha.1

3 years ago

1.3.1-alpha.2

3 years ago

1.3.1-alpha

3 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.8-alpha.11

4 years ago

1.2.8-alpha.10

4 years ago

1.2.8-alpha.9

4 years ago

1.2.8-alpha.8

4 years ago

1.2.8-alpha.7

4 years ago

1.2.8-alpha.6

4 years ago

1.2.8-alpha.4

4 years ago

1.2.8-alpha.5

4 years ago

1.2.8-alpha.2

4 years ago

1.2.8-alpha.3

4 years ago

1.2.8-alpha.1

4 years ago

1.2.8-alpha

4 years ago

1.2.7

4 years ago

1.2.7-alpha

4 years ago

1.2.7-alpha.1

4 years ago

1.2.6

4 years ago

1.2.6-next.1

4 years ago

1.2.6-next

4 years ago

1.2.5

4 years ago

1.2.5-alpha.1

4 years ago

1.2.5-alpha.2

4 years ago

1.2.5-alpha

4 years ago

1.2.4

4 years ago

1.2.3

5 years ago

1.2.3-alpha

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.1-alpha.2

5 years ago

1.2.1-alpha.1

5 years ago

1.2.1-alpha

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.6-beta

5 years ago

1.1.5

5 years ago

1.1.5-beta

5 years ago

1.1.4

5 years ago

1.1.4-beta

5 years ago

1.1.3

5 years ago

1.1.3-beta

5 years ago

1.1.2

5 years ago

1.1.2-beta

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.1.0-alpha.2

5 years ago

1.1.0-alpha.1

5 years ago

1.1.0-alpha.0

5 years ago

1.0.7

5 years ago

1.1.0-alpha

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.12

5 years ago

1.0.0-beta.11

5 years ago

1.0.0-beta.10

5 years ago

1.0.0-beta.9

5 years ago

1.0.0-beta.8

5 years ago

1.0.0-beta.7

5 years ago

1.0.0-beta.6

5 years ago

1.0.0-beta.5

5 years ago

1.0.0-beta.4

5 years ago

1.0.0-beta.3

5 years ago

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

1.0.0-beta

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha

5 years ago

0.3.8

5 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.18

6 years ago

0.2.17

6 years ago

0.2.16

6 years ago

0.2.15

6 years ago

0.2.14

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.1.0-beta.9

6 years ago

0.1.0-beta.8

6 years ago

0.1.0-beta.7

6 years ago

0.1.0-beta.6

6 years ago

0.1.0-beta.5

6 years ago

0.1.0-beta.4

6 years ago

0.1.0-beta.3

6 years ago

0.1.0-beta.2

6 years ago

0.1.0-beta.1

6 years ago

0.1.0-beta.0

6 years ago

0.1.0-alpha.2

6 years ago

0.1.0-alpha.1

6 years ago

0.1.0-alpha.0

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago