@qn-pandora/pandora-tools 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,11 @@
1
+ # Change Log - @qn-pandora/pandora-tools
2
+
3
+ This log was last generated on Mon, 20 Dec 2021 09:51:49 GMT and should not be manually modified.
4
+
5
+ ## 1.0.0
6
+ Mon, 20 Dec 2021 09:51:49 GMT
7
+
8
+ ### Breaking changes
9
+
10
+ - 仓库迁移至rush后统一发个大版本
11
+
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@qn-pandora/pandora-tools",
3
- "version": "0.0.5",
3
+ "version": "1.0.0",
4
4
  "description": "Pandora Lib 常用开发&打包工具集",
5
5
  "author": "pandora <pandora@qiniu.com>",
6
- "homepage": "https://github.com/qbox/pandora-visualization#readme",
6
+ "homepage": "https://github.com/qbox/phoenix#readme",
7
7
  "license": "ISC",
8
8
  "main": "src/index.js",
9
9
  "bin": {
@@ -18,27 +18,57 @@
18
18
  "lint": "exit 0"
19
19
  },
20
20
  "publishConfig": {
21
- "registry": "http://registry.npmjs.org/"
21
+ "registry": "https://registry.npmjs.org/"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/qbox/pandora-visualization.git"
25
+ "url": "git+https://github.com/qbox/phoenix.git"
26
26
  },
27
27
  "bugs": {
28
- "url": "https://github.com/qbox/pandora-visualization/issues"
28
+ "url": "https://github.com/qbox/phoenix/issues"
29
29
  },
30
30
  "dependencies": {
31
+ "@types/classnames": "^2.2.7",
32
+ "@types/lodash": "^4.14.152",
33
+ "@types/react": "^16.14.5",
34
+ "@types/node": "^14.0.12",
31
35
  "gulp": "^4.0.2",
32
36
  "gulp-less": "^4.0.1",
33
37
  "gulp-typescript": "^6.0.0-alpha.1",
34
38
  "less-plugin-autoprefix": "^2.0.0",
35
39
  "merge2": "^1.4.1",
36
40
  "oclif": "^1.16.1",
41
+ "react-docgen-typescript-loader": "^3.7.2",
37
42
  "rimraf": "^3.0.2",
38
- "through2": "^4.0.2"
43
+ "through2": "^4.0.2",
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"
60
+ },
61
+ "devDependencies": {
62
+ "lodash": "^4.17.15",
63
+ "react": "^16.8.6",
64
+ "antd": "4.16.3"
65
+ },
66
+ "peerDependencies": {
67
+ "lodash": "^4.17.15",
68
+ "react": "^16.8.6",
69
+ "antd": "4.16.3"
39
70
  },
40
71
  "oclif": {
41
72
  "commands": "./src/cli/commands"
42
- },
43
- "gitHead": "048d1bce59f7a06cc2c29ed9451bc1fffad9f9dd"
73
+ }
44
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
  }
@@ -0,0 +1,72 @@
1
+ const { Command, flags } = require('@oclif/command')
2
+ const { spawn } = require('child_process')
3
+ const path = require('path')
4
+ const { getProjectPath, initStorybookContext } = require('../../projectHelper')
5
+
6
+ const pandoraToolsDir = path.resolve(__dirname, '../../../')
7
+ const storybookConfigPath = path.resolve(pandoraToolsDir, './.storybook')
8
+ const startOptions = {
9
+ cmd: path.resolve(pandoraToolsDir, './node_modules/.bin/start-storybook'),
10
+ supportFlags: ['config-dir', 'port', 'static-dir']
11
+ }
12
+ const buildOptions = {
13
+ cmd: path.resolve(pandoraToolsDir, './node_modules/.bin/build-storybook'),
14
+ supportFlags: ['config-dir', 'static-dir', 'output-dir']
15
+ }
16
+
17
+ class StoryBookCommand extends Command {
18
+ async run() {
19
+ initStorybookContext()
20
+
21
+ const { args, flags } = this.parse(StoryBookCommand)
22
+ const { cmd, supportFlags } =
23
+ args.type === 'build' ? buildOptions : startOptions
24
+
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
+ })
33
+
34
+ spawn(cmd, params, { stdio: 'inherit', shell: true, cwd: pandoraToolsDir })
35
+ }
36
+ }
37
+
38
+ StoryBookCommand.description = `start or build storybook of components`
39
+
40
+ StoryBookCommand.args = [
41
+ {
42
+ name: 'type',
43
+ require: true,
44
+ description: 'run type',
45
+ default: 'start',
46
+ options: ['start', 'build']
47
+ }
48
+ ]
49
+
50
+ StoryBookCommand.flags = {
51
+ 'config-dir': flags.string({
52
+ char: 'c',
53
+ default: storybookConfigPath,
54
+ description: 'storybook config path'
55
+ }),
56
+ port: flags.integer({
57
+ char: 'p',
58
+ default: 9000,
59
+ description: 'port of storybook run'
60
+ }),
61
+ 'static-dir': flags.string({
62
+ char: 's',
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'
69
+ })
70
+ }
71
+
72
+ module.exports = StoryBookCommand
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 { projectRoot, getToolsConfig } = require('./projectHelper')
5
+ const { getProjectRoot, getToolsConfig } = require('./projectHelper')
6
6
 
7
- const { srcDir, esmDir, libDir } = getToolsConfig()
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
- () => compileTs(projectRoot, esmDir, { module: 'ES6' }),
19
- () => compileLess(srcDir, esmDir)
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
- () => compileTs(projectRoot, libDir, { module: 'commonjs' }),
28
- () => compileLess(srcDir, libDir)
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
  )
@@ -1,9 +1,64 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
 
4
- const projectRoot = process.cwd()
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
- projectRoot,
96
+ initBuildContext,
97
+ initStorybookContext,
98
+ getProjectRoot,
37
99
  getProjectPath,
38
100
  getToolsConfig,
39
- getWebpackConfig
101
+ getWebpackConfig,
102
+ getPackageJSON
40
103
  }
package/src/tasks/less.js CHANGED
@@ -38,7 +38,7 @@ function compileLess(srcDir, outDir) {
38
38
  .src(`${srcDir}/**/*.less`)
39
39
  .pipe(
40
40
  gulpLess({
41
- paths: [srcDir],
41
+ paths: [srcDir, 'node_modules'],
42
42
  plugins: [autoprefix],
43
43
  javascriptEnabled: true
44
44
  })