Comparing version 1.1.1 to 1.2.0
#!/usr/bin/env node | ||
import axios from 'axios'; | ||
import chalk from 'chalk'; | ||
import { program } from 'commander'; | ||
import * as dotenv from 'dotenv'; | ||
import formData from 'form-data'; | ||
import fs from 'fs'; | ||
import capitalize from 'lodash/fp/capitalize.js'; | ||
import ora from 'ora'; | ||
import path, { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
dotenv.config({ path: path.resolve(__dirname, '../.env') }); | ||
// This ID seems not necessary at all, but we're putting it in the request header anyway since it's | ||
// documented in the official docs | ||
const CLIENT_ID = process.env.IMGUR_CLIENT_ID; | ||
// There are some crazy issues with the TS and the new module system. So instead of importing the | ||
// package.json, we will just read it via the fs module... 😢 | ||
const packageJSONFilePath = path.resolve(__dirname, '../package.json'); | ||
const packageJSON = JSON.parse(fs.readFileSync(packageJSONFilePath, 'utf8')); | ||
const appVersion = packageJSON.version; | ||
program | ||
.option('-f, --file <string>', 'specify an image file path to upload to imgur'); | ||
program.version(appVersion, '-v, --version', 'output the current version'); | ||
program.parse(process.argv); | ||
import path from 'path'; | ||
import { createProgram } from './cli.js'; | ||
import { uploadImage } from './utils.js'; | ||
const program = createProgram(); | ||
const options = program.opts(); | ||
const data = new formData(); | ||
const file = options.file; | ||
@@ -37,4 +19,2 @@ if (!file) { | ||
const filePath = path.resolve(process.cwd(), file); | ||
const baseName = path.basename(filePath); | ||
const fileName = path.parse(baseName).name; | ||
if (!fs.existsSync(filePath)) { | ||
@@ -44,2 +24,5 @@ console.log(`${filePath} doesn't exist!`); | ||
} | ||
const data = new formData(); | ||
const baseName = path.basename(filePath); | ||
const fileName = path.parse(baseName).name; | ||
data.append('image', fs.createReadStream(filePath)); | ||
@@ -51,16 +34,16 @@ data.append('name', fileName); | ||
url: 'https://api.imgur.com/3/upload', | ||
headers: Object.assign({ Authorization: `Client-ID ${CLIENT_ID}` }, data.getHeaders()), | ||
headers: { | ||
...data.getHeaders(), | ||
}, | ||
data: data, | ||
}; | ||
const spinner = ora('Uploading image to imgur...').start(); | ||
axios(config) | ||
.then((response) => { | ||
spinner.succeed('Success'); | ||
console.log('Image URL:', chalk.bold(response.data.data.link)); | ||
console.log('Markdown:', `![${capitalize(fileName)} image](${response.data.data.link})`); | ||
}) | ||
.catch((error) => { | ||
spinner.fail('Failed'); | ||
console.log(error); | ||
}); | ||
const maybeLink = await uploadImage(config); | ||
if (maybeLink) { | ||
console.log('Image URL:', chalk.bold(maybeLink)); | ||
console.log('Markdown:', `![${capitalize(fileName)} image](${maybeLink})`); | ||
process.exit(0); | ||
} | ||
else { | ||
process.exit(1); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "imgup", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "index.js", | ||
@@ -22,17 +22,15 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/axios": "^0.14.0", | ||
"@types/form-data": "^2.5.0", | ||
"@types/lodash": "^4.14.176", | ||
"@types/node": "^16.11.7", | ||
"axios": "^0.24.0", | ||
"axios": "^1.2.6", | ||
"chalk": "^4.1.2", | ||
"commander": "^8.3.0", | ||
"dotenv": "^10.0.0", | ||
"form-data": "^4.0.0", | ||
"husky": "^4.3.8", | ||
"lodash": "^4.17.21", | ||
"ora": "^6.0.1", | ||
"prettier": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"husky": "^4.3.8" | ||
} | ||
} |
@@ -5,2 +5,8 @@ # imgup | ||
## Installation | ||
```sh | ||
npm install -g imgup | ||
``` | ||
## Usage | ||
@@ -17,13 +23,17 @@ | ||
## Example | ||
To upload an image from our test data directory: | ||
```sh | ||
imgup --file ./a/path/to/an/image.jpg | ||
imgup --file ./testData/big-cat.png | ||
# The following output will be shown in your CLI | ||
✔ Success | ||
Image URL: https://i.imgur.com/example.png | ||
Markdown: ![Example image](https://i.imgur.com/example.png) | ||
Image URL: https://i.imgur.com/mWbxxoM.png | ||
Markdown: ![Big-cat image](https://i.imgur.com/mWbxxoM.png) | ||
``` | ||
## Acknowledgement | ||
Big thanks to [Rob Potter](https://unsplash.com/@robpotter) for the test data image | ||
## TODOs | ||
@@ -38,4 +48,4 @@ | ||
License | ||
## License | ||
MIT |
#!/usr/bin/env node | ||
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { AxiosRequestConfig } from 'axios'; | ||
import chalk from 'chalk'; | ||
import { program } from 'commander'; | ||
import * as dotenv from 'dotenv'; | ||
import formData from 'form-data'; | ||
import fs from 'fs'; | ||
import capitalize from 'lodash/fp/capitalize.js'; | ||
import ora from 'ora'; | ||
import path, { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import path from 'path'; | ||
import { createProgram } from './cli.js'; | ||
import { uploadImage } from './utils.js'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
dotenv.config({ path: path.resolve(__dirname, '../.env') }); | ||
// This ID seems not necessary at all, but we're putting it in the request header anyway since it's | ||
// documented in the official docs | ||
const CLIENT_ID = process.env.IMGUR_CLIENT_ID; | ||
// There are some crazy issues with the TS and the new module system. So instead of importing the | ||
// package.json, we will just read it via the fs module... 😢 | ||
const packageJSONFilePath = path.resolve(__dirname, '../package.json'); | ||
const packageJSON = JSON.parse(fs.readFileSync(packageJSONFilePath, 'utf8')); | ||
const appVersion = packageJSON.version; | ||
program.option( | ||
'-f, --file <string>', | ||
'specify an image file path to upload to imgur', | ||
); | ||
program.version(appVersion, '-v, --version', 'output the current version'); | ||
program.parse(process.argv); | ||
const program = createProgram(); | ||
const options = program.opts(); | ||
const data = new formData(); | ||
const file = options.file as string; | ||
@@ -48,4 +24,2 @@ | ||
const filePath = path.resolve(process.cwd(), file); | ||
const baseName = path.basename(filePath); | ||
const fileName = path.parse(baseName).name; | ||
@@ -57,2 +31,5 @@ if (!fs.existsSync(filePath)) { | ||
const data = new formData(); | ||
const baseName = path.basename(filePath); | ||
const fileName = path.parse(baseName).name; | ||
data.append('image', fs.createReadStream(filePath)); | ||
@@ -66,3 +43,2 @@ data.append('name', fileName); | ||
headers: { | ||
Authorization: `Client-ID ${CLIENT_ID}`, | ||
...data.getHeaders(), | ||
@@ -73,16 +49,10 @@ }, | ||
const spinner = ora('Uploading image to imgur...').start(); | ||
const maybeLink = await uploadImage(config); | ||
axios(config) | ||
.then((response: AxiosResponse) => { | ||
spinner.succeed('Success'); | ||
console.log('Image URL:', chalk.bold(response.data.data.link)); | ||
console.log( | ||
'Markdown:', | ||
`![${capitalize(fileName)} image](${response.data.data.link})`, | ||
); | ||
}) | ||
.catch((error: AxiosError) => { | ||
spinner.fail('Failed'); | ||
console.log(error); | ||
}); | ||
if (maybeLink) { | ||
console.log('Image URL:', chalk.bold(maybeLink)); | ||
console.log('Markdown:', `![${capitalize(fileName)} image](${maybeLink})`); | ||
process.exit(0); | ||
} else { | ||
process.exit(1); | ||
} |
@@ -6,6 +6,6 @@ { | ||
"allowSyntheticDefaultImports": true, | ||
"target": "es6", | ||
"target": "ES2018", | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"moduleResolution": "node", | ||
"moduleResolution": "nodenext", | ||
"strict": true, | ||
@@ -19,5 +19,3 @@ "sourceMap": true, | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} | ||
"include": ["src/**/*"] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
940286
0
19
199
49
12
4
1
+ Added@types/axios@^0.14.0
+ Addedhusky@^4.3.8
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@types/axios@0.14.4(transitive)
+ Added@types/parse-json@4.0.2(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedci-info@2.0.0(transitive)
+ Addedcompare-versions@3.6.0(transitive)
+ Addedcosmiconfig@7.1.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedfind-versions@4.0.0(transitive)
+ Addedhusky@4.3.8(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedopencollective-postinstall@2.0.3(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpkg-dir@5.0.0(transitive)
+ Addedplease-upgrade-node@3.2.0(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedsemver-compare@1.0.0(transitive)
+ Addedsemver-regex@3.1.4(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedwhich-pm-runs@1.1.0(transitive)
+ Addedyaml@1.10.2(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removeddotenv@^10.0.0
- Removedaxios@0.24.0(transitive)
- Removeddotenv@10.0.0(transitive)
Updatedaxios@^1.2.6