@qn-pandora/pandora-tools 2.0.11 → 2.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +185 -161
- package/CHANGELOG.md +123 -107
- package/README.md +19 -19
- package/bin/pandora-tools +3 -3
- package/package.json +69 -69
- package/src/cli/commands/build.js +32 -32
- package/src/cli/commands/storybook.js +72 -72
- package/src/cli/commands/watchLess.js +32 -32
- package/src/cli/index.js +6 -6
- package/src/gulpfile.js +89 -89
- package/src/index.js +6 -6
- package/src/projectHelper.js +102 -102
- package/src/tasks/clear.js +6 -6
- package/src/tasks/less.js +64 -64
- package/src/tasks/ts.js +54 -54
package/src/projectHelper.js
CHANGED
@@ -1,102 +1,102 @@
|
|
1
|
-
const fs = require('fs')
|
2
|
-
const path = require('path')
|
3
|
-
|
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
|
-
return projectRoot
|
57
|
-
}
|
58
|
-
|
59
|
-
function getProjectPath(pathStr) {
|
60
|
-
const projectRoot = getProjectRoot()
|
61
|
-
return path.resolve(projectRoot, pathStr)
|
62
|
-
}
|
63
|
-
|
64
|
-
function getConfig(pathStr) {
|
65
|
-
const configPath = getProjectPath(pathStr)
|
66
|
-
if (fs.existsSync(configPath)) {
|
67
|
-
return require(configPath)
|
68
|
-
}
|
69
|
-
|
70
|
-
return {}
|
71
|
-
}
|
72
|
-
|
73
|
-
function getToolsConfig(pathStr) {
|
74
|
-
const toolsConfig = getConfig(pathStr || '.pandora-tools.config.js')
|
75
|
-
return Object.assign(
|
76
|
-
{
|
77
|
-
srcDir: './src',
|
78
|
-
esmDir: './es',
|
79
|
-
libDir: './lib',
|
80
|
-
mainFileName: 'index'
|
81
|
-
},
|
82
|
-
toolsConfig
|
83
|
-
)
|
84
|
-
}
|
85
|
-
|
86
|
-
function getWebpackConfig(pathStr) {
|
87
|
-
return getConfig(pathStr || 'webpack.config.js')
|
88
|
-
}
|
89
|
-
|
90
|
-
function getPackageJSON() {
|
91
|
-
return getConfig('package.json')
|
92
|
-
}
|
93
|
-
|
94
|
-
module.exports = {
|
95
|
-
initBuildContext,
|
96
|
-
initStorybookContext,
|
97
|
-
getProjectRoot,
|
98
|
-
getProjectPath,
|
99
|
-
getToolsConfig,
|
100
|
-
getWebpackConfig,
|
101
|
-
getPackageJSON
|
102
|
-
}
|
1
|
+
const fs = require('fs')
|
2
|
+
const path = require('path')
|
3
|
+
|
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
|
+
return projectRoot
|
57
|
+
}
|
58
|
+
|
59
|
+
function getProjectPath(pathStr) {
|
60
|
+
const projectRoot = getProjectRoot()
|
61
|
+
return path.resolve(projectRoot, pathStr)
|
62
|
+
}
|
63
|
+
|
64
|
+
function getConfig(pathStr) {
|
65
|
+
const configPath = getProjectPath(pathStr)
|
66
|
+
if (fs.existsSync(configPath)) {
|
67
|
+
return require(configPath)
|
68
|
+
}
|
69
|
+
|
70
|
+
return {}
|
71
|
+
}
|
72
|
+
|
73
|
+
function getToolsConfig(pathStr) {
|
74
|
+
const toolsConfig = getConfig(pathStr || '.pandora-tools.config.js')
|
75
|
+
return Object.assign(
|
76
|
+
{
|
77
|
+
srcDir: './src',
|
78
|
+
esmDir: './es',
|
79
|
+
libDir: './lib',
|
80
|
+
mainFileName: 'index'
|
81
|
+
},
|
82
|
+
toolsConfig
|
83
|
+
)
|
84
|
+
}
|
85
|
+
|
86
|
+
function getWebpackConfig(pathStr) {
|
87
|
+
return getConfig(pathStr || 'webpack.config.js')
|
88
|
+
}
|
89
|
+
|
90
|
+
function getPackageJSON() {
|
91
|
+
return getConfig('package.json')
|
92
|
+
}
|
93
|
+
|
94
|
+
module.exports = {
|
95
|
+
initBuildContext,
|
96
|
+
initStorybookContext,
|
97
|
+
getProjectRoot,
|
98
|
+
getProjectPath,
|
99
|
+
getToolsConfig,
|
100
|
+
getWebpackConfig,
|
101
|
+
getPackageJSON
|
102
|
+
}
|
package/src/tasks/clear.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
const rimraf = require('rimraf')
|
2
|
-
|
3
|
-
module.exports = function(dir) {
|
4
|
-
rimraf.sync(dir)
|
5
|
-
return Promise.resolve()
|
6
|
-
}
|
1
|
+
const rimraf = require('rimraf')
|
2
|
+
|
3
|
+
module.exports = function(dir) {
|
4
|
+
rimraf.sync(dir)
|
5
|
+
return Promise.resolve()
|
6
|
+
}
|
package/src/tasks/less.js
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
const gulp = require('gulp')
|
2
|
-
const gulpLess = require('gulp-less')
|
3
|
-
const path = require('path')
|
4
|
-
const fs = require('fs')
|
5
|
-
const through2 = require('through2')
|
6
|
-
const LessAutoprefix = require('less-plugin-autoprefix')
|
7
|
-
|
8
|
-
const autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
|
9
|
-
|
10
|
-
function copyLess(srcDir, outDir) {
|
11
|
-
const imports = []
|
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
|
-
})
|
23
|
-
)
|
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
|
-
})
|
40
|
-
}
|
41
|
-
|
42
|
-
function compileLess(srcDir, 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
|
-
})
|
59
|
-
}
|
60
|
-
|
61
|
-
module.exports = async function (srcDir, outDir) {
|
62
|
-
await copyLess(srcDir, outDir)
|
63
|
-
await compileLess(outDir, outDir)
|
64
|
-
}
|
1
|
+
const gulp = require('gulp')
|
2
|
+
const gulpLess = require('gulp-less')
|
3
|
+
const path = require('path')
|
4
|
+
const fs = require('fs')
|
5
|
+
const through2 = require('through2')
|
6
|
+
const LessAutoprefix = require('less-plugin-autoprefix')
|
7
|
+
|
8
|
+
const autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
|
9
|
+
|
10
|
+
function copyLess(srcDir, outDir) {
|
11
|
+
const imports = []
|
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
|
+
})
|
23
|
+
)
|
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
|
+
})
|
40
|
+
}
|
41
|
+
|
42
|
+
function compileLess(srcDir, 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
|
+
})
|
59
|
+
}
|
60
|
+
|
61
|
+
module.exports = async function (srcDir, outDir) {
|
62
|
+
await copyLess(srcDir, outDir)
|
63
|
+
await compileLess(outDir, outDir)
|
64
|
+
}
|
package/src/tasks/ts.js
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
const path = require('path')
|
2
|
-
const gulp = require('gulp')
|
3
|
-
const tsGulp = require('gulp-typescript')
|
4
|
-
const merge = require('merge2')
|
5
|
-
|
6
|
-
module.exports = function(projectDir, outDir, extraTsConfig) {
|
7
|
-
const tsProject = tsGulp.createProject(
|
8
|
-
path.resolve(projectDir, 'tsconfig.json'),
|
9
|
-
extraTsConfig
|
10
|
-
)
|
11
|
-
const tsResult = tsProject.src().pipe(tsProject())
|
12
|
-
return merge([
|
13
|
-
tsResult.js.pipe(gulp.dest(outDir)),
|
14
|
-
tsResult.dts.pipe(gulp.dest(outDir))
|
15
|
-
])
|
16
|
-
}
|
17
|
-
|
18
|
-
/* function compileByWebpack(done) {
|
19
|
-
rimraf.sync(distDir)
|
20
|
-
process.env.RUN_ENV = 'PRODUCTION'
|
21
|
-
webpack(getWebpackConfig(), (err, stats) => {
|
22
|
-
if (err) {
|
23
|
-
console.error(err.stack || err)
|
24
|
-
if (err.details) {
|
25
|
-
console.error(err.details)
|
26
|
-
}
|
27
|
-
return
|
28
|
-
}
|
29
|
-
|
30
|
-
const info = stats.toJson()
|
31
|
-
|
32
|
-
if (stats.hasErrors()) {
|
33
|
-
console.error(info.errors)
|
34
|
-
}
|
35
|
-
|
36
|
-
if (stats.hasWarnings()) {
|
37
|
-
console.warn(info.warnings)
|
38
|
-
}
|
39
|
-
|
40
|
-
const buildInfo = stats.toString({
|
41
|
-
colors: true,
|
42
|
-
children: true,
|
43
|
-
chunks: false,
|
44
|
-
modules: false,
|
45
|
-
chunkModules: false,
|
46
|
-
hash: false,
|
47
|
-
version: false
|
48
|
-
})
|
49
|
-
console.log(buildInfo)
|
50
|
-
|
51
|
-
done(0)
|
52
|
-
})
|
53
|
-
}
|
54
|
-
gulp.task('compileTs:dist', compileByWebpack)*/
|
1
|
+
const path = require('path')
|
2
|
+
const gulp = require('gulp')
|
3
|
+
const tsGulp = require('gulp-typescript')
|
4
|
+
const merge = require('merge2')
|
5
|
+
|
6
|
+
module.exports = function(projectDir, outDir, extraTsConfig) {
|
7
|
+
const tsProject = tsGulp.createProject(
|
8
|
+
path.resolve(projectDir, 'tsconfig.json'),
|
9
|
+
extraTsConfig
|
10
|
+
)
|
11
|
+
const tsResult = tsProject.src().pipe(tsProject())
|
12
|
+
return merge([
|
13
|
+
tsResult.js.pipe(gulp.dest(outDir)),
|
14
|
+
tsResult.dts.pipe(gulp.dest(outDir))
|
15
|
+
])
|
16
|
+
}
|
17
|
+
|
18
|
+
/* function compileByWebpack(done) {
|
19
|
+
rimraf.sync(distDir)
|
20
|
+
process.env.RUN_ENV = 'PRODUCTION'
|
21
|
+
webpack(getWebpackConfig(), (err, stats) => {
|
22
|
+
if (err) {
|
23
|
+
console.error(err.stack || err)
|
24
|
+
if (err.details) {
|
25
|
+
console.error(err.details)
|
26
|
+
}
|
27
|
+
return
|
28
|
+
}
|
29
|
+
|
30
|
+
const info = stats.toJson()
|
31
|
+
|
32
|
+
if (stats.hasErrors()) {
|
33
|
+
console.error(info.errors)
|
34
|
+
}
|
35
|
+
|
36
|
+
if (stats.hasWarnings()) {
|
37
|
+
console.warn(info.warnings)
|
38
|
+
}
|
39
|
+
|
40
|
+
const buildInfo = stats.toString({
|
41
|
+
colors: true,
|
42
|
+
children: true,
|
43
|
+
chunks: false,
|
44
|
+
modules: false,
|
45
|
+
chunkModules: false,
|
46
|
+
hash: false,
|
47
|
+
version: false
|
48
|
+
})
|
49
|
+
console.log(buildInfo)
|
50
|
+
|
51
|
+
done(0)
|
52
|
+
})
|
53
|
+
}
|
54
|
+
gulp.task('compileTs:dist', compileByWebpack)*/
|