Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const [err, down] = await to(downloadImage(url));
handleError('DOWNLOADING', 'the demo image failed', err);
// Spinner Step.
spinner.succeed(`${green(`DOWNLOADED`)} the image in directory: ${dim(UPLOAD_DIR)}`);
spinner.succeed(`ALL DONE! \n`);
} else {
if (!url) {
const spinner = ora({ text: '' });
spinner.warn(`${yellow(` URL`)} cannot be empty. \n${dim(`You forgot the first parameter.`)}\n`);
process.exit(0);
}
const [err, down] = await to(downloadImage(url));
handleError('DOWNLOADING', 'the demo image failed', err);
}
})();
};
if (block.type === 'custom') {
[err, allFiles] = await to(
extractCustomBlock(
block,
path.join(componentsDir, blockName),
progressFunc
)
);
if (err) {
throw new Error(`解压自定义区块${blockName}出错,请重试`);
}
return allFiles;
}
// 通过 npm 源获取区块
[err, tarballURL] = await to(
materialUtils.getTarballURLBySource(block.source, projectVersion)
);
if (err) {
err.message = `请求区块 ${tarballURL} 包失败`;
throw new Error(err);
}
[err, allFiles] = await to(
retryExtractBlock(
path.join(componentsDir, blockName),
tarballURL,
clientPath,
progressFunc
)
);
blocks.map(async (block) => {
return await downloadBlockToPage(
{ clientPath, clientSrcPath, pageName, block },
progressFunc
);
})
)
);
if (err) {
throw err;
}
const pkg = getPackageByPath(clientPath);
const projectVersion = getProjectVersion(pkg);
[err, depList] = await to(
Promise.all(
filesList.map(async (_, idx) => {
const block = blocks[idx];
// 根据项目版本下载依赖
// 兼容旧版物料源
if (block.npm && block.version && block.type !== 'custom') {
return getDependenciesFromNpm({
npm: block.npm,
version: block.version,
});
} if (
block.source
&& block.source.type === 'npm'
&& block.type !== 'custom'
) {
let version = block.source.version;
throw new Error(`解压自定义区块${blockName}出错,请重试`);
}
return allFiles;
}
// 通过 npm 源获取区块
[err, tarballURL] = await to(
materialUtils.getTarballURLBySource(block.source, projectVersion)
);
if (err) {
err.message = `请求区块 ${tarballURL} 包失败`;
throw new Error(err);
}
[err, allFiles] = await to(
retryExtractBlock(
path.join(componentsDir, blockName),
tarballURL,
clientPath,
progressFunc
)
);
if (err) {
if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
throw new Error(`解压区块${blockName}超时,请重试`);
}
throw new Error(`解压区块${blockName}出错, 请重试`);
}
return allFiles;
action: 'download-block',
data: {
name: block.name,
},
});
// 根据项目版本下载
const pkg = getPackageByPath(clientPath);
const projectVersion = getProjectVersion(pkg);
const blockName = block.alias || upperCamelCase(block.name) || block.className;
let err, tarballURL, allFiles;
// 通过 iceland 自定义的区块
if (block.type === 'custom') {
[err, allFiles] = await to(
extractCustomBlock(
block,
path.join(componentsDir, blockName),
progressFunc
)
);
if (err) {
throw new Error(`解压自定义区块${blockName}出错,请重试`);
}
return allFiles;
}
// 通过 npm 源获取区块
[err, tarballURL] = await to(
materialUtils.getTarballURLBySource(block.source, projectVersion)
);
return new Promise(async (resolve, reject) => {
let version = source.version;
// 注意!!! 由于接口设计问题,version-0.x 字段实质指向1.x版本!
if (projectVersion === '1.x') {
// 兼容没有'version-0.x'字段的情况
version = source['version-0.x'] || source.version;
}
const registry = typeof source.npm === 'string' && source.npm.startsWith('@icedesign')
? 'https://registry.npm.taobao.org'
: env.npm_config_registry || source.registry;
const [err, pkgData] = await to(
npmRequest({
name: source.npm,
version,
registry,
})
);
if (err) {
reject(err);
} else {
resolve(pkgData.dist.tarball);
}
});
};
module.exports = async function createProject(
{ destDir, scaffold, projectName, interpreter, progressFunc },
afterCreateRequest
) {
let err, tarballURL, extractedFiles;
[err, tarballURL] = await to(utils.getTarballURLBySource(scaffold.source));
if (err) {
err.message = `请求模板 ${tarballURL} 包失败`;
throw err;
}
[err, extractedFiles] = await to(
utils.extractTarball(
tarballURL,
destDir,
scaffold.source,
progressFunc,
afterCreateRequest
)
);
if (err) {
throw err;
}
// 写 package.json 文件
const pkgJSONPath = path.join(destDir, 'package.json');
let pkgJSON = fs.readFileSync(pkgJSONPath);
module.exports = async function createProject(
{ destDir, scaffold, projectName, interpreter, progressFunc },
afterCreateRequest
) {
let err, tarballURL, extractedFiles;
[err, tarballURL] = await to(utils.getTarballURLBySource(scaffold.source));
if (err) {
err.message = `请求模板 ${tarballURL} 包失败`;
throw err;
}
[err, extractedFiles] = await to(
utils.extractTarball(
tarballURL,
destDir,
scaffold.source,
progressFunc,
afterCreateRequest
)
);
if (err) {
throw err;
}