Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vscode plugin cannot parse flags correctly #36

Merged
merged 1 commit into from
Nov 12, 2022
Merged
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
20 changes: 20 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ jobs:
with:
version: latest
args: release --skip-publish --rm-dist

pluginBuild:
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Check out code
uses: actions/checkout@v3.0.0
- name: Set up Go 1.18
uses: actions/setup-go@v3
with:
go-version: 1.18
id: go
- name: Build tool
run: |
make copy
- name: Test
run: |
cd plugins/vscode/yaml-readme && npm install && npm run pretest && node ./test/suite/extension.test.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ plugins/vscode/yaml-readme/node_modules/
*.vsix
*/**/.DS_Store
.DS_Store
.vscode-test
26 changes: 26 additions & 0 deletions plugins/vscode/yaml-readme/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function generateCommand(metadata, wf, filename) {
metadata = metadata.replace("#!yaml-readme ", "")

let commands = ["yaml-readme", "-t", filename]
let output = ""
const items = metadata.split(" ")

for (var i = 0; i < items.length; i++) {
const item = items[i]
if (item == "-p") {
commands.push("-p", wf + "/" + items[++i])
} else if (item == "--output") {
output = wf + "/" + items[++i]
} else if (item == "--group-by") {
commands.push("--group-by", items[++i])
} else if (item == "--sort-by") {
commands.push("--sort-by", items[++i])
}
}

return [commands.join(" "), output]
}

module.exports = {
generateCommand
}
23 changes: 6 additions & 17 deletions plugins/vscode/yaml-readme/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const vscode = require('vscode');
const cp = require('child_process');
const fs = require('fs');
const cmd = require('./command');

function getFirstLine(filePath) {
const data = fs.readFileSync(filePath);
Expand Down Expand Up @@ -30,28 +31,16 @@ function activate(context) {

let filename = vscode.window.activeTextEditor.document.fileName
let metadata = getFirstLine(filename)
vscode.window.showInformationMessage(metadata + "===" + metadata.startsWith("#!yaml-readme"));
// vscode.window.showInformationMessage(metadata + "===" + metadata.startsWith("#!yaml-readme"));
if (metadata.startsWith("#!yaml-readme")) {
metadata = metadata.replace("#!yaml-readme ", "")
let command = cmd.generateCommand(metadata, wf, filename)

let pattern = ""
let output = ""
const items = metadata.split(" ")
for (var i = 0; i < items.length; i++) {
const item = items[i]
if (item == "-p") {
pattern = wf + "/" + items[++i]
} else if (item == "--output") {
output = wf + "/" + items[++i]
}
}

vscode.window.showInformationMessage(`yaml-readme -p "${pattern}" -t "${filename}" > ${output}`)
cp.exec(`yaml-readme -p "${pattern}" -t "${filename}" > ${output}`, (err) => {
// vscode.window.showInformationMessage(`yaml-readme -p "${pattern}" -t "${filename}" > ${output}`)
cp.exec(`${command[0]} > ${command[1]}`, (err) => {
if (err) {
console.log('error: ' + err);
}
vscode.commands.executeCommand("markdown.showPreviewToSide", vscode.Uri.file(`${output}`));
vscode.commands.executeCommand("markdown.showPreviewToSide", vscode.Uri.file(`${command[1]}`));
});
}
} else {
Expand Down
15 changes: 5 additions & 10 deletions plugins/vscode/yaml-readme/test/suite/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ const assert = require('assert');

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
const vscode = require('vscode');
// const myExtension = require('../extension');
// const vscode = require('vscode');
const myExtension = require('../../command');

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
let cmd = myExtension.generateCommand("#!yaml-readme -p data/*.yaml --output README.md --group-by kind --sort-by kind","wf","filename")
assert.equal(cmd[0], "yaml-readme -t filename -p wf/data/*.yaml --group-by kind --sort-by kind")
assert.equal(cmd[1], "wf/README.md")