Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function Deploy (options: IOptions | IOptions[], modified: IFile[], total
const to = option.to;
const cachePath = option.cachePath;
const cache = option.cache;
const fisConfigFilePath = option.fisConfigFilePath;
let receiver = option.receiver;
let authApi = option.authApi;
let validateApi = option.validateApi;
Expand All @@ -40,7 +41,9 @@ export function Deploy (options: IOptions | IOptions[], modified: IFile[], total
cachePath,
file.getHashRelease ? file.getHashRelease() : file.relative,
file.contents,
file, (error) => error ? errorHandler(file, error, () => reduce(next)) : next()
file,
(error) => error ? errorHandler(file, error, () => reduce(next)) : next(),
fisConfigFilePath
);
});

Expand Down Expand Up @@ -79,4 +82,6 @@ export interface IOptions {
retry: number;
cachePath: string;
cache: boolean;
/** fis 的配置文件目录 */
fisConfigFilePath?: string;
}
8 changes: 6 additions & 2 deletions src/http-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export function httpPush (options: IDeployOption[]) {
cachePath,
host: option.host,
retry: 2,
to: option.to }, {
to: option.to,
fisConfigFilePath: option.fisConfigFilePath
}, {
contents: file.contents,
path: file.path,
relative: '/' + file.relative,
stat: file.stat });
stat: file.stat
});
// 在match名单中
// console.log(option.to, file.path);
}
Expand All @@ -56,4 +59,5 @@ interface IDeployOption {
cachePath?: string;
/** 是否缓存 */
cache?: boolean;
fisConfigFilePath?: string;
}
9 changes: 7 additions & 2 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ import { resolve } from 'path';

const HOME = homedir();
let TOKEN_FILE = `${HOME}/.fis3-tmp/deploy.json`;
let hasCustomTokenPath = false;

if (!existsSync(TOKEN_FILE)) {
// 优先使用FIS3全局TOKEN 因为机器唯一 使用不同TOKEN会导致频繁验证
TOKEN_FILE = `${HOME}/.gulp-deploy-http-push.json`;
}

const TOKEN_PATH = resolve(TOKEN_FILE);
let TOKEN_PATH = resolve(TOKEN_FILE);

let token: null|IToken = null;

export function getToken (): IToken {
export function getToken (fisConfigFilePath?: string): IToken {
if (token !== null) {
return token;
}
if (fisConfigFilePath && !hasCustomTokenPath) {
TOKEN_PATH = resolve(HOME + '/' + fisConfigFilePath);
hasCustomTokenPath = true;
}
token = existsSync(TOKEN_PATH)
? JSON.parse(readFileSync(TOKEN_PATH).toString() || '{}') as IToken
: {};
Expand Down
4 changes: 2 additions & 2 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { parseUrl } from './fetch';
import { IFile } from './file';
import { getToken } from './token';
import { Text } from './util';
export function upload (receiver, to, cache, cachePath, release, content, file: IFile, callback) {
export function upload (receiver, to, cache, cachePath, release, content, file: IFile, callback, fisConfigFilePath?: string ) {
const subpath = file.subpath || file.relative;
if (!subpath) {
throw new Error('subpath is undefined');
}
const data = { ...getToken(), to: to + release };
const data = { ...getToken(fisConfigFilePath), to: to + release };
fupload(
// url, request options, post data, file
receiver, null, data, content, subpath,
Expand Down