Skip to content

Commit d7a6c58

Browse files
authored
Merge pull request #80 from ice-lab/ice-scripts/release-2.1.15
ice-scripts/release-2.1.16
2 parents 43dbef8 + ea73323 commit d7a6c58

File tree

10 files changed

+82
-84
lines changed

10 files changed

+82
-84
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 2.1.16
4+
5+
- [feat] support process.env.DISABLE_COLLECT to disable pv collect
6+
7+
## 2.1.15
8+
9+
- [feat] cli option --skip-compile for skip webpack compile
10+
311
## 2.1.14
412

513
- [feat] support postcssrc/postcss.config.js #2952

packages/ice-plugin-component/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.10
4+
5+
- [feat] generate declaration when compile ts
6+
37
## 0.1.9
48

59
- [feat] support basic component @ali/deep for style generate

packages/ice-plugin-component/lib/compile/component/buildSrc.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* - 生成 style.js 和 index.scss
66
*/
77

8-
const { createReadStream, createWriteStream, writeFileSync } = require('fs');
8+
const { createReadStream, createWriteStream, writeFileSync, ensureDirSync } = require('fs-extra');
99
const babel = require('@babel/core');
1010
const glob = require('glob');
1111
const mkdirp = require('mkdirp');
1212
const path = require('path');
1313
const rimraf = require('rimraf');
14+
const ts = require('typescript');
1415

1516
module.exports = function componentBuild({ babelConfig, rootDir, log }) {
1617
const srcDir = path.join(rootDir, 'src');
@@ -54,6 +55,7 @@ module.exports = function componentBuild({ babelConfig, rootDir, log }) {
5455
filename: file,
5556
}));
5657
writeFileSync(path.format(destData), code, 'utf-8');
58+
dtsCompile({ filePath: file, sourceFile: source, destPath: libDir });
5759
log.info(`Compile ${file}`);
5860
}
5961

@@ -69,4 +71,34 @@ module.exports = function componentBuild({ babelConfig, rootDir, log }) {
6971
log.info(`Copy ${file}`);
7072
});
7173
}
74+
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
75+
function dtsCompile({ filePath, sourceFile, destPath }) {
76+
const REG_TS = /\.(tsx?)$/;
77+
const isTS = REG_TS.test(filePath);
78+
if (!isTS) return;
79+
const compilerOptions = {
80+
allowJs: true,
81+
declaration: true,
82+
emitDeclarationOnly: true,
83+
};
84+
const dtsPath = filePath.replace(REG_TS, '.d.ts');
85+
const targetPath = path.join(destPath, dtsPath);
86+
// Create a Program with an in-memory emit
87+
let createdFiles = {};
88+
const host = ts.createCompilerHost(compilerOptions);
89+
host.writeFile = (fileName, contents) => createdFiles[fileName] = contents;
90+
// Prepare and emit the d.ts files
91+
const program = ts.createProgram([sourceFile], compilerOptions, host);
92+
program.emit();
93+
const fileNamesDTS = sourceFile.replace(REG_TS, '.d.ts');
94+
const content = createdFiles[fileNamesDTS];
95+
// write file
96+
if (content) {
97+
ensureDirSync(path.dirname(targetPath));
98+
writeFileSync(targetPath, content, 'utf-8');
99+
log.info(`Generate ${path.basename(targetPath)}`);
100+
}
101+
// release
102+
createdFiles = null;
103+
}
72104
};

