Skip to content

Commit

Permalink
Merge pull request #80 from ice-lab/ice-scripts/release-2.1.15
Browse files Browse the repository at this point in the history
ice-scripts/release-2.1.16
  • Loading branch information
imsobear authored Dec 30, 2019
2 parents 43dbef8 + ea73323 commit d7a6c58
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 84 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.1.16

- [feat] support process.env.DISABLE_COLLECT to disable pv collect

## 2.1.15

- [feat] cli option --skip-compile for skip webpack compile

## 2.1.14

- [feat] support postcssrc/postcss.config.js #2952
Expand Down
4 changes: 4 additions & 0 deletions packages/ice-plugin-component/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.10

- [feat] generate declaration when compile ts

## 0.1.9

- [feat] support basic component @ali/deep for style generate
Expand Down
34 changes: 33 additions & 1 deletion packages/ice-plugin-component/lib/compile/component/buildSrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* - 生成 style.js 和 index.scss
*/

const { createReadStream, createWriteStream, writeFileSync } = require('fs');
const { createReadStream, createWriteStream, writeFileSync, ensureDirSync } = require('fs-extra');
const babel = require('@babel/core');
const glob = require('glob');
const mkdirp = require('mkdirp');
const path = require('path');
const rimraf = require('rimraf');
const ts = require('typescript');

module.exports = function componentBuild({ babelConfig, rootDir, log }) {
const srcDir = path.join(rootDir, 'src');
Expand Down Expand Up @@ -54,6 +55,7 @@ module.exports = function componentBuild({ babelConfig, rootDir, log }) {
filename: file,
}));
writeFileSync(path.format(destData), code, 'utf-8');
dtsCompile({ filePath: file, sourceFile: source, destPath: libDir });
log.info(`Compile ${file}`);
}

