JSPM

@modyqyw/fabric

2.9.0-4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q54384F
  • License MIT

Opinionated shareable specification for different JavaScript/TypeScript projects.

Package Exports

  • @modyqyw/fabric
  • @modyqyw/fabric/commitlint
  • @modyqyw/fabric/eslint/native
  • @modyqyw/fabric/prettier
  • @modyqyw/fabric/stylelint/scss

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@modyqyw/fabric) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@modyqyw/fabric

Opinionated shareable specification for different JavaScript/TypeScript projects.

Node.js 12+ and npm 6+ are required.

Plan

Github | Gitee

Usage

Using npm below. You can use pnpm or yarn instead.

# locally
npm i -D @modyqyw/fabric@~2.9.0-4

# globally
npm i -g @modyqyw/fabric@~2.9.0-4

Use @legacy for legacy version, which supports Node.js 10+ and npm6+.

# locally
npm i -D @modyqyw/fabric@legacy

# globally
npm i -g @modyqyw/fabric@legacy

CLI (beta)

This is still a beta feature and may cause your project to crash. Please use it in your new projects and give feedback. It will get smarter in the foreseeable future.

CLI is used to config your project easier. Just call it after installing globally.

# in current dir
modyqyw-fabric config
# specify PROJECT_DIR
modyqyw-fabric config ./

Or, you can use scripts in ${PROJECT_DIR}package.json if you install locally.

{
  ...,
  "scripts": {
    ...,
    "config": "modyqyw-fabric config"
  }
}
npm run config

Naming

Naming is very hard and hardly be checked by linters. However, there are still relevant naming suggestions available.

Besides, you can learn naming from some open-source projects, such as Vuetify, MaterialUI, Bootstrap, TailwindCSS and Bulma.

In my opinion, simplicity and clarity are the highest priority for naming.

Git

Learn about Git, GitFlow and GifLFS.

git config --global core.autocrlf false
git config --global init.defaultBranch main

For SSH keys, check Connecting to GitHub with SSH, which also works for other git systems like Gitee.

Set up ${PROJECT_DIR}/.gitattributes.

* text=auto

A better ${PROJECT_DIR}/.gitattributes example here.

A ${PROJECT_DIR}/.gitignore example here.

EditorConfig

Learn about EditorConfig.

Set up ${PROJECT_DIR}/.editorconfig.

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

Prettier

Learn about Prettier.

npm i -D prettier@~2.3.2

Set up ${PROJECT_DIR}/.prettierrc.js.

const config = require('@modyqyw/fabric/prettier');

module.exports = {
  ...config,
};

Set up ${PROJECT_DIR}/package.json. Use .gitignore as the ignore pattern file here.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:json",
    "lint:json": "prettier ./**/*.json --write --ignore-path=.gitignore"
  }
}

ESLint

Learn about ESLint.

npm i -D eslint@~7.31.0 @babel/core@~7.14.8 @babel/eslint-parser@~7.14.7

If you are using typescript, additional dependencies are needed.

npm i -D typescript@~4.3.5 @typescript-eslint/eslint-plugin@~4.28.5 @typescript-eslint/parser@~4.28.5

Set up ${PROJECT_DIR}/.eslintrc.js.

// for js and ts
const config = require('@modyqyw/fabric/eslint/native');

// for react17
// with js or ts
// const config = require('@modyqyw/fabric/eslint/react');

// for vue2 with js
// const config = require('@modyqyw/fabric/eslint/vue2');

// for vue2 with ts
// const config = require('@modyqyw/fabric/eslint/vue2-typescript');

// for vue3 with js
// const config = require('@modyqyw/fabric/eslint/vue3');

// for vue3 with ts
// const config = require('@modyqyw/fabric/eslint/vue3-typescript');

module.exports = {
  ...config,
};

Set up ${PROJECT_DIR}/package.json. Use .gitignore as the ignore pattern file here.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:script",
    "lint:script": "eslint . --fix --ext=.js,.jsx,.ts,.tsx,.vue --ignore-path=.gitignore"
  }
}

When using vue-cli-service, eslint . --fix --ext=.js,.jsx,.ts,.tsx,.vue --ignore-path=.gitignore can be replaced with vue-cli-service lint --fix.

