mirror of
https://github.com/steedos/steedos-platform
synced 2024-11-22 17:06:42 +00:00
调整steedos source:retrieve -p 命令规则:只下载-p 路径下已有的文件。对象文件夹下的子文件夹还是获取所有
https://github.com/steedos/steedos-apps/issues/33
This commit is contained in:
parent
98ffe005bd
commit
3500cca93c
@ -4,10 +4,11 @@ const chalk= require('chalk');
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
const yaml = require("js-yaml");
|
||||
const _ = require('underscore');
|
||||
|
||||
import { getFromServer } from '../../source/retrieve/index'
|
||||
|
||||
import { resolveProjectPathSync, getPackagePath, decompressAndDeploy, getRetrievePackageInfo, getAllowSyncMetadataKeys } from '@steedos/metadata-core'
|
||||
import { resolveProjectPathSync, getPackagePath, decompressAndDeploy, getRetrievePackageInfo, getAllowSyncMetadataKeys, getPackageYml, hasParent, getParentMetadataName, SteedosMetadataTypeInfoKeys as TypeInfoKeys } from '@steedos/metadata-core'
|
||||
|
||||
|
||||
class RetrieveCommand extends retOclif.Command {
|
||||
@ -22,14 +23,51 @@ class RetrieveCommand extends retOclif.Command {
|
||||
const projectPath = resolveProjectPathSync(serverDir);
|
||||
const packagePath = getPackagePath(serverDir);
|
||||
const appPath = path.join(projectPath, packagePath);
|
||||
|
||||
var options = { packageYmlDir: ymlDir, metadata, serverDir}
|
||||
|
||||
requestYmlBase64 = getRetrievePackageInfo(options);
|
||||
|
||||
// var file = Buffer.from(requestYmlBase64, 'base64');
|
||||
// fs.writeFileSync("c:/cli/testReq.yml", file);
|
||||
|
||||
//retrieve -p
|
||||
|
||||
let is_directory = false;
|
||||
if(flags.serverDir){
|
||||
const stat = fs.lstatSync(flags.serverDir);
|
||||
is_directory = stat.isDirectory();
|
||||
}
|
||||
if(!ymlDir && flags.serverDir && is_directory){
|
||||
//getPackageYml 返回了所有源数据明细
|
||||
var packageJson = getPackageYml(appPath, serverDir, {includeJs: false});
|
||||
//如果是源数据的parent是object,则取*
|
||||
for(const metadataName in packageJson){
|
||||
if(hasParent(metadataName)){
|
||||
var parentMetadataName = getParentMetadataName(metadataName);
|
||||
if(parentMetadataName === TypeInfoKeys.Object){
|
||||
const info: any = [];
|
||||
_.map(packageJson[metadataName], (item)=>{
|
||||
const foo = item.split('.');
|
||||
if(foo.length > 0){
|
||||
info.push(`${foo[0]}.*`)
|
||||
}
|
||||
})
|
||||
packageJson[metadataName] = _.uniq(info)
|
||||
}
|
||||
}
|
||||
// else if(metadataName === TypeInfoKeys.Object){
|
||||
// const info: any = [];
|
||||
// _.map(packageJson[metadataName], (objectApiName)=>{
|
||||
// info.push(`${objectApiName}.*`)
|
||||
// })
|
||||
// packageJson[metadataName] = _.uniq(info)
|
||||
// }
|
||||
}
|
||||
|
||||
var packageYml = yaml.dump(packageJson);
|
||||
var ymlBuffer = Buffer.from(packageYml);
|
||||
requestYmlBase64 = ymlBuffer.toString('base64');
|
||||
// fs.writeFileSync("F:/package.yml", packageYml);
|
||||
}else{
|
||||
var options = { packageYmlDir: ymlDir, metadata, serverDir}
|
||||
requestYmlBase64 = getRetrievePackageInfo(options);
|
||||
// fs.writeFileSync("F:/package.yml", Buffer.from(requestYmlBase64, 'base64'));
|
||||
}
|
||||
|
||||
getFromServer(requestYmlBase64, async function(zipBuffer){
|
||||
// 解压以后根据配置文件部署到相应位置
|
||||
await decompressAndDeploy(zipBuffer, appPath);
|
||||
|
@ -46,6 +46,18 @@ export function compressFiles(appDir, sourceDir, zipPath, option, callBack){
|
||||
archive.finalize();
|
||||
}
|
||||
|
||||
|
||||
export function getPackageYml(appDir, sourceDir, option){
|
||||
|
||||
var includeJs = option.includeJs;
|
||||
var inDeploy = option.inDeploy;
|
||||
|
||||
var des = new ZipDescription(null, appDir, includeJs, inDeploy);
|
||||
scanOrAdd(des, sourceDir);
|
||||
var description = des.export();
|
||||
return description;
|
||||
}
|
||||
|
||||
function scanTargetDir(archive, rootpath, targetPath, option){
|
||||
|
||||
var includeJs = option.includeJs;
|
||||
@ -194,7 +206,9 @@ class ZipDescription{
|
||||
}
|
||||
}
|
||||
// append files
|
||||
archive.file(filePath, {name: zipFileName});
|
||||
if(archive){
|
||||
archive.file(filePath, {name: zipFileName});
|
||||
}
|
||||
|
||||
// filePath: C:\steedos-app\main\default\objects\test_object\test_object.object.yml
|
||||
// fileName: main\default\objects\test_object\test_object.object.yml
|
||||
@ -227,7 +241,6 @@ class ZipDescription{
|
||||
throw new Error('The attribute "name" in the file does not match its filename.\nName:"'+fileContent['name']+'" Path:' + filePath)
|
||||
}
|
||||
}else{
|
||||
|
||||
if(itemName != fullName){
|
||||
throw new Error('The attribute "name" in the file does not match its filename.\nName:"'+fileContent['name']+'" Path:' + filePath)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export * from './metadata'
|
||||
export * from './loadFile'
|
||||
export { jsonToFile } from './jsonToFile'
|
||||
export { mkTempFolder, createIfNotExist, mkdirsSync, deleteFolderRecursive, getRetrievePackageInfo } from './folderUtil'
|
||||
export { compressFiles, decompressAndDeploy } from './compressUtil'
|
||||
export { compressFiles, decompressAndDeploy, getPackageYml } from './compressUtil'
|
||||
export * from './packages'
|
||||
|
||||
export * from './auth/index'
|
||||
@ -86,7 +86,7 @@ export function getFileinfoByFilename(filename) {
|
||||
|
||||
}else if(filename.endsWith('.field.yml')){
|
||||
metadataName = TypeInfoKeys.Field;
|
||||
itemName = _.first(filename.split('.'));
|
||||
itemName = filename.replace('.field.yml', "");
|
||||
|
||||
}else if(filename.endsWith('.button.yml')){
|
||||
metadataName = TypeInfoKeys.Action;
|
||||
|
Loading…
Reference in New Issue
Block a user