Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iceworks/bugfix adapter #1331

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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