-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8326b3a
Showing
39 changed files
with
4,089 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
dist/ | ||
.DS_Store | ||
yarn-error.log | ||
temp.js | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules/ | ||
yarn-error.log | ||
temp.js | ||
package-lock.json | ||
tsconfig.json | ||
tslint.json | ||
.vscode/ | ||
src/ | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
language: node_js | ||
node_js: stable | ||
|
||
# Travis-CI Caching | ||
cache: | ||
directories: | ||
- node_modules | ||
yarn: true | ||
|
||
# S: Build Lifecycle | ||
install: | ||
- yarn | ||
|
||
stages: | ||
- name: deploy | ||
|
||
jobs: | ||
include: | ||
- stage: deploy | ||
script: | ||
- npm run build | ||
deploy: | ||
provider: npm | ||
email: "[email protected]" | ||
api_key: "${NPM_TOKEN}" | ||
skip_cleanup: true | ||
on: | ||
branch: master | ||
branches: | ||
only: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tslint.enable": true, | ||
"tslint.autoFixOnSave": true, | ||
"typescript.tsdk": "node_modules\\typescript\\lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Molunerfinn | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
## PicGo - Core | ||
|
||
 | ||
 | ||
 | ||
 | ||
|
||
 | ||
|
||
A tool for picture uploading. Both CLI & api supports. | ||
|
||
|
||
## Installation | ||
|
||
### Global install | ||
|
||
```bash | ||
npm install picgo -g | ||
|
||
# or | ||
|
||
yarn global add picgo | ||
``` | ||
|
||
### Local install | ||
|
||
```bash | ||
npm install picgo -D | ||
|
||
# or | ||
|
||
yarn add picgo -D | ||
``` | ||
|
||
## Usage | ||
|
||
### Use in CLI | ||
|
||
> PicGo uses `SM.MS` as the default upload pic-bed. | ||
Show help: | ||
|
||
```bash | ||
$ picgo -h | ||
|
||
Usage: picgo [options] [command] | ||
|
||
Options: | ||
|
||
-v, --version output the version number | ||
-d, --debug debug mode | ||
-s, --silent silent mode | ||
-c, --config <path> set config path | ||
-h, --help output usage information | ||
|
||
Commands: | ||
|
||
install|add <plugins...> install picgo plugin | ||
uninstall|rm <plugins...> uninstall picgo plugin | ||
update <plugins...> update picgo plugin | ||
set|config <module> [name] configure config of picgo modules | ||
upload|u <input...> upload, go go go | ||
choose|ch [options] [module] choose modules of picgo | ||
``` | ||
|
||
#### Upload a picture from path | ||
|
||
```bash | ||
picgo upload /xxx/xx/xx.jpg | ||
``` | ||
|
||
### Use in node project | ||
|
||
```js | ||
const PicGo = require('picgo') | ||
const picgo = new PicGo() | ||
|
||
picgo.upload(['/xxx/xxx.jpg']) | ||
``` | ||
|
||
## Documentation | ||
|
||
For more details, you can checkout [documentation](https://picgo.github.io/PicGo-Core-Doc/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env node | ||
const path = require('path') | ||
const minimist = require('minimist') | ||
let argv = minimist(process.argv.slice(2)) | ||
let configPath = argv.c || argv.config || '' | ||
if (configPath) { | ||
configPath = path.resolve(configPath) | ||
} | ||
const PicGo = require('../dist/src/index') | ||
const picgo = new PicGo(configPath) | ||
|
||
try { | ||
picgo.cmd.program.parse(process.argv) | ||
} catch (e) { | ||
picgo.log.error(e) | ||
if (process.argv.includes('--debug')) { | ||
Promise.reject(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "picgo", | ||
"version": "1.0.10", | ||
"description": "A tool for picture uploading", | ||
"main": "dist/src/index.js", | ||
"bin": { | ||
"picgo": "./bin/picgo" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc -p .", | ||
"dev": "tsc -w -p .", | ||
"patch": "npm version patch && git push origin master && git push origin --tags", | ||
"minor": "npm version minor && git push origin master && git push origin --tags", | ||
"major": "npm version major && git push origin master && git push origin --tags" | ||
}, | ||
"keywords": [ | ||
"picture", | ||
"upload", | ||
"util" | ||
], | ||
"author": "Molunerfinn", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/cross-spawn": "^6.0.0", | ||
"@types/fs-extra": "^5.0.4", | ||
"@types/image-size": "^0.0.29", | ||
"@types/inquirer": "^0.0.42", | ||
"@types/lowdb": "^1.0.4", | ||
"@types/md5": "^2.1.32", | ||
"@types/node": "^10.5.2", | ||
"@types/request-promise-native": "^1.0.15", | ||
"@types/resolve": "^0.0.8", | ||
"eslint": "^5.0.1", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.13.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.8.0", | ||
"eslint-plugin-standard": "^3.1.0", | ||
"tslint": "^5.10.0", | ||
"tslint-config-standard": "^7.1.0", | ||
"typescript": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"chalk": "^2.4.1", | ||
"commander": "^2.17.0", | ||
"cross-spawn": "^6.0.5", | ||
"dayjs": "^1.7.4", | ||
"fs-extra": "^6.0.1", | ||
"image-size": "^0.6.3", | ||
"inquirer": "^6.0.0", | ||
"lodash-id": "^0.14.0", | ||
"lowdb": "^1.0.0", | ||
"md5": "^2.2.1", | ||
"qiniu": "^7.2.1", | ||
"request": "^2.87.0", | ||
"request-promise-native": "^1.0.5", | ||
"resolve": "^1.8.1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/PicGo/PicGo-Core.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { EventEmitter } from 'events' | ||
import PicGo from './PicGo' | ||
import { Plugin } from '../utils/interfaces' | ||
|
||
class Lifecycle extends EventEmitter { | ||
configPath: string | ||
ctx: PicGo | ||
|
||
constructor (ctx: PicGo) { | ||
super() | ||
this.ctx = ctx | ||
} | ||
|
||
async start (input: any[]) { | ||
try { | ||
// images input | ||
if (!Array.isArray(input)) { | ||
throw new Error('Input must be an array.') | ||
} | ||
this.ctx.input = input | ||
|
||
// lifecycle main | ||
await this.beforeTransform(this.ctx) | ||
await this.doTransform(this.ctx) | ||
await this.beforeUpload(this.ctx) | ||
await this.doUpload(this.ctx) | ||
await this.afterUpload(this.ctx) | ||
return this.ctx | ||
} catch (e) { | ||
this.ctx.emit('uploadProgress', -1) | ||
this.ctx.emit('failed') | ||
this.ctx.log.error(e) | ||
if (this.ctx.config.debug) { | ||
Promise.reject(e) | ||
} | ||
} | ||
} | ||
async beforeTransform (ctx: PicGo) { | ||
this.ctx.emit('uploadProgress', 0) | ||
this.ctx.emit('beforeTransform', ctx) | ||
this.ctx.log.info('Before transform') | ||
await this.handlePlugins(ctx.helper.beforeTransformPlugins.getList(), ctx) | ||
return ctx | ||
} | ||
async doTransform (ctx: PicGo) { | ||
this.ctx.emit('uploadProgress', 30) | ||
this.ctx.log.info('Transforming...') | ||
let type = ctx.config.picBed.transformer || 'path' | ||
let transformer = this.ctx.helper.transformer.get(type) | ||
if (!transformer) { | ||
transformer = this.ctx.helper.transformer.get('path') | ||
ctx.log.warn(`Can't find transformer - ${type}, swtich to default transformer - path`) | ||
} | ||
await transformer.handle(ctx) | ||
return ctx | ||
} | ||
async beforeUpload (ctx: PicGo) { | ||
this.ctx.emit('uploadProgress', 60) | ||
this.ctx.log.info('Before upload') | ||
this.ctx.emit('beforeUpload', ctx) | ||
await this.handlePlugins(ctx.helper.beforeUploadPlugins.getList(), ctx) | ||
return ctx | ||
} | ||
async doUpload (ctx: PicGo) { | ||
this.ctx.log.info('Uploading...') | ||
let type = ctx.config.picBed.uploader || ctx.config.picBed.current || 'smms' | ||
let uploader = this.ctx.helper.uploader.get(type) | ||
if (!uploader) { | ||
uploader = this.ctx.helper.uploader.get('smms') | ||
ctx.log.warn(`Can't find uploader - ${type}, swtich to default uploader - smms`) | ||
} | ||
await uploader.handle(ctx) | ||
return ctx | ||
} | ||
async afterUpload (ctx: PicGo) { | ||
this.ctx.emit('afterUpload', ctx) | ||
this.ctx.emit('uploadProgress', 100) | ||
await this.handlePlugins(ctx.helper.afterUploadPlugins.getList(), ctx) | ||
this.ctx.emit('finished', ctx) | ||
let msg = '' | ||
for (let i in ctx.output) { | ||
msg += ctx.output[i].imgUrl + '\n' | ||
} | ||
this.ctx.log.success(`\n${msg}`) | ||
return ctx | ||
} | ||
|
||
async handlePlugins (plugins: Plugin[], ctx: PicGo) { | ||
await Promise.all(plugins.map(async plugin => { | ||
await plugin.handle(ctx) | ||
})) | ||
return ctx | ||
} | ||
} | ||
|
||
export default Lifecycle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import chalk from 'chalk' | ||
import PicGo from './PicGo' | ||
|
||
class Logger { | ||
level: {} | ||
ctx | ||
constructor (ctx: PicGo) { | ||
this.level = { | ||
success: 'green', | ||
info: 'blue', | ||
warn: 'yellow', | ||
error: 'red' | ||
} | ||
this.ctx = ctx | ||
} | ||
protected handleLog (type: string, msg: string | Error): string | Error | undefined { | ||
if (!this.ctx.config.silent) { | ||
let log = chalk[this.level[type]](`[PicGo ${type.toUpperCase()}]: `) | ||
log += msg | ||
console.log(log) | ||
return msg | ||
} else { | ||
return | ||
} | ||
} | ||
|
||
success (msg) { | ||
return this.handleLog('success', msg) | ||
} | ||
|
||
info (msg) { | ||
return this.handleLog('info', msg) | ||
} | ||
|
||
error (msg) { | ||
return this.handleLog('error', msg) | ||
} | ||
|
||
warn (msg) { | ||
return this.handleLog('warn', msg) | ||
} | ||
} | ||
|
||
export default Logger |
Oops, something went wrong.