You should declare paths in jsconfig.json or tsconfig.json if you are using path aliases.

Stylelint

Learn about Stylelint.

npm i -D stylelint@~13.13.1

Set up ${PROJECT_DIR}/.stylelintrc.js.

// for css
const config = require('@modyqyw/fabric/stylelint/css');

// for less
// const config = require('@modyqyw/fabric/stylelint/less');

// for sass
// const config = require('@modyqyw/fabric/stylelint/sass');

// for scss
// const config = require('@modyqyw/fabric/stylelint/scss');

module.exports = {
  ...config,
};

Set up ${PROJECT_DIR}/package.json. Use .gitignore as the ignore pattern file here.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:style",
    "lint:style": "stylelint ./**/*.{css,less,sass,scss,vue} --fix --ignore-path=.gitignore"
  }
}

Markdownlint

Learn about Markdown and Markdownlint.

npm i -D markdownlint-cli@~0.28.1

Set up ${PROJECT_DIR}/.markdownlint.json.

{
  "MD003": false,
  "MD013": false,
  "MD022": false,
  "MD024": false,
  "MD025": false,
  "MD033": false
}

Set up ${PROJECT_DIR}/package.json. Use .gitignore as the ignore pattern file here.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:markdown",
    "lint:markdown": "markdownlint . --fix --ignore-path=.gitignore"
  }
}

LintMD

Learn about LintMD, which aims at Chinese markdown files.

npm i -D @lint-md/cli@~0.1.5

Set up ${PROJECT_DIR}/.lintmdrc.

{
  "excludeFiles": [],
  "rules": {
    "no-long-code": [
      "error",
      {
        "length": 80,
        "exclude": ["css", "less", "sass", "scss"]
      }
    ]
  }
}

Set up ${PROJECT_DIR}/package.json.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:markdown",
    "lint:markdown": "lint-md . --fix"
  }
}

LsLint

Learn about LsLint.

npm i -D @ls-lint/ls-lint@~1.10.0

Set up ${PROJECT_DIR}/.ls-lint.yml.

ls:
  .config.json: camelCase | PascalCase | kebab-case
  .project.json: camelCase | PascalCase | kebab-case
  .js: camelCase | PascalCase | kebab-case
  .jsx: camelCase | PascalCase | kebab-case
  .d.ts: camelCase | PascalCase | kebab-case
  .ts: camelCase | PascalCase | kebab-case
  .tsx: camelCase | PascalCase | kebab-case
  .vue: camelCase | PascalCase | kebab-case
  .config.js: camelCase | PascalCase | kebab-case
  .config.dev.js: camelCase | PascalCase | kebab-case
  .config.development.js: camelCase | PascalCase | kebab-case
  .config.staging.js: camelCase | PascalCase | kebab-case
  .config.prod.js: camelCase | PascalCase | kebab-case
  .config.production.js: camelCase | PascalCase | kebab-case
  .config.ts: camelCase | PascalCase | kebab-case
  .config.dev.ts: camelCase | PascalCase | kebab-case
  .config.development.ts: camelCase | PascalCase | kebab-case
  .config.staging.ts: camelCase | PascalCase | kebab-case
  .config.prod.ts: camelCase | PascalCase | kebab-case
  .config.production.ts: camelCase | PascalCase | kebab-case
  .test.js: camelCase | PascalCase | kebab-case
  .test.ts: camelCase | PascalCase | kebab-case
  .spec.js: camelCase | PascalCase | kebab-case
  .spec.ts: camelCase | PascalCase | kebab-case
  .css: camelCase | PascalCase | kebab-case
  .less: camelCase | PascalCase | kebab-case
  .sass: camelCase | PascalCase | kebab-case
  .scss: camelCase | PascalCase | kebab-case
  .module.css: camelCase | PascalCase | kebab-case
  .module.less: camelCase | PascalCase | kebab-case
  .module.sass: camelCase | PascalCase | kebab-case
  .module.scss: camelCase | PascalCase | kebab-case

