Skip to content

Commit

Permalink
fix: delete noejideba
Browse files Browse the repository at this point in the history
  • Loading branch information
wssgcg1213 committed Apr 13, 2018
1 parent 1814e39 commit a8f8a8c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 45 deletions.
93 changes: 51 additions & 42 deletions tools/ice-devtools/database/generate-marterials-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ const os = require('os');
const uppercamelcase = require('uppercamelcase');
const rp = require('request-promise');
const depAnalyze = require('../shared/dep-analyze');
const { cut } = require('../shared/participle');

function generatePartciple(payload, source) {
if (process.env.PARTICIPLE) {
const { cut } = require('../shared/participle');
// 分词 payload
const participle = {
title: cut(source.title),
content: cut(source.content),
};
if (payload && payload.features) {
payload.features.participle = participle;
}
}
}

/**
* 生成 blocks 信息列表
* @param {*} files
* @param {*} SPACE
* @param {String} type | block or react
*/
function generateBlocks(files, SPACE) {
function generateBlocks(files, SPACE, type) {
const result = [];
files.forEach((pkgPath) => {
const pkg = JSON.parse(fs.readFileSync(path.join(SPACE, pkgPath)));
Expand All @@ -43,61 +57,59 @@ function generateBlocks(files, SPACE) {
};
});

// hack 临时兼容下 layout 的场景
if (!pkg.blockConfig) {
pkg.blockConfig = pkg.layoutConfig;
}

// 分词 payload
const participle = {
title: cut(pkg.blockConfig.title),
content: cut(pkg.description),
};
// blockConfig or layoutConfig
const configKey = `${type}Config`;
const pkgConfig = pkg[configKey] || {};

const payload = {
// (必)英文名
name: pkg.blockConfig.name,
name: pkgConfig.name,
// (必)中文描述
title: pkg.blockConfig.title,
title: pkgConfig.title,
source: {
type: 'npm',
npm: pkg.name,
version: pkg.version,
// layout or block need src/
sourceCodeDirectory: 'src/',
},
// (必) 用于说明组件依赖关系
dependencies: pkg.dependencies || {},
// (必) 截图
snapshot: pkg.blockConfig.snapshot,
snapshot: pkgConfig.snapshot,

categories: pkg.blockConfig.categories || [],
categories: pkgConfig.categories || [],
publishTime: pkg.publishTime || new Date().toISOString(),
features: {
participle,
useComponents,
},
};

generatePartciple(payload, {
title: pkgConfig.title,
content: pkg.description,
});

// (可)区块详细说明, markdown 格式
if (pkg.description) {
payload.description = pkg.description;
}

// (可) 标签
if (pkg.blockConfig.categories) {
payload.categories = pkg.blockConfig.categories;
if (pkgConfig.categories) {
payload.categories = pkgConfig.categories;
}

if (pkg.blockConfig.thumbnail) {
payload.thumbnail = pkg.blockConfig.thumbnail;
if (pkgConfig.thumbnail) {
payload.thumbnail = pkgConfig.thumbnail;
}

if (pkg.blockConfig.sketchURL) {
payload.sketchURL = pkg.blockConfig.sketchURL;
if (pkgConfig.sketchURL) {
payload.sketchURL = pkgConfig.sketchURL;
}

if (pkg.blockConfig.icelandURL) {
payload.sketchURL = pkg.blockConfig.icelandURL;
if (pkgConfig.icelandURL) {
payload.sketchURL = pkgConfig.icelandURL;
}

// if registry is user defined
Expand Down Expand Up @@ -133,12 +145,6 @@ function generateScaffolds(files, SPACE) {
Object.assign(generatorJson, require(generatorJsonPath));
}

// 分词 payload
const participle = {
title: cut(pkg.scaffoldConfig.title),
content: cut(pkg.description),
};

const payload = {
// (必)英文名
name: pkg.scaffoldConfig.name,
Expand All @@ -157,11 +163,14 @@ function generateScaffolds(files, SPACE) {

categories: pkg.scaffoldConfig.categories || [],
publishTime: pkg.publishTime || new Date().toISOString(),
features: {
participle,
},
features: {},
};

generatePartciple(payload, {
title: pkg.scaffoldConfig.title,
content: pkg.description,
});

// (可)预览地址
if (pkg.homepage) {
payload.homepage = pkg.homepage;
Expand All @@ -179,19 +188,19 @@ function generateScaffolds(files, SPACE) {

// (可) 标签
if (pkg.scaffoldConfig.categories) {
payload.categories = pkg.blockConfig.categories;
payload.categories = pkg.scaffoldConfig.categories;
}

if (pkg.scaffoldConfig.thumbnail) {
payload.thumbnail = pkg.blockConfig.thumbnail;
payload.thumbnail = pkg.scaffoldConfig.thumbnail;
}

if (pkg.scaffoldConfig.sketchURL) {
payload.sketchURL = pkg.blockConfig.sketchURL;
payload.sketchURL = pkg.scaffoldConfig.sketchURL;
}

if (pkg.scaffoldConfig.icelandURL) {
payload.sketchURL = pkg.blockConfig.icelandURL;
payload.sketchURL = pkg.scaffoldConfig.icelandURL;
}

// if registry is user defined
Expand All @@ -208,7 +217,7 @@ function generateScaffolds(files, SPACE) {
* @param {*} pattern
* @param {*} SPACE
*/
function gatherBlocksOrLayouts(pattern, SPACE) {
function gatherBlocksOrLayouts(pattern, SPACE, type) {
return new Promise((resolve, reject) => {
glob(
pattern,
Expand All @@ -221,7 +230,7 @@ function gatherBlocksOrLayouts(pattern, SPACE) {
console.log('err:', err);
reject(err);
} else {
resolve(generateBlocks(files, SPACE));
resolve(generateBlocks(files, SPACE, type));
}
}
);
Expand Down Expand Up @@ -287,8 +296,8 @@ module.exports = function main(materialName, materialPath, options) {
Promise.resolve(materialPath)
.then((space) => {
return Promise.all([
gatherBlocksOrLayouts('blocks/*/package.json', space),
gatherBlocksOrLayouts('layouts/*/package.json', space),
gatherBlocksOrLayouts('blocks/*/package.json', space, 'block'),
gatherBlocksOrLayouts('layouts/*/package.json', space, 'layout'),
gatherScaffolds('scaffolds/*/package.json', space),
]);
})
Expand Down
2 changes: 1 addition & 1 deletion tools/ice-devtools/database/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function generateDatabase({ name, path, options }) {
generateMaterialsDatabases(name, path, options).then(() => {
// done
console.log(
'All materials db generated, then you can put the db.json in a http server and put the url in Iceworks settings panel. You will see your materials in Iceworks.'
'All materials JSON generated, you can upload the JSON file to a static web server and put the URL at Iceworks settings panel. You will see your materials in Iceworks.'
);
});
}
1 change: 0 additions & 1 deletion tools/ice-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"moment": "^2.22.0",
"multimatch": "^2.1.0",
"node-sass": "^4.8.3",
"nodejieba": "^2.2.5",
"ora": "^2.0.0",
"read-metadata": "^1.0.0",
"request": "^2.85.0",
Expand Down
12 changes: 11 additions & 1 deletion tools/ice-devtools/shared/participle/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
const jieba = require('nodejieba');
let jieba;

try {
jieba = require('nodejieba');
} catch (err) {
console.log(
`[ERR] nodejieba is not installed, please mamually install it by executing npm i nodejieba --save-dev`
);
process.exit(1);
}

// load dict at first time
jieba.load({
userDict: require.resolve('./userDict.utf8'),
Expand Down

0 comments on commit a8f8a8c

Please sign in to comment.