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

aliyun-oss-deploy

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aliyun-oss-deploy - npm Package Compare versions

Comparing version

to
0.0.3

bin/Deploy.js

65

bin/index.js

@@ -5,1 +5,66 @@ /**

*/
const fs = require('fs');
const path = require('path');
const { h, render } = require('ink');
const assert = require('assert');
const DeployComponent = require('./Deploy.js');
const deploy = require('..');
const deployGenerator = deploy.deployGenerator;
/**
* 命令行参数配置
*/
const argv = require('yargs')
.option('p', {
describe: 'Set your upload files path',
type: 'string',
alias: 'filePath',
})
.option('d', {
describe: 'Set the target dir of upload',
type: 'string',
alias: 'prefix',
})
.option('c', {
describe: 'Set your .aliossrc file path',
type: 'string',
alias: 'aliossrc',
})
.option('s', {
describe: 'Upload file by putStream',
type: 'boolean',
alias: 'useStream',
})
.help()
.argv;
// 校验路径
assert(argv.filePath, 'argv -p should be required');
// oss 配置文件
const aliossrc = argv.aliossrc && path.resolve(argv.aliossrc) || path.join(process.cwd(), '.aliossrc');
const ossConfig = JSON.parse(fs.readFileSync(aliossrc, {
encoding: 'utf8',
}));
// 校验配置
assert(ossConfig.region, `region is required in ${aliossrc}`);
assert(ossConfig.accessKeyId, `accessKeyId is required in ${aliossrc}`);
assert(ossConfig.accessKeySecret, `accessKeySecret is required in ${aliossrc}`);
assert(ossConfig.bucket, `bucket is required in ${aliossrc}`);
const dg = deployGenerator(argv.filePath, ossConfig, argv.prefix, argv.useStream);
let unmount;
const onExit = () => {
unmount();
process.exit(0);
};
// render ink component
unmount = render(h(DeployComponent, { dg, onExit }));

60

index.js

@@ -8,2 +8,3 @@ /**

const path = require('path');
const co = require('co');

@@ -16,11 +17,10 @@ const OSS = require('ali-oss');

/**
* 使用 putObject 上传
* @param client
* @param file
* @param ossTarget
* @param stream
*/
const uploadByPutObject = async (client, file, ossTarget) => {
const stream = fs.createReadStream(file);
const uploadByPutObject = async (client, ossTarget, stream) => {
return await co(function*() {

@@ -36,8 +36,6 @@ return Promise.resolve(

* @param client
* @param file
* @param ossTarget
* @param stream
*/
const uploadByPutStream = async (client, file, ossTarget) => {
const stream = fs.createReadStream(file);
const uploadByPutStream = async (client, ossTarget, stream) => {
return await co(function*() {

@@ -51,11 +49,10 @@ return Promise.resolve(

/**
* 入口方法
* @param filePath 上传的文件目录
* @param config aliyun-oss 配置内容
* @param prefix 上传到 oss 的批量文件前缀,可以用于做版本号
* @param byStream 默认是 putObject
* 上传文件的 generator
* @param filePath
* @param config
* @param prefix
* @param byStream
*/
module.exports = async (filePath, config, prefix, byStream) => {
const deployGenerator = function* (filePath, config, prefix, byStream) {
prefix = prefix || '';
byStream = !!byStream;

@@ -66,17 +63,34 @@ const client = new OSS(config);

const files = fileList(filePath);
const func = byStream ? uploadByPutStream : uploadByPutObject;
const uploadFunc = byStream ? uploadByPutStream : uploadByPutObject;
const r = [];
let file;
for (const file of files) {
const ossTarget = path.join(prefix, file);
// stream
const stream = fs.createReadStream(path.join(filePath, file));
for (let i = 0; i < files.length; i ++) {
file = files[i];
// 使用 oss 上传文件 file 到 targetFile
r.push(
await uploadFunc(client, path.join(filePath, file), prefix + file),
);
const result = yield func(client, ossTarget, stream);
r.push(result);
}
return r;
};
/**
* 入口方法
* @param filePath 上传的文件目录
* @param config aliyun oss 配置内容
* @param prefix 上传到 oss 的批量文件前缀,可以用于做版本号
* @param byStream 默认是 putObject
*/
module.exports = async (filePath, config, prefix, byStream) => {
return await co(function*() {
return Promise.resolve(
yield deployGenerator(filePath, config, prefix, byStream),
);
});
};
module.exports.deployGenerator = deployGenerator;
{
"name": "aliyun-oss-deploy",
"version": "0.0.2",
"version": "0.0.3",
"description": "An aliyun oss deploy tool, putObject and putStream are all supported.",

@@ -31,5 +31,8 @@ "main": "index.js",

"ali-oss": "^5.2.0",
"assert": "^1.4.1",
"co": "^4.6.0",
"globby": "^8.0.1"
"globby": "^8.0.1",
"ink": "^0.5.0",
"yargs": "^11.0.0"
}
}

@@ -5,4 +5,2 @@ # aliyun-oss-deploy

[![Build Status](https://travis-ci.org/hustcc/aliyun-oss-deploy.svg?branch=master)](https://travis-ci.org/hustcc/aliyun-oss-deploy)
[![Coverage Status](https://coveralls.io/repos/github/hustcc/aliyun-oss-deploy/badge.svg?branch=master)](https://coveralls.io/github/hustcc/aliyun-oss-deploy)
[![npm](https://img.shields.io/npm/v/aliyun-oss-deploy.svg)](https://www.npmjs.com/package/aliyun-oss-deploy)

@@ -35,7 +33,19 @@ [![npm](https://img.shields.io/npm/dm/aliyun-oss-deploy.svg)](https://www.npmjs.com/package/aliyun-oss-deploy)

```bash
aliyun-oss-deploy -p ./dist -c .aliossrc
aliyun-oss-deploy -p ./dist -c .aliossrc -d static
```
> 其中 -p c 参数是指定 oss 配置文件路径,不传则默认为当前目录的 `.aliossrc` 文件。
帮助文档:
```bash
aliyun-oss-deploy --help
Options:
--version Show version number [boolean]
-p, --filePath Set your upload files path [string]
-d, --prefix Set the target dir of upload [string]
-c, --aliossrc Set your .aliossrc file path [string]
-s, --useStream Upload file by putStream [boolean]
--help Show help [boolean]
```
可以在 package.json 中直接使用

@@ -63,11 +73,12 @@

"accessKeySecret": "your accessKeySecret",
"endpoint": "your endpoint",
"bucket": "your bucket",
"bucketPath": "your bucketPath"
"region": "your region",
"bucket": "your bucket"
}
```
**注意**:`region` 是区分 endpoint 的区域分类。
## License
ISC@[hustcc](https://github.com/hustcc).

Sorry, the diff of this file is not supported yet