ignore:
  - logs
  - report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
  - pids
  - lib-cov
  - coverage
  - .nyc_output
  - .grunt
  - bower_components
  - .lock-wscript
  - buildRelease
  - node_modules
  - jspm_packages
  - web_modules
  - .npm
  - .eslintcache
  - .rpt2_cache
  - .rts2_cache_cjs
  - .rts2_cache_es
  - .rts2_cache_umd
  - .node_repl_history
  - .yarn-integrity
  - .env
  - .env.test
  - .env.*.test
  - .env.local
  - .env.*.local
  - .cache
  - .parcel-cache
  - dist_electron
  - .next
  - out
  - .umi
  - .umi-production
  - .umi-test
  - .nuxt
  - dist
  - .rax
  - .cache
  - .vuepressdist
  - .serverless
  - .fusebox
  - .dynamodb
  - .tern-port
  - .vscode-test
  - .vscode
  - .idea
  - .hbuilder
  - .hbuilderx
  - .yarncache
  - .yarnunplugged
  - .yarnbuild-state.yml
  - .yarninstall-state.gz
  - .pnp.*
  - .DS_Store
  - .commitlintrc.js
  - .commitlintrc.json
  - .eslintrc.js
  - .eslintrc.json
  - .lintstagedrc.js
  - .lintstagedrc.json
  - .markdownlintrc.js
  - .markdownlint.json
  - .prettierrc.js
  - .prettierrc.json
  - .stylelintrc.js
  - .stylelintrc.json

Set up ${PROJECT_DIR}/package.json.

{
  ...,
  "scripts": {
    ...,
    "lint": "npm run lint:ls",
    "lint:ls": "ls-lint ."
  }
}

Commitlint

Learn about Commitlint.

npm i -D @commitlint/cli@~13.1.0

Set up ${PROJECT_DIR}/.commitlintrc.js.

const config = require('@modyqyw/fabric/commitlint');

module.exports = {
  ...config,
};

Commitizen

Learn about Commitizen.

npm i -D commitizen@~4.2.4

Set up ${PROJECT_DIR}/package.json.

{
  ...,
  "scripts": {
    ...,
    "commit": "cz"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

LintStaged

Learn about LintStaged.

npm install -D lint-staged@~11.1.1

Set up ${PROJECT_DIR}/.lintstagedrc.js.

module.exports = {
  '*.json': 'prettier --write',
  '*.{css,less,sass,scss,vue}': 'stylelint --fix',
  '*.{js,jsx,ts,tsx,vue}': 'eslint --fix',
  '*.{md,markdown}': 'markdownlint --fix && lint-md --fix',
};

When using vue-cli-service, eslint --fix can be replaced with vue-cli-service lint --fix.

Husky

Learn about Husky.

npm install -D is-ci@~3.0.0 husky@~7.0.1

npx husky install

Set up ${PROJECT_DIR}/package.json.

{
  ...,
  "scripts": {
    ...,
    "prepare": "is-ci || husky install"
  }
}

Set up ${PROJECT_DIR}/.husky/commit-msg hook.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1

Set up ${PROJECT_DIR}/.husky/pre-commit hook.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install ls-lint . && npx --no-install lint-staged

Finally use chmod.

chmod +x .git/hooks/*
chmod +x .husky/*

If you want to use husky@4, steps are shown below.

npm i -D husky@~4.3.8

Set up ${PROJECT_DIR}/package.json.

{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
      "pre-commit": "ls-lint . && lint-staged"
    }
  }
}

Deploy

Experience has proven that automation is the best option. You may want to try packages below, sorted according to alphabetical order.

VSCode

{
  "css.validate": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.markdownlint": true,
    "source.fixAll.stylelint": true
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.rulers": [{ "column": 80 }],
  "editor.tabSize": 2,
  "editor.wordWrap": "on",
  "files.eol": "\n",
  "files.associations": {
    "*.wxml": "html",
    "*.wxs": "javascript",
    "*.wxss": "css",
    "*.axml": "html",
    "*.sjs": "javascript",
    "*.acss": "css",
    "*.swan": "html",
    "*.ttml": "html",
    "*.ttss": "css",
    "*.jxml": "html",
    "*.jxss": "css",
    "*.wpy": "vue",
    "*.json": "jsonc",
    "*.nvue": "vue",
    "*.ux": "vue"
  },
  "less.validate": false,
  "scss.validate": false,
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  }
}

Acknowledge

Sorted according to alphabetical order.

License

MIT

Copyright (c) 2020-present ModyQyW