Skip to content

Commit d9ee2a0

Browse files
committed
✨ add utils
0 parents  commit d9ee2a0

30 files changed

+6798
-0
lines changed

.circleci/config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
# specify the version you desire here
6+
- image: circleci/node:latest-browsers
7+
environment:
8+
NPM_CONFIG_LOGLEVEL: error
9+
JOBS: max # https://gist.github.com/ralphtheninja/f7c45bdee00784b41fed
10+
working_directory: ~/micro-app-shared-utils
11+
branches:
12+
ignore:
13+
- docs
14+
- gh-pages
15+
16+
steps:
17+
- checkout
18+
- restore_cache:
19+
key: micro-app-shared-utils-{{ .Branch }}-{{ checksum "yarn.lock" }}
20+
- run: yarn --network-timeout 600000
21+
- save_cache:
22+
key: micro-app-shared-utils-{{ .Branch }}-{{ checksum "yarn.lock" }}
23+
paths:
24+
- ./node_modules
25+
- run: yarn run test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
26+

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
coverage
3+
.vscode
4+
.circleci

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true
6+
},
7+
extends: [
8+
"eslint-config-2o3t"
9+
],
10+
parserOptions: {
11+
parser: "babel-eslint"
12+
},
13+
}

.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# parcel-bundler cache (https://parceljs.org/)
63+
.cache
64+
65+
# next.js build output
66+
.next
67+
68+
# nuxt.js build output
69+
.nuxt
70+
71+
# Nuxt generate
72+
dist
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless
79+
80+
# IDE
81+
.idea
82+
83+
.vscode
84+
*.suo
85+
*.ntvs*
86+
*.njsproj
87+
*.sln
88+
*.sw*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-present, Zyao89
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Micro APP Shared-Utils
2+
3+
[Shared] shared utilities for micro-app.
4+
5+
Micro APP 依赖工具库.
6+
7+
[![Coverage Status][Coverage-img]][Coverage-url]
8+
[![CircleCI][CircleCI-img]][CircleCI-url]
9+
[![NPM Version][npm-img]][npm-url]
10+
[![NPM Download][download-img]][download-url]
11+
12+
[Coverage-img]: https://coveralls.io/repos/github/MicrosApp/MicroApp-Shared-Utils/badge.svg?branch=master
13+
[Coverage-url]: https://coveralls.io/github/MicrosApp/MicroApp-Shared-Utils?branch=master
14+
[CircleCI-img]: https://circleci.com/gh/MicrosApp/MicroApp-Shared-Utils/tree/master.svg?style=svg
15+
[CircleCI-url]: https://circleci.com/gh/MicrosApp/MicroApp-Shared-Utils/tree/master
16+
[npm-img]: https://img.shields.io/npm/v/@micro-app/shared-utils.svg?style=flat-square
17+
[npm-url]: https://npmjs.org/package/@micro-app/shared-utils
18+
[download-img]: https://img.shields.io/npm/dm/@micro-app/shared-utils.svg?style=flat-square
19+
[download-url]: https://npmjs.org/package/@micro-app/shared-utils
20+
21+
## Install
22+
23+
```sh
24+
yarn add @micro-app/shared-utils
25+
```
26+
27+
or
28+
29+
```sh
30+
npm install -D @micro-app/shared-utils
31+
```

constants/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
INJECT_ID: '_MICRO_APP_INJECT_',
5+
};

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
[
4+
'moduleAlias',
5+
'getPadLength',
6+
'injectHtml',
7+
'loadFile',
8+
'logger',
9+
'smartMerge',
10+
'virtualFile',
11+
].forEach(m => {
12+
Object.assign(exports, {
13+
[m]: require(`./libs/${m}`),
14+
});
15+
});
16+
17+
exports.assert = require('assert');
18+
exports.fs = require('fs-extra');
19+
exports.chalk = require('chalk');
20+
exports.cheerio = require('cheerio');
21+
exports.semver = require('semver');
22+
exports.semverRegex = require('semver-regex');
23+
exports._ = require('lodash');
24+
exports.tryRequire = require('try-require');
25+
exports.ora = require('ora');

libs/getPadLength.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
module.exports = function getPadLength(obj) {
4+
let longest = 10;
5+
if (Array.isArray(obj)) {
6+
obj.forEach(({ name }) => {
7+
if (name && name.length + 1 > longest) {
8+
longest = name.length + 1;
9+
}
10+
});
11+
} else {
12+
for (const name in obj) {
13+
if (name.length + 1 > longest) {
14+
longest = name.length + 1;
15+
}
16+
}
17+
}
18+
return longest;
19+
};

0 commit comments

Comments
 (0)