@qn-pandora/pandora-tools 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "name": "@qn-pandora/pandora-tools",
3
3
  "entries": [
4
4
  {
5
- "version": "1.0.1",
6
- "tag": "@qn-pandora/pandora-tools_v1.0.1",
7
- "date": "Fri, 28 Jan 2022 15:30:56 GMT",
5
+ "version": "2.0.0",
6
+ "tag": "@qn-pandora/pandora-tools_v2.0.0",
7
+ "date": "Tue, 14 Jun 2022 09:21:39 GMT",
8
8
  "comments": {
9
- "patch": [
9
+ "major": [
10
10
  {
11
- "comment": "1.28publish"
11
+ "comment": "很久没发版了,统一发个大版本"
12
12
  }
13
13
  ]
14
14
  }
package/CHANGELOG.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Change Log - @qn-pandora/pandora-tools
2
2
 
3
- This log was last generated on Fri, 28 Jan 2022 15:30:56 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 14 Jun 2022 09:21:39 GMT and should not be manually modified.
4
4
 
5
- ## 1.0.1
5
+ ## 2.0.0
6
6
 
7
- Fri, 28 Jan 2022 15:30:56 GMT
7
+ Tue, 14 Jun 2022 09:21:39 GMT
8
8
 
9
- ### Patches
9
+ ### Breaking changes
10
10
 
11
- - 1.28publish
11
+ - 很久没发版了,统一发个大版本
12
12
 
13
13
  ## 1.0.0
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qn-pandora/pandora-tools",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Pandora Lib 常用开发&打包工具集",
5
5
  "author": "pandora <pandora@qiniu.com>",
6
6
  "homepage": "https://github.com/qbox/phoenix#readme",
@@ -44,7 +44,7 @@
44
44
  "webpack": "^4.35.3",
45
45
  "@oclif/command": "^1",
46
46
  "@oclif/errors": "~1.3.5",
47
- "classnames": "^2.3.1",
47
+ "classnames": "^2.2.6",
48
48
  "@storybook/react": "6.4.9",
49
49
  "@storybook/theming": "6.4.9",
50
50
  "@storybook/components": "6.4.9",
@@ -56,17 +56,15 @@
56
56
  "css-loader": "^3.0.0",
57
57
  "less-loader": "^5.0.0",
58
58
  "@mdx-js/loader": "^1.5.1",
59
- "react-is": "^16.8.0"
59
+ "react-is": "^16.8.0",
60
+ "lodash": "^4.17.15",
61
+ "antd": "4.17.1"
60
62
  },
61
63
  "devDependencies": {
62
- "lodash": "^4.17.15",
63
- "react": "^16.8.6",
64
- "antd": "4.16.9"
64
+ "react": "^16.8.6"
65
65
  },
66
66
  "peerDependencies": {
67
- "lodash": "^4.17.15",
68
- "react": "^16.8.6",
69
- "antd": "4.16.9"
67
+ "react": "^16.8.6"
70
68
  },
71
69
  "oclif": {
72
70
  "commands": "./src/cli/commands"
@@ -24,7 +24,7 @@ class StoryBookCommand extends Command {
24
24
 
25
25
  const params = supportFlags.map(key => {
26
26
  let value = flags[key]
27
- if (key === 'output-dir' && value) {
27
+ if (key === 'output-dir' && !value) {
28
28
  // 默认输出路径
29
29
  value = getProjectPath(value)
30
30
  }
@@ -0,0 +1,32 @@
1
+ const { Command } = require('@oclif/command')
2
+ const runTask = require('../../index')
3
+ const { initBuildContext } = require('../../projectHelper')
4
+
5
+ class WatchLessCommand extends Command {
6
+ async run() {
7
+ initBuildContext()
8
+
9
+ const { type } = this.parse(WatchLessCommand).args
10
+ runTask('watchLess:' + type)
11
+ }
12
+ }
13
+
14
+ WatchLessCommand.description = `Watch and build less files to esm or cjs
15
+ this command will
16
+ 1. watching less files, run next steps when less files changed
17
+ 2. copy .less
18
+ 3. generate index.less which import all .less files
19
+ 4. build all .less to .css
20
+ you can set esmDir, cjsDir, srcDir in pandora-tools.config.json`
21
+
22
+ WatchLessCommand.args = [
23
+ {
24
+ name: 'type',
25
+ require: true,
26
+ description: 'module type',
27
+ default: 'esm',
28
+ options: ['esm', 'cjs']
29
+ }
30
+ ]
31
+
32
+ module.exports = WatchLessCommand
package/src/gulpfile.js CHANGED
@@ -2,13 +2,48 @@ 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 { getProjectRoot, getToolsConfig } = require('./projectHelper')
5
+ const {
6
+ getProjectRoot,
7
+ getToolsConfig,
8
+ getPackageJSON
9
+ } = require('./projectHelper')
6
10
 
7
11
  process.on('uncaughtException', function (err) {
8
12
  console.error(err.message)
9
13
  process.exit(1)
10
14
  })
11
15
 
16
+ function compileLessToEsm() {
17
+ const { srcDir, esmDir } = getToolsConfig()
18
+ return compileLess(srcDir, esmDir)
19
+ }
20
+
21
+ function compileLessToCjs() {
22
+ const { srcDir, libDir } = getToolsConfig()
23
+ return compileLess(srcDir, libDir)
24
+ }
25
+
26
+ async function building() {
27
+ console.log('building')
28
+ }
29
+
30
+ async function done() {
31
+ console.log('done')
32
+ }
33
+
34
+ /**
35
+ * watch 模式下构建报错不应该退出程序
36
+ */
37
+ function catchErr(fn) {
38
+ return async () => {
39
+ try {
40
+ return await fn()
41
+ } catch (e) {
42
+ console.error(e)
43
+ }
44
+ }
45
+ }
46
+
12
47
  gulp.task(
13
48
  'compileTs:esm',
14
49
  gulp.series(
@@ -17,10 +52,7 @@ gulp.task(
17
52
  compileTs(getProjectRoot(), getToolsConfig().esmDir, {
18
53
  module: 'esnext'
19
54
  }),
20
- () => {
21
- const { srcDir, esmDir } = getToolsConfig()
22
- return compileLess(srcDir, esmDir)
23
- }
55
+ compileLessToEsm
24
56
  )
25
57
  )
26
58
 
@@ -32,9 +64,26 @@ gulp.task(
32
64
  compileTs(getProjectRoot(), getToolsConfig().libDir, {
33
65
  module: 'commonjs'
34
66
  }),
35
- () => {
36
- const { srcDir, libDir } = getToolsConfig()
37
- return compileLess(srcDir, libDir)
38
- }
67
+ compileLessToCjs
39
68
  )
40
69
  )
70
+
71
+ gulp.task('watchLess:esm', function () {
72
+ console.log(
73
+ `[pandora tools] watchLess:esm watching ${getPackageJSON().name}...`
74
+ )
75
+ return gulp.watch(
76
+ `${getToolsConfig().srcDir}/**/*.less`,
77
+ gulp.series(building, catchErr(compileLessToEsm), done)
78
+ )
79
+ })
80
+
81
+ gulp.task('watchLess:cjs', function () {
82
+ console.log(
83
+ `[pandora tools] watchLess:cjs watching ${getPackageJSON().name}...`
84
+ )
85
+ return gulp.watch(
86
+ `${getToolsConfig().srcDir}/**/*.less`,
87
+ gulp.series(building, catchErr(compileLessToCjs), done)
88
+ )
89
+ })
@@ -53,7 +53,6 @@ function getProjectRoot() {
53
53
  // do nothing
54
54
  }
55
55
  }
56
- console.log('[pandora tools] get project root', projectRoot)
57
56
  return projectRoot
58
57
  }
59
58
 
package/src/tasks/less.js CHANGED
@@ -9,46 +9,56 @@ const autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
9
9
 
10
10
  function copyLess(srcDir, outDir) {
11
11
  const imports = []
12
- return gulp
13
- .src(`${srcDir}/**/*.less`)
14
- .pipe(
15
- through2.obj(function(file, encoding, next) {
16
- this.push(file)
17
- const filePath = path.relative(outDir, file.path)
18
- imports.push(`@import './${filePath}';`)
19
- next()
20
- })
21
- )
22
- .pipe(gulp.dest(outDir))
23
- .on('finish', function() {
24
- if (imports.length === 0) {
25
- return
26
- }
27
- // when copy finish write root index.less
28
- fs.writeFileSync(
29
- path.resolve(outDir, 'index.less'),
30
- imports.join('\n'),
31
- 'utf8'
12
+ return new Promise(function (resolve, reject) {
13
+ gulp
14
+ .src(`${srcDir}/**/*.less`)
15
+ .on('error', reject)
16
+ .pipe(
17
+ through2.obj(function (file, _, next) {
18
+ this.push(file)
19
+ const filePath = path.relative(outDir, file.path)
20
+ imports.push(`@import './${filePath}';`)
21
+ next()
22
+ })
32
23
  )
33
- })
24
+ .on('error', reject)
25
+ .pipe(gulp.dest(outDir))
26
+ .on('error', reject)
27
+ .on('finish', function () {
28
+ if (imports.length === 0) {
29
+ return
30
+ }
31
+ // when copy finish write root index.less
32
+ fs.writeFileSync(
33
+ path.resolve(outDir, 'index.less'),
34
+ imports.join('\n'),
35
+ 'utf8'
36
+ )
37
+ resolve()
38
+ })
39
+ })
34
40
  }
35
41
 
36
42
  function compileLess(srcDir, outDir) {
37
- return gulp
38
- .src(`${srcDir}/**/*.less`)
39
- .pipe(
40
- gulpLess({
41
- paths: [srcDir, 'node_modules'],
42
- plugins: [autoprefix],
43
- javascriptEnabled: true
44
- })
45
- )
46
- .pipe(gulp.dest(outDir))
43
+ return new Promise((resolve, reject) => {
44
+ gulp
45
+ .src(`${srcDir}/**/*.less`)
46
+ .on('error', reject)
47
+ .pipe(
48
+ gulpLess({
49
+ paths: [srcDir, 'node_modules'],
50
+ plugins: [autoprefix],
51
+ javascriptEnabled: true
52
+ })
53
+ )
54
+ .on('error', reject)
55
+ .pipe(gulp.dest(outDir))
56
+ .on('error', reject)
57
+ .on('finish', resolve)
58
+ })
47
59
  }
48
60
 
49
- module.exports = function(srcDir, outDir) {
50
- return gulp.series(
51
- () => copyLess(srcDir, outDir),
52
- () => compileLess(outDir, outDir)
53
- )()
61
+ module.exports = async function (srcDir, outDir) {
62
+ await copyLess(srcDir, outDir)
63
+ await compileLess(outDir, outDir)
54
64
  }