Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/plugins/hwc/.codecheck/check.yml

This file was deleted.

52 changes: 0 additions & 52 deletions packages/plugins/hwc/.vscode/debug-ts.js

This file was deleted.

28 changes: 0 additions & 28 deletions packages/plugins/hwc/.vscode/i18n-ally-custom-framework.yml

This file was deleted.

12 changes: 0 additions & 12 deletions packages/plugins/hwc/.vscode/settings.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/plugins/hwc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,3 @@
## 产品介绍和使用说明

https://opentiny.design/ng-pro/docs/hwcPlugin

## 开发指导

1. 安装tiny cli,请参考 https://opentiny.design/tiny-cli/docs/use-install

2. 执行 npm run watch,会监视源文件的变化

3. 执行 tiny link

4. done,本地执行 tiny hwc 命令,查看效果
2 changes: 1 addition & 1 deletion packages/plugins/hwc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opentiny/tiny-plugin-hwc",
"private": false,
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/link/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentiny/tiny-plugin-link",
"version": "1.0.1",
"version": "1.0.2",
"description": "提供本地软链接工程,提升组件开发、调试效率",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/link/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

1. 第一步:首先将 lazyload 软链到 .tiny/LocalCDNPath 目录去。
`执行tiny link 或者 tiny link init`
![init](./doc/init.png)
![init](https://github.com/opentiny/tiny-cli/blob/dev/packages/plugins/link/doc/init.png)
此时在个人的用户目录下会存在一份目标组件的软链接:
![initlink](./doc/initlink.png)
![initlink](https://github.com/opentiny/tiny-cli/blob/dev/packages/plugins/link/doc/initlink.png)

2. 第二步:在.tiny/LocalCDNPath 目录查找 @opentiny/xxxx 组件,找到的话,将页面依赖的@opentiny/xxxx 删除,将.tiny/LocalCDNPath 下的组件软链到页面项目中去。
`执行tiny link -m @opentiny/xxx 本例中xxx表示lazyload`
![insert](./doc/insert.png)
![insert](https://github.com/opentiny/tiny-cli/blob/dev/packages/plugins/link/doc/insert.png)
此时,在测试工程中,就会将目标组件软链接过来,如:
![insertlink](./doc/insertlink.png)
![insertlink](https://github.com/opentiny/tiny-cli/blob/dev/packages/plugins/link/doc/insertlink.png)

## 使用场景

Expand Down
9 changes: 6 additions & 3 deletions packages/plugins/link/src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ async function initLink(options: any) {
if (!fs.existsSync(path.join(homePath, './LocalCDNPath'))) {
fs.mkdirSync(`${homePath}` + '/LocalCDNPath');
}
let scope = ''
let scope = '';
if (pkgName.startsWith('@') && pkgName.split('/').length > 1) {
scope = pkgName.split('/')[0]
scope = pkgName.split('/')[0];
}
if (scope && !fs.existsSync(path.join(homePath, `./LocalCDNPath/${scope}`))) {
if (
scope &&
!fs.existsSync(path.join(homePath, `./LocalCDNPath/${scope}`))
) {
fs.mkdirSync(`${homePath}` + `/LocalCDNPath/${scope}`);
}

Expand Down
15 changes: 15 additions & 0 deletions packages/plugins/lint/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org
root = true

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

[*.md]
max_line_length = 0
trim_trailing_whitespace = false
12 changes: 12 additions & 0 deletions packages/plugins/lint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
build
test
src/**.js
.idea/*

coverage
.nyc_output
*.log
dist
yarn.lock
/package-lock.json
20 changes: 20 additions & 0 deletions packages/plugins/lint/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
src
test
tsconfig.json
tsconfig.module.json
tslint.json
.travis.yml
.github
.prettierignore
.vscode
build/docs
**/*.spec.*
coverage
.nyc_output
*.log
!template/*
!template/**/src
!template/**/src
!template/**/tsconfig.json
!template/**/tsconfig.module.json
!template/**/tslint.json
2 changes: 2 additions & 0 deletions packages/plugins/lint/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package.json is formatted by package managers, so we ignore it here
package.json
21 changes: 21 additions & 0 deletions packages/plugins/lint/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions packages/plugins/lint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# tiny-plugin-lint

> 本地代码 commit 时校验提交代码的 eslint,禁止不规范的代码入库

当前 lint 插件基于 Opentiny 前端规范开发而成,eslint 规则包可查看:[@opentiny/eslint-config](https://www.npmjs.com/package/@opentiny/eslint-config)

## 说明

> 代码提交时校验 eslint
> 提交校验不通过的代码,可以通过 fix 操作,修复不合规的代码(部分不规范的 eslint 问题仍需要手动修复)

## 使用场景

1. 代码提交时校验
2. 代码提交后修复

## 用法

### 在命令行里面使用

```
$ tiny lint help
$ tiny lint init //初始化tiny lint
$ tiny lint fix //修复本地lint,包括eslint(规则见:.eslintrc.js)、prettier(规则见:.prettierrc.js)、stylelint(规则见:.stylelintrc.js)
```
102 changes: 102 additions & 0 deletions packages/plugins/lint/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const spawn = require('cross-spawn');
const os = require('os');

const YELLOW = '\033[1;33m';
const END = '\033[0m';
const cwd = process.cwd();

function getBin() {
const bin = 'tiny';
return bin;
}

const bin = getBin();

function runEslint() {
if (fs.existsSync(path.join(cwd, '.eslintrc.js'))) {
// git diff --name-only git status --porcelain -b
const result = spawn.sync('git', ['diff', '--cached', '--name-status']);
const resultFile = [];
const diffFile = result.stdout
.toString()
.trim()
.split('\n');
diffFile.forEach(item => {
// R是重命名,也过滤掉
if (
item[0] !== 'D' &&
item[0] !== 'R' &&
['.js', '.jsx', '.ts', '.tsx'].indexOf(path.extname(item)) !== -1
) {
resultFile.push(item.substr(2).trim());
}
});
if (resultFile.length) {
console.log(`${YELLOW} Running eslint, please wait...${END}`);
const eslintResult = spawn.sync(
'./node_modules/eslint/bin/eslint.js',
['--fix', '--quiet', '--ext', '.js,.jsx,.ts,.tsx'].concat(resultFile),
{ stdio: 'inherit', cwd }
);

if (eslintResult.status !== 0) {
// has error
console.log(
`Tips: run ${YELLOW}tiny lint fix ${END}to excute eslint task`
);
process.exit(1);
} else {
spawn.sync('git', ['add'].concat(resultFile), { stdio: 'inherit' });
}
}
} else {
console.log(
`${YELLOW}当前项目没有eslint环境,开始进行环境初始化... ${END}`
);
spawn.sync(bin, ['lint', 'init', '--js'], { stdio: 'inherit' });
// 新文件默认加进去
spawn.sync('git', ['add', '.']);
}
}

function runPrettier() {
if (fs.existsSync(path.join(cwd, '.prettierrc.js'))) {
// git diff --name-only
const result = spawn.sync('git', ['diff', '--cached', '--name-status']);
const diffFile = result.stdout
.toString()
.trim()
.split('\n');
const resultFile = [];
diffFile.forEach(item => {
if (
item[0] !== 'D' &&
item[0] !== 'R' &&
['.js', '.jsx', '.ts', '.tsx'].indexOf(path.extname(item)) !== -1
) {
resultFile.push(item.substr(2).trim());
}
});
if (resultFile.length) {
try {
console.log(`${YELLOW} Running prettier, please wait...${END}`);
spawn.sync(
'./node_modules/.bin/prettier',
['--write'].concat(resultFile),
{ stdio: 'inherit' }
);
} catch (e) {
console.log(`${YELLOW} Running prettier error...${END}`);
spawn.sync(bin, ['lint', 'init', '--js'], { stdio: 'inherit' });
}
}
} else {
spawn.sync(bin, ['lint', 'init', '--js'], { stdio: 'inherit' });
}
}

runPrettier();
runEslint();
Loading