Skip to content

Commit 2342c55

Browse files
authored
feat: Locale && Plugin
Merge pull request #141 from xx45/feature/iamkun Locale && Plugin update
2 parents 0d9a01e + 9b51dd9 commit 2342c55

22 files changed

+211
-54
lines changed

.eslintrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
],
2525
"func-names": [
2626
0
27+
],
28+
"import/no-extraneous-dependencies": [
29+
0
30+
],
31+
"import/no-unresolved": [
32+
2,
33+
{
34+
"ignore": [
35+
"dayjs"
36+
]
37+
}
38+
],
39+
"import/extensions": [
40+
2,
41+
"ignorePackages"
2742
]
2843
}
2944
}

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@ package-lock.json
1212
# jest
1313
coverage
1414

15-
# dist
16-
dist
15+
# build
16+
locale
17+
plugin
18+
dayjs.min.js
19+
20+
#dev
21+
demo.js

.npmignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ yarn.lock
1010
package-lock.json
1111

1212
# jest
13-
coverage
13+
coverage
14+
15+
# dev
16+
src
17+
test
18+
build

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ English | [简体中文](./README.zh-CN.md)
1717
src="https://img.shields.io/codecov/c/github/xx45/dayjs/master.svg?style=flat-square" alt="Codecov"></a>
1818
<a href="https://github.com/xx45/dayjs/blob/master/LICENSE"><img
1919
src="https://img.shields.io/npm/l/dayjs.svg?style=flat-square" alt="License"></a>
20+
<br>
21+
<a href="https://saucelabs.com/u/dayjs">
22+
<img width="750" src="https://user-images.githubusercontent.com/17680888/40040137-8e3323a6-584b-11e8-9dba-bbe577ee8a7b.png" alt="Sauce Test Status">
23+
</a>
2024
</p>
2125

22-
> Day.js is a minimalist JavaScript library for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.
26+
> Day.js is a minimalist JavaScript library that parse, validate, manipulate, and display dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.
2327
2428
```js
2529
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');

README.zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
src="https://img.shields.io/codecov/c/github/xx45/dayjs/master.svg?style=flat-square" alt="Codecov"></a>
1717
<a href="https://github.com/xx45/dayjs/blob/master/LICENSE"><img
1818
src="https://img.shields.io/npm/l/dayjs.svg?style=flat-square" alt="License"></a>
19+
<br>
20+
<a href="https://saucelabs.com/u/dayjs">
21+
<img width="750" src="https://user-images.githubusercontent.com/17680888/40040137-8e3323a6-584b-11e8-9dba-bbe577ee8a7b.png" alt="Sauce Test Status">
22+
</a>
1923
</p>
2024

2125
> Day.js 是一个轻量的 JavaScript 时间日期处理库,和 Moment.js 的 API 设计保持完全一样. 如果你曾经用过 Moment.js, 那么你已经知道如何使用 Day.js

build/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const rollup = require('rollup')
2+
const configFactory = require('./rollup.config')
3+
const fs = require('fs')
4+
const util = require('util')
5+
const path = require('path')
6+
7+
const { promisify } = util
8+
9+
const promisifyReadDir = promisify(fs.readdir)
10+
11+
const formatName = n => n.replace(/\.js/, '').replace('-', '_')
12+
13+
async function build(option) {
14+
const bundle = await rollup.rollup(option.input)
15+
await bundle.write(option.output)
16+
}
17+
18+
(async () => {
19+
try {
20+
const locales = await promisifyReadDir(path.join(__dirname, '../src/locale'))
21+
locales.forEach((l) => {
22+
build(configFactory({
23+
input: `./src/locale/${l}`,
24+
fileName: `./locale/${l}`,
25+
name: `dayjs_locale_${formatName(l)}`
26+
}))
27+
})
28+
29+
const plugins = await promisifyReadDir(path.join(__dirname, '../src/plugin'))
30+
plugins.forEach((l) => {
31+
build(configFactory({
32+
input: `./src/plugin/${l}`,
33+
fileName: `./plugin/${l}`,
34+
name: `dayjs_plugin_${formatName(l)}`
35+
}))
36+
})
37+
38+
build(configFactory({
39+
input: './src/index.js',
40+
fileName: './dayjs.min.js'
41+
}))
42+
} catch (e) {
43+
console.error(e) // eslint-disable-line no-console
44+
}
45+
})()

build/rollup.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const babel = require('rollup-plugin-babel')
2+
const uglify = require('rollup-plugin-uglify')
3+
4+
module.exports = (config) => {
5+
const { input, fileName, name } = config
6+
return {
7+
input: {
8+
input,
9+
external: [
10+
'dayjs'
11+
],
12+
plugins: [
13+
babel({
14+
exclude: 'node_modules/**'
15+
}),
16+
uglify()
17+
]
18+
},
19+
output: {
20+
file: fileName,
21+
format: 'umd',
22+
name: name || 'dayjs',
23+
globals: {
24+
dayjs: 'dayjs'
25+
}
26+
}
27+
}
28+
}

karma.sauce.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ module.exports = function (config) {
8282
basePath: '',
8383
frameworks: ['jasmine'],
8484
files: [
85-
'dist/*.js',
85+
'dayjs.min.js',
8686
'test/*spec.js'
8787
],
8888
reporters: ['dots', 'saucelabs'],
8989
port: 9876,
9090
colors: true,
9191
logLevel: config.LOG_DEBUG,
9292
sauceLabs: {
93+
// build: 'Manual',
9394
testName: 'Day.js'
9495
},
9596
captureTimeout: 200000, // try fix ios timeout

package.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
{
22
"name": "dayjs",
33
"version": "0.0.0-development",
4-
"description": "2KB immutable date library alternative to Moment.js with the same modern API ",
5-
"main": "dist/dayjs.min.js",
4+
"description": "2KB immutable date time library alternative to Moment.js with the same modern API ",
5+
"main": "dayjs.min.js",
66
"types": "index.d.ts",
77
"scripts": {
88
"test": "jest",
9-
"lint": "./node_modules/.bin/eslint src/* test/*",
10-
"build": "BABEL_ENV=build rollup -c",
9+
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
10+
"build": "BABEL_ENV=build node build",
1111
"sauce": "npx karma start karma.sauce.conf.js",
1212
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2 && npm run sauce -- 3",
13-
"gzip-size": "gzip-size ./dist/*.min.js"
13+
"gzip-size": "gzip-size dayjs.min.js"
1414
},
1515
"pre-commit": [
1616
"lint"
1717
],
1818
"jest": {
19+
"roots": [
20+
"test"
21+
],
1922
"testRegex": "test/(.*?/)?.*test.js$",
2023
"coverageDirectory": "./coverage/",
2124
"collectCoverage": true,
2225
"collectCoverageFrom": [
2326
"src/**/*"
2427
]
2528
},
29+
"release": {
30+
"prepare": [
31+
{
32+
"path": "@semantic-release/changelog"
33+
},
34+
"@semantic-release/git"
35+
]
36+
},
2637
"keywords": [
2738
"dayjs",
2839
"date",

rollup.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)