Skip to content

Commit

Permalink
refactor: use form-data and update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesteery committed Jul 31, 2021
1 parent 958f98d commit 2a7df50
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 331 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
pull-request-title-pattern: 'chore${scope}: release${component} v${version}'
bump-minor-pre-major: true
default_branch: main
changelog-types: '[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"perf","section":"Performance Improvements"},{"type":"deps","section":"Dependencies"},{"type":"revert","section":"Reverts"},{"type":"docs","section":"Documentation"},{"type":"style","section":"Styles","hidden":true},{"type":"chore","section":"Miscellaneous Chores","hidden":true},{"type":"refactor","section":"Code Refactoring","hidden":false},{"type":"test","section":"Tests","hidden":true},{"type":"ci","section":"Continuous Integration","hidden":true}]'

publish:
name: Publish extension
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ yarn build --noEmit # check typescript types
git commit -am "conventional commit"
git push origin <branch_name>
```

## Testing

Open this project with Visual Studio Code, and click on `Run Extension` (or `F5`).
250 changes: 125 additions & 125 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,127 +1,127 @@
{
"name": "rtdbin",
"displayName": "Read The Bin",
"publisher": "readthedocs",
"description": "An extension to easily create bins.",
"version": "0.2.1",
"icon": "media/icon.png",
"main": "build/extension.js",
"prettier": "@typescord/prettier-config",
"scripts": {
"vscode:prepublish": "yarn build",
"deploy-vsce": "vsce publish",
"deploy-ovsx": "ovsx publish",
"package": "vsce package --yarn -o bin.vsix",
"build": "tsc",
"watch": "tsc -w",
"lint": "eslint src --ext ts",
"lint-fix": "yarn lint --fix",
"format": "prettier . --write"
},
"author": "Read The Docs FR",
"engines": {
"vscode": "^1.52.0"
},
"license": "MIT",
"homepage": "https://github.com/readthedocs-fr/bin-client-discord#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/readthedocs-fr/bin-client-discord.git"
},
"bugs": {
"url": "https://github.com/readthedocs-fr/bin-client-discord/issues"
},
"activationEvents": [
"onCommand:rtdbin.createBin"
],
"contributes": {
"commands": [
{
"command": "rtdbin.createBin",
"title": "Create a bin",
"category": "Bin",
"enablement": "activeEditor || activePanel == 'workbench.panel.output' || explorerViewletVisible && !explorerResourceIsFolder"
}
],
"keybindings": [
{
"command": "rtdbin.createBin",
"key": "ctrl+; h",
"when": "activeEditor || activePanel == 'workbench.panel.output'"
}
],
"menus": {
"commandPalette": [
{
"command": "rtdbin.createBin",
"title": "Create a bin",
"category": "Bin",
"when": "activeEditor || activePanel == 'workbench.panel.output'"
}
],
"explorer/context": [
{
"command": "rtdbin.createBin",
"group": "5_cutcopypaste",
"when": "!explorerResourceIsFolder"
}
],
"editor/context": [
{
"command": "rtdbin.createBin",
"group": "9_cutcopypaste",
"when": "editorTextFocus"
}
]
},
"configuration": {
"title": "Read The Bin",
"properties": {
"rtdbin.defaultLifetime": {
"type": "string",
"default": "0",
"pattern": "^[\\ddhms]+$",
"markdownDescription": "The default lifetime of your futures bins (0 for never, else in this format: 1d1h1m1s)"
},
"rtdbin.defaultMaxUses": {
"type": "integer",
"default": "0",
"description": "The default max uses of your futures bins (0 for infinity)"
}
}
}
},
"categories": [
"Other"
],
"dependencies": {
"@typescord/famfor": "^0.1.2",
"got": "^11.8.2"
},
"devDependencies": {
"@types/node": "^15.0.2",
"@types/vscode": "^1.52.0",
"@typescord/eslint-config": "^0.2.1",
"@typescord/prettier-config": "^0.1.2",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.22.1",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.7.0",
"eslint-plugin-unicorn": "^32.0.1",
"ovsx": "0.1.0",
"prettier": "^2.3.0",
"rimraf": "^3.0.2",
"typescript": "~4.2.4",
"vsce": "^1.84.0"
},
"keywords": [
"bin",
"rtdbin",
"pastebin"
]
"name": "rtdbin",
"displayName": "Read The Bin",
"publisher": "readthedocs",
"description": "An extension to easily create bins.",
"version": "0.2.1",
"icon": "media/icon.png",
"main": "build/extension.js",
"prettier": "@typescord/prettier-config",
"scripts": {
"vscode:prepublish": "yarn build",
"deploy-vsce": "vsce publish",
"deploy-ovsx": "ovsx publish",
"package": "vsce package --yarn -o bin.vsix",
"build": "tsc",
"watch": "tsc -w",
"lint": "eslint src --ext ts",
"lint-fix": "yarn lint --fix",
"format": "prettier . --write"
},
"author": "Read The Docs FR",
"engines": {
"vscode": "^1.52.0"
},
"license": "MIT",
"homepage": "https://github.com/readthedocs-fr/bin-client-discord#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/readthedocs-fr/bin-client-discord.git"
},
"bugs": {
"url": "https://github.com/readthedocs-fr/bin-client-discord/issues"
},
"activationEvents": [
"onCommand:rtdbin.createBin"
],
"contributes": {
"commands": [
{
"command": "rtdbin.createBin",
"title": "Create a bin",
"category": "Bin",
"enablement": "activeEditor || activePanel == 'workbench.panel.output' || explorerViewletVisible && !explorerResourceIsFolder"
}
],
"keybindings": [
{
"command": "rtdbin.createBin",
"key": "ctrl+; h",
"when": "activeEditor || activePanel == 'workbench.panel.output'"
}
],
"menus": {
"commandPalette": [
{
"command": "rtdbin.createBin",
"title": "Create a bin",
"category": "Bin",
"when": "activeEditor || activePanel == 'workbench.panel.output'"
}
],
"explorer/context": [
{
"command": "rtdbin.createBin",
"group": "5_cutcopypaste",
"when": "!explorerResourceIsFolder"
}
],
"editor/context": [
{
"command": "rtdbin.createBin",
"group": "9_cutcopypaste",
"when": "editorTextFocus"
}
]
},
"configuration": {
"title": "Read The Bin",
"properties": {
"rtdbin.defaultLifetime": {
"type": "string",
"default": "0",
"pattern": "^[\\ddhms]+$",
"markdownDescription": "The default lifetime of your futures bins (0 for never, else in this format: 1d1h1m1s)"
},
"rtdbin.defaultMaxUses": {
"type": "integer",
"default": "0",
"description": "The default max uses of your futures bins (0 for infinity)"
}
}
}
},
"categories": [
"Other"
],
"dependencies": {
"form-data": "^4.0.0",
"got": "^11.8.2"
},
"devDependencies": {
"@types/node": "^15.0.2",
"@types/vscode": "^1.52.0",
"@typescord/eslint-config": "^0.2.1",
"@typescord/prettier-config": "^0.1.2",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.22.1",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.7.0",
"eslint-plugin-unicorn": "^32.0.1",
"ovsx": "0.1.0",
"prettier": "^2.3.0",
"rimraf": "^3.0.2",
"typescript": "~4.2.4",
"vsce": "^1.84.0"
},
"keywords": [
"bin",
"rtdbin",
"pastebin"
]
}
37 changes: 9 additions & 28 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { basename } from 'path';
import { window, commands, workspace, env, Uri, ExtensionContext } from 'vscode';
import { createBin } from './helpers/bin';
import { input } from './helpers/input';
import { createBin, input } from './helpers';

// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};
Expand All @@ -21,34 +20,19 @@ export function activate(context: ExtensionContext): void {
const selection = editor.selection;
const code = editor.document.getText(selection.isEmpty ? undefined : selection);

if (!code) {
return;
}

const language = await input({
prompt: 'The language of your bin',
placeHolder: 'Language',
value: editor.document.languageId,
});

if (!language) {
return;
}
if (!code) return;

const configuration = workspace.getConfiguration('rtdbin');

const lifetime = await input({
const lifeTime = await input({
prompt: 'The lifetime of your bin (0 for never, else in this format: 1d1h1m1s)',
placeHolder: 'Lifetime',
value: configuration.get('defaultLifetime'),
validateInput(value) {
return !/^[\ddhms]+$/.test(value) ? 'Please enter a valid duration (0 or 1d1h1m1s).' : undefined;
},
});

if (!lifetime) {
return;
}
if (!lifeTime) return;

const maxUses = await input({
prompt: 'The max uses of your bin (0 for infinity)',
Expand All @@ -60,29 +44,26 @@ export function activate(context: ExtensionContext): void {
return isNaN(maxUses) || maxUses < 0 ? 'Please enter a valid integer greater than or equal to 0.' : undefined;
},
});

if (!maxUses) {
return;
}
if (!maxUses) return;

try {
const binUrl = await createBin({
code,
filename: basename(editor.document.fileName),
language,
fileName: basename(editor.document.fileName),
maxUses: parseInt(maxUses),
lifetime: parseInt(lifetime),
lifeTime: parseInt(lifeTime),
});

const action = await window.showInformationMessage(`[${binUrl}](${binUrl})`, 'Open', 'Copy');

if (action === 'Open') {
env.openExternal(Uri.parse(binUrl));
} else {
// action === 'Copy'
env.clipboard.writeText(binUrl);
}
} catch (error) {
window.showErrorMessage(error);
window.showErrorMessage(error.toString());
}
});

Expand Down
Loading

0 comments on commit 2a7df50

Please sign in to comment.