packages/ice-plugin-component/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ module.exports = ({ context, chainWebpack, onHook, log }, opts = {}) => {
124124
if (hasAdaptor) {
125125
// generate adaptor index.scss
126126
const sassContent = resolveSassImport('main.scss', path.resolve(rootDir, 'src'));
127+
fse.ensureDirSync(path.join(rootDir, 'build'));
127128
fse.writeFileSync(path.resolve(rootDir, 'build/index.scss'), sassContent, 'utf-8');
128129
// adaptor build
129130
reRun();

packages/ice-plugin-component/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ice-plugin-component",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "ice plugin for develop component",
55
"main": "lib/index.js",
66
"scripts": {
@@ -27,6 +27,7 @@
2727
"npmlog": "^4.1.2",
2828
"prismjs": "^1.16.0",
2929
"resolve": "^1.11.0",
30-
"resolve-sass-import": "^0.1.0"
30+
"resolve-sass-import": "^0.1.0",
31+
"typescript": "^3.7.3"
3132
}
3233
}

packages/ice-scripts/bin/ice-scripts-build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ program
88
.option('--config <config>', 'use custom config')
99
.option('--analyzer', '开启构建分析')
1010
.option('--analyzer-port', '设置分析端口号')
11+
.option('--skip-compile', 'skip webpack compile, excute hooks for component compile')
1112
.parse(process.argv);
1213

1314
(async () => {

packages/ice-scripts/lib/commands/build.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const webpack = require('webpack');
33
const { collectDetail } = require('@alifd/fusion-collector');
44

55
const iceScriptsPkgData = require('../../package.json');
6-
const goldlog = require('../utils/goldlog');
76
const log = require('../utils/log');
87
const checkDepsInstalled = require('../utils/checkDepsInstalled');
98

@@ -16,10 +15,6 @@ const checkDepsInstalled = require('../utils/checkDepsInstalled');
1615
*/
1716
module.exports = async function (context) {
1817
const { applyHook, commandArgs, rootDir, webpackConfig, pkg } = context;
19-
goldlog('version', {
20-
version: iceScriptsPkgData.version,
21-
});
22-
goldlog('build', commandArgs);
2318
log.verbose('build cliOptions', commandArgs);
2419

2520
await applyHook('beforeBuild');
@@ -29,7 +24,7 @@ module.exports = async function (context) {
2924
return Promise.reject(new Error('项目依赖未安装,请先安装依赖。'));
3025
}
3126

32-
if (!pkg.componentConfig && !pkg.blockConfig) {
27+
if (!pkg.componentConfig && !pkg.blockConfig && !process.env.DISABLE_COLLECT) {
3328
// only collect project
3429
try {
3530
collectDetail({
@@ -43,28 +38,34 @@ module.exports = async function (context) {
4338
}
4439
}
4540

46-
// empty output path
47-
fse.emptyDirSync(webpackConfig.output.path);
48-
return new Promise((resolve, reject) => {
49-
webpack(webpackConfig, (error, stats) => {
50-
if (error) {
51-
return reject(error);
52-
}
53-
console.log(
54-
stats.toString({
55-
colors: true,
56-
chunks: false,
57-
children: false,
58-
modules: false,
59-
chunkModules: false,
60-
})
61-
);
62-
if (stats.hasErrors()) {
63-
return reject(new Error('webpack compiled failed.'));
64-
}
65-
log.info('ICE build finished');
66-
applyHook('afterBuild', stats);
67-
resolve();
41+
const skipCompile = commandArgs.skipCompile || process.env.SKIP_COMPILE;
42+
if (skipCompile) {
43+
applyHook('afterBuild', {});
44+
return Promise.resolve();
45+
} else {
46+
// empty output path
47+
fse.emptyDirSync(webpackConfig.output.path);
48+
return new Promise((resolve, reject) => {
49+
webpack(webpackConfig, (error, stats) => {
50+
if (error) {
51+
return reject(error);
52+
}
53+
console.log(
54+
stats.toString({
55+
colors: true,
56+
chunks: false,
57+
children: false,
58+
modules: false,
59+
chunkModules: false,
60+
}),
61+
);
62+
if (stats.hasErrors()) {
63+
return reject(new Error('webpack compiled failed.'));
64+
}
65+
log.info('ICE build finished');
66+
applyHook('afterBuild', stats);
67+
resolve();
68+
});
6869
});
69-
});
70+
}
7071
};

packages/ice-scripts/lib/commands/dev.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ const WebpackDevServer = require('webpack-dev-server');
1414
const openBrowser = require('react-dev-utils/openBrowser');
1515
const iceworksClient = require('../utils/iceworksClient');
1616
const prepareUrLs = require('../utils/prepareURLs');
17-
const goldlog = require('../utils/goldlog');
1817
const pkgData = require('../../package.json');
1918
const log = require('../utils/log');
2019
const checkDepsInstalled = require('../utils/checkDepsInstalled');
2120

2221
module.exports = async function(context, subprocess) {
2322
const { applyHook, commandArgs, rootDir, webpackConfig, pkg } = context;
24-
25-
goldlog('version', {
26-
version: pkgData.version,
27-
});
28-
goldlog('dev', commandArgs);
2923
log.verbose('dev cliOptions', commandArgs);
3024

3125
await applyHook('beforeDev');
@@ -43,7 +37,7 @@ module.exports = async function(context, subprocess) {
4337
return Promise.reject(new Error('项目依赖未安装,请先安装依赖。'));
4438
}
4539

46-
if (!pkg.componentConfig && !pkg.blockConfig) {
40+
if (!pkg.componentConfig && !pkg.blockConfig && !process.env.DISABLE_COLLECT) {
4741
// only collect project
4842
try {
4943
collectDetail({

packages/ice-scripts/lib/utils/goldlog.js

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

packages/ice-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ice-scripts",
3-
"version": "2.1.14",
3+
"version": "2.1.16",
44
"description": "ICE SDK",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)