New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@easyv/cli

Package Overview
Dependencies
Maintainers
11
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@easyv/cli - npm Package Compare versions

Comparing version 1.14.3 to 1.14.4

2

package.json
{
"name": "@easyv/cli",
"version": "1.14.3",
"version": "1.14.4",
"description": "Easy[V] component tools",

@@ -5,0 +5,0 @@ "engines": {

const fs = require('fs');
const path = require("path");
const { appPackage,appComponents } = require('./paths');
const path = require('path');
const { appPackage, appComponents, getPluginRoot } = require('./paths');
const { request } = require('./utils/request');

@@ -8,150 +8,159 @@ const crypto = require('crypto');

const chalk = require('chalk');
const {
getGlobalConfig,
checkEasyvProject,
getToken,
getComponentBase
} = require('./utils');
const { getGlobalConfig, checkEasyvProject, getToken } = require('./utils');
const load = (path,host,defaultParams,assetsPath)=>{
const files = fs.readdirSync(path);
const load = (filePath, host, defaultParams, assetsPath) => {
const files = fs.readdirSync(filePath);
files.map(async d => {
const filePath = path + '\\' + d;
const stat = fs.lstatSync(filePath);
files.map(async (d) => {
const assetPath = path.resolve(filePath, d);
const stat = fs.lstatSync(assetPath);
if(stat.isDirectory() === true){
load(filePath,host,defaultParams,assetsPath);
} else {
try {
let readStream = fs.createReadStream(filePath); //createReadStream比较适合大文件,readfile容易导致内存爆仓
const requestParams = {
...defaultParams,
formData:{
...defaultParams.formData,
assetsPath: filePath.slice(assetsPath.length).replace(/\\/g,'/'),
file: {
value: readStream,
options: {
filename: d,
},
}
}
}
if (stat.isDirectory() === true) {
load(assetPath, host, defaultParams, assetsPath);
} else {
try {
let readStream = fs.createReadStream(assetPath); //createReadStream比较适合大文件,readfile容易导致内存爆仓
const requestParams = {
...defaultParams,
formData: {
...defaultParams.formData,
assetsPath: assetPath.slice(assetsPath.length).replace(/\\/g, '/'),
file: {
value: readStream,
options: {
filename: d,
},
},
},
};
const result = await request(host + '/api/easyv/v5/constants/upload/assets',requestParams);
if(result.success){
//请求platform-config接口
const platformConfigs = await request(host + '/api/easyv/v5/platform-configs',{
method: 'GET',
json: true,
agent: host.startsWith('https')
? new https.Agent({
rejectUnauthorized: false,
})
: null,
});
let assetsUrl = '{ Your online server address }/'
if(platformConfigs.success)
assetsUrl = platformConfigs.data.assetsUrl;
//上传位置提示
console.log(chalk.green(`Uploaded successfully to ${assetsUrl}` +
`components/${requestParams.formData.constantName}/assets${requestParams.formData.assetsPath}`));
const result = await request(
host + '/api/easyv/v5/constants/upload/assets',
requestParams,
);
if (result.success) {
//请求platform-config接口
const platformConfigs = await request(
host + '/api/easyv/v5/platform-configs',
{
method: 'GET',
json: true,
agent: host.startsWith('https')
? new https.Agent({
rejectUnauthorized: false,
})
: null,
},
);
let assetsUrl = '{ Your online server address }/';
if (platformConfigs.success)
assetsUrl = platformConfigs.data.assetsUrl;
//上传位置提示
console.log(
chalk.green(
`Uploaded successfully to ${assetsUrl}` +
`components/${requestParams.formData.constantName}/assets${requestParams.formData.assetsPath}`,
),
);
return ;
}
//独立部署提示
if(result.indexOf('405 Not Allowed')!==-1){
console.log(chalk.red('当前组件发布的目标EasyV平台暂不支持静态资源上传功能,需要v7.0版本以上的平台。\n'));
return ;
}
throw new Error(result.message);
} catch(error) {
console.log(chalk.red(error));
}
return;
}
})
}
//独立部署提示
if (result.indexOf('405 Not Allowed') !== -1) {
console.log(
chalk.red(
'当前组件发布的目标EasyV平台暂不支持静态资源上传功能,需要v7.0版本以上的平台。\n',
),
);
return;
}
const uploadAssets = async ({
moduleName,
token,
host
}) => {
const {base} = getComponentBase(moduleName);
const defaultParams = {
headers:{
token:crypto
.privateEncrypt(token.privateKey, Buffer.from('NIKO NIKO NI'))
.toString('hex'),
},
method:'POST',
json: true,
agent: host.startsWith('https')
? new https.Agent({
rejectUnauthorized: false,
})
: null,
formData:{
constantName: `${base.module_name}/${base.version}`
},
throw new Error(result.message);
} catch (error) {
console.log(chalk.red(error));
}
}
const assetsPath = path.join(appComponents, moduleName, 'assets');
load(assetsPath,host,defaultParams,assetsPath);
});
};
module.exports = async( name, cmd ) => {
checkEasyvProject();
const appPackageJSON = require(appPackage);
const uploadAssets = async ({ moduleName, token, host, appPackageJSON }) => {
const builderUtil = require(path.join(
getPluginRoot(appPackageJSON.easyv.builder),
'utils/index.js',
));
let host, hostError = false;
const h = cmd.host;
if(!h){
if (typeof appPackageJSON.easyv.assetsHost === 'string') {
host = appPackageJSON.easyv.assetsHost;
} else {
hostError = true;
}
const { base } = builderUtil.getComponentBase(moduleName);
const defaultParams = {
headers: {
token: crypto
.privateEncrypt(token.privateKey, Buffer.from('NIKO NIKO NI'))
.toString('hex'),
},
method: 'POST',
json: true,
agent: host.startsWith('https')
? new https.Agent({
rejectUnauthorized: false,
})
: null,
formData: {
constantName: `${base.module_name}/${base.version}`,
},
};
const assetsPath = path.join(appComponents, moduleName, 'assets');
load(assetsPath, host, defaultParams, assetsPath);
};
module.exports = async (name, cmd) => {
checkEasyvProject();
const appPackageJSON = require(appPackage);
let host,
hostError = false;
const h = cmd.host;
if (!h) {
if (typeof appPackageJSON.easyv.assetsHost === 'string') {
host = appPackageJSON.easyv.assetsHost;
} else {
hostError = true;
}
else{
const globalConfig = getGlobalConfig();
const presetHosts =
typeof appPackageJSON.easyv.assetsHost === 'object'
? appPackageJSON.easyv.assetsHost
: {};
host = presetHosts[h] || globalConfig[h] || h;
}
if(hostError){
console.log(chalk.red('host was not specify, use --host <server> '));
process.exit();
}
} else {
const globalConfig = getGlobalConfig();
const presetHosts =
typeof appPackageJSON.easyv.assetsHost === 'object'
? appPackageJSON.easyv.assetsHost
: {};
host = presetHosts[h] || globalConfig[h] || h;
}
if (hostError) {
console.log(chalk.red('host was not specify, use --host <server> '));
process.exit();
}
const isAllUpload = cmd.all;
const isAllUpload = cmd.all;
if(isAllUpload){
name = fs.readdirSync(appComponents)
}
else {
if(name.indexOf(',')){
name = name.split(',');
}
else{
name = [name];
}
if (isAllUpload) {
name = fs.readdirSync(appComponents);
} else {
if (name.indexOf(',')) {
name = name.split(',');
} else {
name = [name];
}
}
const token = await getToken();
const token = await getToken();
await Promise.all(
name.map(async(moduleName)=>{
await uploadAssets({
moduleName,
token,
host
});
})
);
};
await Promise.all(
name.map(async (moduleName) => {
await uploadAssets({
moduleName,
token,
host,
appPackageJSON,
});
}),
);
};

@@ -172,50 +172,6 @@ const fs = require('fs');

function getComponentBase(name) {
const sourcePath = path.join(appComponents, name);
if (!fs.existsSync(sourcePath)) {
console.error(chalk.red(`cannot found folder ${sourcePath}.`));
process.exit();
}
//旧配置
if (fs.existsSync(path.join(sourcePath, "js/config.js")) &&
fs.existsSync(path.join(sourcePath, "mocks/data.js"))
) {
const base = require(path.resolve(sourcePath, "js/config.js")).config.base;
return { base };
}
//新配置
const newConfigs = ["config/main", "config/main.data"];
newConfigs.every((file) => {
if (!(fs.existsSync(path.join(sourcePath, file + ".js")) ||
fs.existsSync(path.join(sourcePath, file + ".json")))
) {
console.error(
chalk.red(
`${file}.js or ${file}.json cannot be found in folder ${sourcePath}, if the folder is not a component folder please move it out.`
)
);
process.exit();
}
return true;
});
let base = {};
if (fs.existsSync(path.join(sourcePath, "config/main.json"))) {
base = JSON.parse(fs.readFileSync(path.join(sourcePath, "config/main.json"), {
encoding: "utf8"
})).base;
} else {
base = require(path.resolve(sourcePath, "config/main.js")).default.base;
}
return { base }
}
function checkHtmlError(html) {
return (html + '').includes(`<title>Error</title>`)
return (html + '').includes(`<title>Error</title>`);
}
module.exports = {

@@ -231,3 +187,2 @@ getGlobalConfig,

readCustomTemplates,
getComponentBase
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc