Skip to content

Commit

Permalink
- Make changes to package and tsconfig files to support web
Browse files Browse the repository at this point in the history
- Used vscode.workspace.fs to read and write files instead of fs
  • Loading branch information
surajmandalcell committed Sep 18, 2024
1 parent 58b5f2b commit 8051c06
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 128 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

230 changes: 117 additions & 113 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,113 +1,117 @@
{
"name": "context-copy",
"displayName": "Context Copy",
"publisher": "collinc777",
"repository": {
"type": "git",
"url": "https://github.com/collinc777/context-copy"
},
"description": "VS Code extension that enables one-click copying of multiple files as markdown. Features automatic language detection, file path inclusion, and clipboard integration for seamless code sharing and documentation.",
"version": "0.3.0",
"engines": {
"vscode": "^1.91.0"
},
"icon": "logo.png",
"categories": [
"Other"
],
"main": "./out/extension.js",
"activationEvents": [],
"contributes": {
"commands": [
{
"command": "extension.filesToMarkdown",
"title": "Copy for Context"
},
{
"command": "extension.tabsToMarkdown",
"title": "Copy All Open Tabs for Context"
},
{
"command": "extension.singleFileToMarkdown",
"title": "Copy This File for Context"
},
{
"command": "extension.tabGroupToMarkdown",
"title": "Copy This Tab Group for Context"
}
],
"menus": {
"explorer/context": [
{
"command": "extension.filesToMarkdown"
}
],
"editor/title": [
{
"command": "extension.tabsToMarkdown"
}
],
"editor/title/context": [
{
"command": "extension.singleFileToMarkdown",
"group": "navigation@999",
"when": "resource"
},
{
"command": "extension.tabGroupToMarkdown",
"group": "navigation@999"
},
{
"command": "extension.tabsToMarkdown",
"group": "navigation@999"
}
],
"commandPalette": [
{
"command": "extension.filesToMarkdown",
"title": "Copy for Context"
},
{
"command": "extension.tabsToMarkdown",
"title": "Copy All Open Tabs for Context"
},
{
"command": "extension.singleFileToMarkdown",
"title": "Copy This File for Context"
},
{
"command": "extension.tabGroupToMarkdown",
"title": "Copy This Tab Group for Context"
}
]
}
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet",
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix",
"format": "prettier --write 'src/**/*.{js,ts,tsx}'",
"format:check": "prettier --check 'src/**/*.{js,ts,tsx}'",
"test": "node ./out/test/runTest.js",
"package": "vsce package",
"cpi": "npm run compile && npm run package && code-insiders --install-extension $(ls context-copy-*.vsix | head -n 1)"
},
"devDependencies": {
"@types/mocha": "^10.0.7",
"@types/node": "20.x",
"@types/vscode": "^1.91.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.10",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.4",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"typescript": "^5.4.5"
}
}
{
"name": "context-copy",
"displayName": "Context Copy",
"publisher": "collinc777",
"repository": {
"type": "git",
"url": "https://github.com/collinc777/context-copy"
},
"description": "VS Code extension that enables one-click copying of multiple files as markdown. Features automatic language detection, file path inclusion, and clipboard integration for seamless code sharing and documentation.",
"version": "0.3.0",
"engines": {
"vscode": "^1.91.0"
},
"icon": "logo.png",
"categories": [
"Other"
],
"main": "./out/extension.js",
"activationEvents": [],
"contributes": {
"commands": [
{
"command": "extension.filesToMarkdown",
"title": "Copy for Context"
},
{
"command": "extension.tabsToMarkdown",
"title": "Copy All Open Tabs for Context"
},
{
"command": "extension.singleFileToMarkdown",
"title": "Copy This File for Context"
},
{
"command": "extension.tabGroupToMarkdown",
"title": "Copy This Tab Group for Context"
}
],
"menus": {
"explorer/context": [
{
"command": "extension.filesToMarkdown"
}
],
"editor/title": [
{
"command": "extension.tabsToMarkdown"
}
],
"editor/title/context": [
{
"command": "extension.singleFileToMarkdown",
"group": "navigation@999",
"when": "resource"
},
{
"command": "extension.tabGroupToMarkdown",
"group": "navigation@999"
},
{
"command": "extension.tabsToMarkdown",
"group": "navigation@999"
}
],
"commandPalette": [
{
"command": "extension.filesToMarkdown",
"title": "Copy for Context"
},
{
"command": "extension.tabsToMarkdown",
"title": "Copy All Open Tabs for Context"
},
{
"command": "extension.singleFileToMarkdown",
"title": "Copy This File for Context"
},
{
"command": "extension.tabGroupToMarkdown",
"title": "Copy This Tab Group for Context"
}
]
},
"extensionKind": [
"workspace",
"web"
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet",
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix",
"format": "prettier --write 'src/**/*.{js,ts,tsx}'",
"format:check": "prettier --check 'src/**/*.{js,ts,tsx}'",
"test": "node ./out/test/runTest.js",
"package": "vsce package",
"cpi": "npm run compile && npm run package && code-insiders --install-extension $(ls context-copy-*.vsix | head -n 1)"
},
"devDependencies": {
"@types/mocha": "^10.0.7",
"@types/node": "20.x",
"@types/vscode": "^1.91.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.10",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.4",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"typescript": "^5.4.5"
}
}
17 changes: 7 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from 'vscode';
import * as fs from 'fs';

export function activate(context: vscode.ExtensionContext) {
console.log('Activating extension "file-to-markdown"');
Expand Down Expand Up @@ -87,29 +86,27 @@ export function activate(context: vscode.ExtensionContext) {
}
);

context.subscriptions.push(disposable1);
context.subscriptions.push(disposable2);
context.subscriptions.push(disposable3);
context.subscriptions.push(disposable4);
context.subscriptions.push(disposable1, disposable2, disposable3, disposable4);
}

async function convertFilesToMarkdown(files: vscode.Uri[]) {
let markdownContent = '';

for (const file of files) {
const relativePath = vscode.workspace.asRelativePath(file);
let fileContent = fs.readFileSync(file.fsPath, 'utf8');
const fileContent = await vscode.workspace.fs.readFile(file);

// Remove BOM if present
if (fileContent.charCodeAt(0) === 0xfeff) {
fileContent = fileContent.slice(1);
// Convert Uint8Array to string and remove BOM if present
let fileContentString = new TextDecoder().decode(fileContent);
if (fileContentString.charCodeAt(0) === 0xfeff) {
fileContentString = fileContentString.slice(1);
}

const languageId = await getLanguageId(file);

markdownContent += `## File: ${relativePath}\n`;
markdownContent += '```' + languageId + '\n';
markdownContent += fileContent + '\n';
markdownContent += fileContentString + '\n';
markdownContent += '```\n\n';
}

Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"module": "Node16",
"target": "ES2022",
"outDir": "out",
"lib": [
"ES2022"
],
"lib": ["ES2022", "DOM"],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
Expand Down

0 comments on commit 8051c06

Please sign in to comment.