Skip to content

Commit

Permalink
release: ice-scripts/release-2.1.13 (#72)
Browse files Browse the repository at this point in the history
* chore: changelog

* feat: support stylus (#71)

* feat: add ice-plugin-fusion-material (#69)

* feat: add ice-plugin-fusion-material

* feat: ice-plugin-fusion-materia ver_0.0.2

* feat: making ice-plugin-fusion-material plugin more easier to use

* feat: make fusion-material plugin more easier to use

* feat: fix lint problem

* feat: add function to delete iframe tag in html

* docs: update readme

* docs: update package.json

* chore: lock lerna version

* chore: eslint rules

* feat: support antd-mobile (#74)

* feat: support stylus (#73)

* feat(stylus): 添加stylus支持

* feat(stylus config): 全局配置选项和插件支持stylus

* chore: changelog
  • Loading branch information
imsobear authored Dec 3, 2019
2 parents 3707453 + 301ebd1 commit eac808c
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = deepmerge(eslint, {
},
"rules": {
"global-require": 1,
"comma-dangle": 1
}
});
11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,5 @@ coverage/
databases
build
.vscode/
tools/ice-scripts/lib/ICE_CA
.tmp/

npmrc
tools/extract-css-assets-webpack-plugin/test/actual/
tools/extract-css-assets-webpack-plugin/lib/

# iceworks
!tools/iceworks/**/yarn.lock
!tools/iceworks/build
tools/iceworks/out
tools/iceworks/dist
tools/iceworks/renderer/src/datacenter/data
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.1.13

- [feat] support stylus alibaba/ice#2910
- [feat] ice-plugin-fusion-material: generate screenshot and html used in fusion cool
- [feat] ice-plugin-antd supportn option libraryName

## 2.1.12

- [feat] support file watcher for compile library alibaba/ice#2844
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eslint": "^6.0.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"husky": "^1.3.1",
"lerna": "^3.15.0"
"lerna": "~3.17.0"
},
"dependencies": {
"@babel/plugin-proposal-function-bind": "^7.2.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/ice-plugin-antd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.5

- [feat] support libraryName

## 0.1.3

- [fix] 兼容 options 为空
Expand Down
8 changes: 4 additions & 4 deletions packages/ice-plugin-antd/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = async ({ chainWebpack, log }, pluginOptions) => {
const { themeConfig } = pluginOptions || {};
const { themeConfig, libraryName = 'antd' } = pluginOptions || {};
chainWebpack((config) => {
// 1. 支持主题能力
if (themeConfig) {
log.info('自定义 Antd 组件主题变量:', themeConfig);
log.info(`自定义 ${libraryName} 组件主题变量:`, themeConfig);
}
['less', 'less-module'].forEach((rule) => {
config.module
Expand All @@ -29,11 +29,11 @@ module.exports = async ({ chainWebpack, log }, pluginOptions) => {
[
require.resolve('babel-plugin-import'),
{
libraryName: 'antd',
libraryName,
libraryDirectory: 'es',
style: true,
},
'antd',
libraryName,
]
);
return options;
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-plugin-antd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-plugin-antd",
"version": "0.1.4",
"version": "0.1.5",
"description": "ice-scripts plugin for antd",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-plugin-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = ({ context, chainWebpack }) => {

// update publicPath ./
config.output.publicPath('./');
['scss', 'scss-module', 'css', 'css-module', 'less', 'less-module'].forEach((rule) => {
['scss', 'scss-module', 'css', 'css-module', 'less', 'less-module', 'styl', 'styl-module'].forEach((rule) => {
if (config.module.rules.get(rule)) {
config.module.rule(rule).use('MiniCssExtractPlugin.loader').tap(() => ({ publicPath: '../' }));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-plugin-block/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-plugin-block",
"version": "0.1.2",
"version": "0.1.3",
"description": "ice-scripts plugin for block development",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-plugin-component/lib/configs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (config, { demos, markdownParser, rootDir }) => {
}),
};
config.output.publicPath('./');
['scss', 'scss-module', 'css', 'css-module', 'less', 'less-module'].forEach((rule) => {
['scss', 'scss-module', 'css', 'css-module', 'less', 'less-module', 'styl', 'styl-module'].forEach((rule) => {
if (config.module.rules.get(rule)) {
config.module.rule(rule).use('MiniCssExtractPlugin.loader').tap(() => ({ publicPath: '../' }));
}
Expand Down
2 changes: 1 addition & 1 deletion 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.7",
"version": "0.1.8",
"description": "ice plugin for develop component",
"main": "lib/index.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions packages/ice-plugin-fusion-material/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ice-plugin-fusion-material

## 功能

本插件能够使用户运行`npm run build`时,自动生成区块或模板的截图与html文件,并保存于`build/views`文件夹下,同时在`package.json`中更新截图与html文件的路径地址。

## 使用方式

`ice.config.js`中引入`ice-plugin-fusion-material`即可使用。
45 changes: 45 additions & 0 deletions packages/ice-plugin-fusion-material/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require('path');
const fs = require('fs');
const screenShot = require('./utils/screenShot');

// Update package.json
const updatePackageJson = (packageJsonPath, type, htmls, screenshots) => {
const jsonData = fs.readFileSync(packageJsonPath, 'utf8');
const jsonObj = JSON.parse(jsonData);
for (let i = 0; i < htmls.length; i++) {
jsonObj[type].views[i].html = htmls[i];
jsonObj[type].views[i].screenshot = screenshots[i];
}
fs.writeFileSync(packageJsonPath, JSON.stringify(jsonObj, null, ' '));
};

module.exports = ({
context,
onHook,
}) => {
// after the build script finished
onHook('afterBuild', () => {
// get package.json and rootDir
const { pkg, rootDir } = context;
const packageJsonPath = path.join(rootDir, 'package.json');
const outputRootPath = path.join(rootDir, 'build', 'views');
fs.mkdirSync(outputRootPath);
// get htmls and screenshots if blockConfig.views or scaffoldConfig.views exist
const htmls = [];
const screenshots = [];
if (pkg.blockConfig && pkg.blockConfig.views) {
// block type
screenShot(rootDir, '/build/index.html', './build/views/block_view1.png', './build/views/block_view1.html', 2000);
updatePackageJson(packageJsonPath, 'blockConfig', ['build/views/block_view1.html'], ['build/views/block_view1.png']);
}
else if (pkg.scaffoldConfig && pkg.scaffoldConfig.views) {
// scaffold type
for (let i = 0; i < pkg.scaffoldConfig.views.length; i++) {
screenShot(rootDir, '/build/index.html', `./build/views/page${i}.png`, `./build/views/page${i}.html`, 2000, pkg.scaffoldConfig.views[i].path);
htmls.push(`build/views/page${i}.html`);
screenshots.push(`build/views/page${i}.png`);
}
updatePackageJson(packageJsonPath, 'scaffoldConfig', htmls, screenshots);
}
});
};
20 changes: 20 additions & 0 deletions packages/ice-plugin-fusion-material/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "ice-plugin-fusion-material",
"version": "0.1.1",
"description": "ice plugin fusion material",
"main": "index.js",
"scripts": {
"lint": "eslint --cache --ext .js,.jsx ./",
"test": "echo \"test\""
},
"author": "",
"license": "ISC",
"devDependencies": {
"puppeteer": "^2.0.0"
},
"dependencies": {
"chalk": "^2.4.2",
"detect-port": "^1.3.0",
"ora": "^4.0.2"
}
}
52 changes: 52 additions & 0 deletions packages/ice-plugin-fusion-material/utils/createServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

const http = require('http');
const fs = require('fs');
const url = require('url');
const path = require('path');
const chalk = require('chalk');

module.exports = function (cwd, port) {
const server = http
.createServer((req, res) => {
const pathname = cwd + url.parse(req.url).pathname;

fs.exists(pathname, (exists) => {
if (exists) {
switch (path.extname(pathname)) { // set HTTP HEAD
case '.html':
res.writeHead(200, { 'Content-Type': 'text/html' });
break;
case '.js':
res.writeHead(200, { 'Content-Type': 'text/javascript' });
break;
case '.css':
res.writeHead(200, { 'Content-Type': 'text/css' });
break;
case '.gif':
res.writeHead(200, { 'Content-Type': 'image/gif' });
break;
case '.jpg':
res.writeHead(200, { 'Content-Type': 'image/jpeg' });
break;
case '.png':
res.writeHead(200, { 'Content-Type': 'image/png' });
break;
default:
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
});
}
fs.readFile(pathname, (_err, data) => {
res.end(data);
});
} else {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('<h1>404 Not Found</h1>');
console.log(chalk.yellow(`${pathname} Not Found.`));
}
});
})
.listen(port, '127.0.0.1');

return server;
};
58 changes: 58 additions & 0 deletions packages/ice-plugin-fusion-material/utils/getPuppeteer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const spawn = require('cross-spawn');
const chalk = require('chalk');

function isNotFoundError(error = '') {
return error.indexOf('Cannot find module') === 0;
}

/**
* get Puppeteer(headless chromium)
*
* we don't want depend on puppeteer locally,
* puppeteer takes a long to install
*
*/
module.exports = async function getPuppeteer() {
try {
// get Puppeteer from local node_modules
// eslint-disable-next-line global-require
return require('puppeteer');
} catch (error) {
if (isNotFoundError(error.message)) {
try {
// get Puppeteer from global node_modules
// eslint-disable-next-line global-require
return require('import-global')('puppeteer');
} catch (importGlobalErr) {
// if not found puppeteer from global node_modules
// install it to global node_modules
if (isNotFoundError(importGlobalErr.message)) {
console.log(chalk.yellow('\n\nCannot find puppeteer in current environment.'));
console.log(chalk.yellow('Installing globally puppeteer, please wait a moment.\n'));

// set puppeteer download host
// default download host has been blocking, use cnpm mirror
// https://github.com/cnpm/cnpmjs.org/issues/1246#issuecomment-341631992
spawn.sync('npm', ['config', 'set', 'puppeteer_download_host=https://storage.googleapis.com.cnpmjs.org']);
const result = spawn.sync('npm', ['install', '[email protected]', '-g', '--registry', 'https://registry.npm.taobao.org'], { stdio: 'inherit' });
spawn.sync('npm', ['config', 'delete', 'puppeteer_download_host']);

// get spawn error, exit with code 1
if (result.error) {
console.log(chalk.red('\n\nInstall Error. \nPlease install puppeteer using the following commands:'));
console.log(chalk.white('\n npm uninstall puppeteer -g'));
console.log(chalk.white('\n PUPPETEER_DOWNLOAD_HOST=https://storage.googleapis.com.cnpmjs.org npm i puppeteer -g --registry=https://registry.npm.taobao.org'));
console.log(chalk.white('\n screenshot -u http://www.example.com\n'));
process.exit(1);
}

console.log(chalk.green('\nPuppeteer installed.\n'));
// eslint-disable-next-line global-require
return require('import-global')('puppeteer');
}
throw Error(importGlobalErr);
}
}
throw Error(error);
}
};
Loading

0 comments on commit eac808c

Please sign in to comment.