Skip to content

Commit

Permalink
Iceworks/bugfix adapter (#1331)
Browse files Browse the repository at this point in the history
* fix: 依赖获取判断逻辑添加

* chore: version-0.x字段 指向新版本  1.x
  • Loading branch information
fenglai0802 authored and chenbin92 committed Jan 15, 2019
1 parent 9c7ce16 commit 6e6aeae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 14 additions & 4 deletions tools/iceworks/app/main/scaffolder/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const request = require('request');
const tar = require('tar');
const upperCamelCase = require('uppercamelcase');
const zlib = require('zlib');
const pathExists = require('path-exists');

const config = require('../../config');

Expand All @@ -29,16 +30,25 @@ function downloadBlocksToPage({ destDir = process.cwd(), blocks, pageName, isNod
return Promise.all(
filesList.map((_, idx) => {
const block = blocks[idx];
// 根据项目版本下载依赖
const pkg = getPackageByPath(destDir);
const projectVersion = getProjectVersion(pkg);
// 兼容旧版物料源
if (block.npm && block.version && ( block.type != 'custom' ) ) {
return getDependenciesFromNpm({
npm: block.npm,
version: block.version,
});
} else if (block.source && block.source.type == 'npm' && ( block.type != 'custom' ) ) {
let version = block.source.version;
// 注意!!! 由于接口设计问题,version-0.x 字段实质指向1.x版本!
if (projectVersion === '1.x') {
// 兼容没有'version-0.x'字段的情况
version = block.source['version-0.x'] || block.source.version;
}
return getDependenciesFromNpm({
version,
npm: block.source.npm,
version: block.source.version,
registry: block.source.registry,
});
} else if (block.type == 'custom') {
Expand Down Expand Up @@ -110,8 +120,8 @@ function downloadBlockToPage({ destDir = process.cwd(), block, pageName, isNodeP
});
}

function getPackageByPath(path) {
const pkgPath = path.join(path, 'package.json');
function getPackageByPath(destDir) {
const pkgPath = path.join(destDir, 'package.json');
if (pathExists.sync(pkgPath)) {
try {
const packageText = fs.readFileSync(pkgPath);
Expand All @@ -123,7 +133,7 @@ function getPackageByPath(path) {
/**
* 1. 有 @icedesign/base 相关依赖 则返回 0.x
* 2. 只有 @alifd/next 相关依赖 则返回 1.x
* 3. 都没有 则返回 0.x
* 3. 都没有 则返回 1.x
* @param {*} pkg
*/
function getProjectVersion(pkg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* {
"type": "npm",
"npm": "@icedesign/foo-block",
"version": "1.0.0",
"version-0.x": "0.1.5"
"version": "0.1.5",
"version-0.x": "1.0.0",
"sourceCodeDirectory": "src",
},
* "projectVersion": "1.x" // "0.x"
Expand All @@ -19,8 +19,8 @@ const npmRequest = require('../../utils/npmRequest');
module.exports = function getTarballURLBySource(source = {}, projectVersion) {
return new Promise((resolve, reject) => {
let version = source.version;

if (projectVersion === '0.x') {
// 注意!!! 由于接口设计问题,version-0.x 字段实质指向1.x版本!
if (projectVersion === '1.x') {
// 兼容没有'version-0.x'字段的情况
version = source['version-0.x'] || source.version;
}
Expand Down

0 comments on commit 6e6aeae

Please sign in to comment.