Expand All @@ -69,4 +71,34 @@ module.exports = function componentBuild({ babelConfig, rootDir, log }) {
log.info(`Copy ${file}`);
});
}
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
function dtsCompile({ filePath, sourceFile, destPath }) {
const REG_TS = /\.(tsx?)$/;
const isTS = REG_TS.test(filePath);
if (!isTS) return;
const compilerOptions = {
allowJs: true,
declaration: true,
emitDeclarationOnly: true,
};
const dtsPath = filePath.replace(REG_TS, '.d.ts');
const targetPath = path.join(destPath, dtsPath);
// Create a Program with an in-memory emit
let createdFiles = {};
const host = ts.createCompilerHost(compilerOptions);
host.writeFile = (fileName, contents) => createdFiles[fileName] = contents;
// Prepare and emit the d.ts files
const program = ts.createProgram([sourceFile], compilerOptions, host);
program.emit();
const fileNamesDTS = sourceFile.replace(REG_TS, '.d.ts');
const content = createdFiles[fileNamesDTS];
// write file
if (content) {
ensureDirSync(path.dirname(targetPath));
writeFileSync(targetPath, content, 'utf-8');
log.info(`Generate ${path.basename(targetPath)}`);
}
// release
createdFiles = null;
}
};
1 change: 1 addition & 0 deletions packages/ice-plugin-component/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ module.exports = ({ context, chainWebpack, onHook, log }, opts = {}) => {
if (hasAdaptor) {
// generate adaptor index.scss
const sassContent = resolveSassImport('main.scss', path.resolve(rootDir, 'src'));
fse.ensureDirSync(path.join(rootDir, 'build'));
fse.writeFileSync(path.resolve(rootDir, 'build/index.scss'), sassContent, 'utf-8');
// adaptor build
reRun();
Expand Down
5 changes: 3 additions & 2 deletions packages/ice-plugin-component/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-plugin-component",
"version": "0.1.9",
"version": "0.1.10",
"description": "ice plugin for develop component",
"main": "lib/index.js",
"scripts": {
Expand All @@ -27,6 +27,7 @@
"npmlog": "^4.1.2",
"prismjs": "^1.16.0",
"resolve": "^1.11.0",
"resolve-sass-import": "^0.1.0"
"resolve-sass-import": "^0.1.0",
"typescript": "^3.7.3"
}
}
1 change: 1 addition & 0 deletions packages/ice-scripts/bin/ice-scripts-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ program
.option('--config <config>', 'use custom config')
.option('--analyzer', '开启构建分析')
.option('--analyzer-port', '设置分析端口号')
.option('--skip-compile', 'skip webpack compile, excute hooks for component compile')
.parse(process.argv);

(async () => {
Expand Down
59 changes: 30 additions & 29 deletions packages/ice-scripts/lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const webpack = require('webpack');
const { collectDetail } = require('@alifd/fusion-collector');

const iceScriptsPkgData = require('../../package.json');
const goldlog = require('../utils/goldlog');
const log = require('../utils/log');
const checkDepsInstalled = require('../utils/checkDepsInstalled');

Expand All @@ -16,10 +15,6 @@ const checkDepsInstalled = require('../utils/checkDepsInstalled');
*/
module.exports = async function (context) {
const { applyHook, commandArgs, rootDir, webpackConfig, pkg } = context;
goldlog('version', {
version: iceScriptsPkgData.version,
});
goldlog('build', commandArgs);
log.verbose('build cliOptions', commandArgs);

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

if (!pkg.componentConfig && !pkg.blockConfig) {
if (!pkg.componentConfig && !pkg.blockConfig && !process.env.DISABLE_COLLECT) {
// only collect project
try {
collectDetail({
Expand All @@ -43,28 +38,34 @@ module.exports = async function (context) {
}
}

// empty output path
fse.emptyDirSync(webpackConfig.output.path);
return new Promise((resolve, reject) => {
webpack(webpackConfig, (error, stats) => {
if (error) {
return reject(error);
}
console.log(
stats.toString({
colors: true,
chunks: false,
children: false,
modules: false,
chunkModules: false,
})
);
if (stats.hasErrors()) {
return reject(new Error('webpack compiled failed.'));
}
log.info('ICE build finished');
applyHook('afterBuild', stats);
resolve();
const skipCompile = commandArgs.skipCompile || process.env.SKIP_COMPILE;
if (skipCompile) {
applyHook('afterBuild', {});
return Promise.resolve();
} else {
// empty output path
fse.emptyDirSync(webpackConfig.output.path);
return new Promise((resolve, reject) => {
webpack(webpackConfig, (error, stats) => {
if (error) {
return reject(error);
}
console.log(
stats.toString({
colors: true,
chunks: false,
children: false,
modules: false,
chunkModules: false,
}),
);
if (stats.hasErrors()) {
return reject(new Error('webpack compiled failed.'));
}
log.info('ICE build finished');
applyHook('afterBuild', stats);
resolve();
});
});
});
}
};
8 changes: 1 addition & 7 deletions packages/ice-scripts/lib/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ const WebpackDevServer = require('webpack-dev-server');
const openBrowser = require('react-dev-utils/openBrowser');
const iceworksClient = require('../utils/iceworksClient');
const prepareUrLs = require('../utils/prepareURLs');
const goldlog = require('../utils/goldlog');
const pkgData = require('../../package.json');
const log = require('../utils/log');
const checkDepsInstalled = require('../utils/checkDepsInstalled');

module.exports = async function(context, subprocess) {
const { applyHook, commandArgs, rootDir, webpackConfig, pkg } = context;

goldlog('version', {
version: pkgData.version,
});
goldlog('dev', commandArgs);
log.verbose('dev cliOptions', commandArgs);

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

if (!pkg.componentConfig && !pkg.blockConfig) {
if (!pkg.componentConfig && !pkg.blockConfig && !process.env.DISABLE_COLLECT) {
// only collect project
try {
collectDetail({
Expand Down
44 changes: 0 additions & 44 deletions packages/ice-scripts/lib/utils/goldlog.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/ice-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-scripts",
"version": "2.1.14",
"version": "2.1.16",
"description": "ICE SDK",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit d7a6c58

Please sign in to comment.