@qn-pandora/pandora-tools 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +17 -0
- package/CHANGELOG.md +11 -0
- package/package.json +32 -11
- package/src/cli/commands/build.js +3 -0
- package/src/cli/commands/storybook.js +18 -4
- package/src/gulpfile.js +20 -10
- package/src/projectHelper.js +67 -4
- package/src/tasks/less.js +1 -1
package/CHANGELOG.json
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"name": "@qn-pandora/pandora-tools",
|
3
|
+
"entries": [
|
4
|
+
{
|
5
|
+
"version": "1.0.0",
|
6
|
+
"tag": "@qn-pandora/pandora-tools_v1.0.0",
|
7
|
+
"date": "Mon, 20 Dec 2021 09:51:49 GMT",
|
8
|
+
"comments": {
|
9
|
+
"major": [
|
10
|
+
{
|
11
|
+
"comment": "仓库迁移至rush后统一发个大版本"
|
12
|
+
}
|
13
|
+
]
|
14
|
+
}
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
package/CHANGELOG.md
ADDED
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@qn-pandora/pandora-tools",
|
3
|
-
"version": "
|
3
|
+
"version": "1.0.0",
|
4
4
|
"description": "Pandora Lib 常用开发&打包工具集",
|
5
5
|
"author": "pandora <pandora@qiniu.com>",
|
6
|
-
"homepage": "https://github.com/qbox/
|
6
|
+
"homepage": "https://github.com/qbox/phoenix#readme",
|
7
7
|
"license": "ISC",
|
8
8
|
"main": "src/index.js",
|
9
9
|
"bin": {
|
@@ -18,17 +18,20 @@
|
|
18
18
|
"lint": "exit 0"
|
19
19
|
},
|
20
20
|
"publishConfig": {
|
21
|
-
"registry": "
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
22
22
|
},
|
23
23
|
"repository": {
|
24
24
|
"type": "git",
|
25
|
-
"url": "git+https://github.com/qbox/
|
25
|
+
"url": "git+https://github.com/qbox/phoenix.git"
|
26
26
|
},
|
27
27
|
"bugs": {
|
28
|
-
"url": "https://github.com/qbox/
|
28
|
+
"url": "https://github.com/qbox/phoenix/issues"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@
|
31
|
+
"@types/classnames": "^2.2.7",
|
32
|
+
"@types/lodash": "^4.14.152",
|
33
|
+
"@types/react": "^16.14.5",
|
34
|
+
"@types/node": "^14.0.12",
|
32
35
|
"gulp": "^4.0.2",
|
33
36
|
"gulp-less": "^4.0.1",
|
34
37
|
"gulp-typescript": "^6.0.0-alpha.1",
|
@@ -38,16 +41,34 @@
|
|
38
41
|
"react-docgen-typescript-loader": "^3.7.2",
|
39
42
|
"rimraf": "^3.0.2",
|
40
43
|
"through2": "^4.0.2",
|
41
|
-
"webpack": "^4.35.3"
|
44
|
+
"webpack": "^4.35.3",
|
45
|
+
"@oclif/command": "^1",
|
46
|
+
"@oclif/errors": "~1.3.5",
|
47
|
+
"classnames": "^2.3.1",
|
48
|
+
"@storybook/react": "6.4.9",
|
49
|
+
"@storybook/theming": "6.4.9",
|
50
|
+
"@storybook/components": "6.4.9",
|
51
|
+
"@storybook/addon-docs": "6.4.9",
|
52
|
+
"babel-loader": "^8.1.0",
|
53
|
+
"ts-loader": "^7.0.5",
|
54
|
+
"@babel/core": "^7.0.1",
|
55
|
+
"style-loader": "^0.23.1",
|
56
|
+
"css-loader": "^3.0.0",
|
57
|
+
"less-loader": "^5.0.0",
|
58
|
+
"@mdx-js/loader": "^1.5.1",
|
59
|
+
"react-is": "^16.8.0"
|
42
60
|
},
|
43
61
|
"devDependencies": {
|
44
|
-
"
|
62
|
+
"lodash": "^4.17.15",
|
63
|
+
"react": "^16.8.6",
|
64
|
+
"antd": "4.16.3"
|
45
65
|
},
|
46
66
|
"peerDependencies": {
|
47
|
-
"
|
67
|
+
"lodash": "^4.17.15",
|
68
|
+
"react": "^16.8.6",
|
69
|
+
"antd": "4.16.3"
|
48
70
|
},
|
49
71
|
"oclif": {
|
50
72
|
"commands": "./src/cli/commands"
|
51
|
-
}
|
52
|
-
"gitHead": "238bf5cd62d1f0a46e064961bc4ff82ac63dcd6b"
|
73
|
+
}
|
53
74
|
}
|
@@ -1,8 +1,11 @@
|
|
1
1
|
const { Command } = require('@oclif/command')
|
2
2
|
const runTask = require('../../index')
|
3
|
+
const { initBuildContext } = require('../../projectHelper')
|
3
4
|
|
4
5
|
class BuildCommand extends Command {
|
5
6
|
async run() {
|
7
|
+
initBuildContext()
|
8
|
+
|
6
9
|
const { type } = this.parse(BuildCommand).args
|
7
10
|
runTask('compileTs:' + type)
|
8
11
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
const { Command, flags } = require('@oclif/command')
|
2
2
|
const { spawn } = require('child_process')
|
3
3
|
const path = require('path')
|
4
|
+
const { getProjectPath, initStorybookContext } = require('../../projectHelper')
|
4
5
|
|
5
6
|
const pandoraToolsDir = path.resolve(__dirname, '../../../')
|
6
7
|
const storybookConfigPath = path.resolve(pandoraToolsDir, './.storybook')
|
@@ -10,18 +11,27 @@ const startOptions = {
|
|
10
11
|
}
|
11
12
|
const buildOptions = {
|
12
13
|
cmd: path.resolve(pandoraToolsDir, './node_modules/.bin/build-storybook'),
|
13
|
-
supportFlags: ['config-dir', 'static-dir']
|
14
|
+
supportFlags: ['config-dir', 'static-dir', 'output-dir']
|
14
15
|
}
|
15
16
|
|
16
17
|
class StoryBookCommand extends Command {
|
17
18
|
async run() {
|
19
|
+
initStorybookContext()
|
20
|
+
|
18
21
|
const { args, flags } = this.parse(StoryBookCommand)
|
19
22
|
const { cmd, supportFlags } =
|
20
23
|
args.type === 'build' ? buildOptions : startOptions
|
21
24
|
|
22
|
-
const params = supportFlags.map(key =>
|
25
|
+
const params = supportFlags.map(key => {
|
26
|
+
let value = flags[key]
|
27
|
+
if (key === 'output-dir' && value) {
|
28
|
+
// 默认输出路径
|
29
|
+
value = getProjectPath(value)
|
30
|
+
}
|
31
|
+
return value ? `--${key} ${value}` : ''
|
32
|
+
})
|
23
33
|
|
24
|
-
spawn(cmd, params, { stdio: 'inherit', shell: true })
|
34
|
+
spawn(cmd, params, { stdio: 'inherit', shell: true, cwd: pandoraToolsDir })
|
25
35
|
}
|
26
36
|
}
|
27
37
|
|
@@ -50,8 +60,12 @@ StoryBookCommand.flags = {
|
|
50
60
|
}),
|
51
61
|
'static-dir': flags.string({
|
52
62
|
char: 's',
|
53
|
-
default: './public',
|
54
63
|
description: 'static directory'
|
64
|
+
}),
|
65
|
+
'output-dir': flags.string({
|
66
|
+
char: 'o',
|
67
|
+
default: './storybook-static',
|
68
|
+
description: 'output directory, relative to your project root'
|
55
69
|
})
|
56
70
|
}
|
57
71
|
|
package/src/gulpfile.js
CHANGED
@@ -2,11 +2,9 @@ const gulp = require('gulp')
|
|
2
2
|
const clear = require('./tasks/clear')
|
3
3
|
const compileLess = require('./tasks/less')
|
4
4
|
const compileTs = require('./tasks/ts')
|
5
|
-
const {
|
5
|
+
const { getProjectRoot, getToolsConfig } = require('./projectHelper')
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
process.on('uncaughtException', function(err) {
|
7
|
+
process.on('uncaughtException', function (err) {
|
10
8
|
console.error(err.message)
|
11
9
|
process.exit(1)
|
12
10
|
})
|
@@ -14,17 +12,29 @@ process.on('uncaughtException', function(err) {
|
|
14
12
|
gulp.task(
|
15
13
|
'compileTs:esm',
|
16
14
|
gulp.series(
|
17
|
-
() => clear(esmDir),
|
18
|
-
() =>
|
19
|
-
|
15
|
+
() => clear(getToolsConfig().esmDir),
|
16
|
+
() =>
|
17
|
+
compileTs(getProjectRoot(), getToolsConfig().esmDir, {
|
18
|
+
module: 'esnext'
|
19
|
+
}),
|
20
|
+
() => {
|
21
|
+
const { srcDir, esmDir } = getToolsConfig()
|
22
|
+
return compileLess(srcDir, esmDir)
|
23
|
+
}
|
20
24
|
)
|
21
25
|
)
|
22
26
|
|
23
27
|
gulp.task(
|
24
28
|
'compileTs:cjs',
|
25
29
|
gulp.series(
|
26
|
-
() => clear(libDir),
|
27
|
-
() =>
|
28
|
-
|
30
|
+
() => clear(getToolsConfig().libDir),
|
31
|
+
() =>
|
32
|
+
compileTs(getProjectRoot(), getToolsConfig().libDir, {
|
33
|
+
module: 'commonjs'
|
34
|
+
}),
|
35
|
+
() => {
|
36
|
+
const { srcDir, libDir } = getToolsConfig()
|
37
|
+
return compileLess(srcDir, libDir)
|
38
|
+
}
|
29
39
|
)
|
30
40
|
)
|
package/src/projectHelper.js
CHANGED
@@ -1,9 +1,64 @@
|
|
1
1
|
const fs = require('fs')
|
2
2
|
const path = require('path')
|
3
3
|
|
4
|
-
const
|
4
|
+
const projectConfigFile = path.join(__dirname, '../project.json')
|
5
|
+
|
6
|
+
let isStorybookContext = true
|
7
|
+
|
8
|
+
function initBuildContext() {
|
9
|
+
initContext('build')
|
10
|
+
}
|
11
|
+
|
12
|
+
function initStorybookContext() {
|
13
|
+
initContext('storybook')
|
14
|
+
}
|
15
|
+
|
16
|
+
function initContext(context) {
|
17
|
+
if (context === 'build') {
|
18
|
+
isStorybookContext = false
|
19
|
+
}
|
20
|
+
|
21
|
+
if (isStorybookContext) {
|
22
|
+
const projectRoot = process.cwd()
|
23
|
+
let data = {}
|
24
|
+
try {
|
25
|
+
data = getProjectConfig()
|
26
|
+
} catch (e) {
|
27
|
+
// do nothing
|
28
|
+
}
|
29
|
+
console.log('[pandora tools] init storybook project root: ', projectRoot)
|
30
|
+
setProjectConfig({ ...data, projectRoot })
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function getProjectConfig() {
|
35
|
+
if (fs.existsSync(projectConfigFile)) {
|
36
|
+
const raw = fs.readFileSync(projectConfigFile)
|
37
|
+
return JSON.parse(raw)
|
38
|
+
}
|
39
|
+
return {}
|
40
|
+
}
|
41
|
+
|
42
|
+
function setProjectConfig(config) {
|
43
|
+
fs.writeFileSync(projectConfigFile, JSON.stringify(config))
|
44
|
+
}
|
45
|
+
|
46
|
+
function getProjectRoot() {
|
47
|
+
let projectRoot = process.cwd()
|
48
|
+
if (isStorybookContext) {
|
49
|
+
try {
|
50
|
+
const config = getProjectConfig()
|
51
|
+
projectRoot = config.projectRoot
|
52
|
+
} catch (e) {
|
53
|
+
// do nothing
|
54
|
+
}
|
55
|
+
}
|
56
|
+
console.log('[pandora tools] get project root', projectRoot)
|
57
|
+
return projectRoot
|
58
|
+
}
|
5
59
|
|
6
60
|
function getProjectPath(pathStr) {
|
61
|
+
const projectRoot = getProjectRoot()
|
7
62
|
return path.resolve(projectRoot, pathStr)
|
8
63
|
}
|
9
64
|
|
@@ -22,7 +77,8 @@ function getToolsConfig(pathStr) {
|
|
22
77
|
{
|
23
78
|
srcDir: './src',
|
24
79
|
esmDir: './es',
|
25
|
-
libDir: './lib'
|
80
|
+
libDir: './lib',
|
81
|
+
mainFileName: 'index'
|
26
82
|
},
|
27
83
|
toolsConfig
|
28
84
|
)
|
@@ -32,9 +88,16 @@ function getWebpackConfig(pathStr) {
|
|
32
88
|
return getConfig(pathStr || 'webpack.config.js')
|
33
89
|
}
|
34
90
|
|
91
|
+
function getPackageJSON() {
|
92
|
+
return getConfig('package.json')
|
93
|
+
}
|
94
|
+
|
35
95
|
module.exports = {
|
36
|
-
|
96
|
+
initBuildContext,
|
97
|
+
initStorybookContext,
|
98
|
+
getProjectRoot,
|
37
99
|
getProjectPath,
|
38
100
|
getToolsConfig,
|
39
|
-
getWebpackConfig
|
101
|
+
getWebpackConfig,
|
102
|
+
getPackageJSON
|
40
103
|
}
|