Skip to content
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
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registry = https://registry.npm.taobao.org
registry = https://registry.npmmirror.com/
36 changes: 28 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"build": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"build": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"stylelint.validate": [
"css",
"less",
"scss",
"vue"
],
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.exclude": {
"build": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"build": true // set this to false to include "out" folder in search results
},
"typescript.tsdk": "node_modules/typescript/lib",
}
23 changes: 3 additions & 20 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,7 @@ vsc-extension-quickstart.md
**/*.ts
*.lock
*.vsix
webpack.config.js
.lowcoderc
esbuild.js

node_modules
!node_modules/prettier
!node_modules/copy-paste
!node_modules/iconv-lite
!node_modules/safer-buffer
!node_modules/typescript-json-schema
!node_modules/glob
!node_modules/fs.realpath
!node_modules/minimatch
!node_modules/brace-expansion
!node_modules/concat-map
!node_modules/balanced-match
!node_modules/inherits
!node_modules/path-is-absolute
!node_modules/inflight
!node_modules/wrappy
!node_modules/once
!node_modules/json-stable-stringify
!node_modules/typescript
node_modules
18 changes: 18 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path');
const fs = require('fs-extra');
const { build } = require('esbuild');

fs.removeSync(path.join(__dirname, 'build'));
const entryFile = path.join(__dirname, 'src', 'extension.ts');
build({
entryPoints: [entryFile],
bundle: true,
minify: true,
// only needed if you have dependencies
external: ['vscode'],
platform: 'node',
format: 'cjs',
outfile: path.join(__dirname, 'build', 'extension.js'),
write: true,
logLevel: 'error',
});
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
"displayName": "lowcode",
"description": "lowcode tool, support ChatGPT and other LLM",
"author": "wjkang <ruoxieme@gmail.com>",
"version": "1.8.9",
"version": "1.9.0",
"icon": "asset/icon.png",
"publisher": "wjkang",
"repository": "https://github.com/lowcoding/lowcode-vscode",
"main": "./build/extension.js",
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "webpack --mode production",
"compile": "node ./esbuild.js",
"compile:tsc": "tsc -p ./",
"dev": "yarn --cwd \"webview-react\" dev",
"build": "yarn --cwd \"webview-react\" build",
"lint": "eslint src --ext ts",
"watch": "webpack --mode development",
"pretest": "yarn run compile:tsc",
"test:js": "node ./build/test/runTest.js",
"test": "node ./build/test/runTest.js"
Expand Down Expand Up @@ -271,7 +270,6 @@
}
},
"devDependencies": {
"@types/copy-paste": "^1.1.30",
"@types/debug": "^4.1.5",
"@types/ejs": "^3.0.4",
"@types/fs-extra": "^9.0.1",
Expand All @@ -294,15 +292,13 @@
"prettier": "^2.2.1",
"ts-loader": "^8.0.3",
"typescript": "^4.3.5",
"vscode-test": "^1.3.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
"vscode-test": "^1.3.0"
},
"dependencies": {
"axios": "^0.19.2",
"copy-paste": "^1.3.0",
"directory-tree": "^2.2.4",
"ejs": "^3.1.3",
"esbuild": "^0.24.2",
"execa": "^4.0.3",
"fs-extra": "^9.0.1",
"generate-schema": "^2.6.0",
Expand Down
19 changes: 11 additions & 8 deletions src/commands/addSnippet.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { getClipboardText, getSelectedText } from '../utils/editor';
import { showWebView } from '../webview';

export const createOrShowWebview = (context: vscode.ExtensionContext) => {
context.subscriptions.push(
vscode.commands.registerTextEditorCommand('lowcode.addSnippet', () => {
const content = getSelectedText() || getClipboardText();
showWebView({
key: 'main',
task: { task: 'addSnippets', data: { content } },
});
}),
vscode.commands.registerTextEditorCommand(
'lowcode.addSnippet',
async () => {
const content = getSelectedText() || (await getClipboardText());
showWebView({
key: 'main',
task: { task: 'addSnippets', data: { content } },
});
},
),
vscode.commands.registerCommand('lowcode.addPromptTemplate', () => {
showWebView({
key: 'main',
Expand Down
8 changes: 4 additions & 4 deletions src/commands/chatGPT.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { commands } from '../utils/env';
import { hideChatGPTView, showChatGPTView } from '../webview';
import { getClipboardText, getSelectedText } from '../utils/editor';
Expand All @@ -19,11 +19,11 @@ export const registerChatGPTCommand = (context: vscode.ExtensionContext) => {
'lowcode',
);
}),
vscode.commands.registerCommand('lowcode.askChatGPT', () => {
vscode.commands.registerCommand('lowcode.askChatGPT', async () => {
showChatGPTView({
task: {
task: 'askChatGPT',
data: getSelectedText() || getClipboardText(),
data: getSelectedText() || (await getClipboardText()),
},
});
}),
Expand All @@ -49,7 +49,7 @@ export const registerChatGPTCommand = (context: vscode.ExtensionContext) => {
const template = templateList.find((s) => s.name === templateResult);
const model = {
rawSelectedText: getSelectedText() || '',
rawClipboardText: getClipboardText() || '',
rawClipboardText: await getClipboardText(),
};
const code = compileEjs(
template?.commandPrompt || template!.preview.chatGPT?.commandPrompt!,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { commands } from '../utils/env';
import { hideChatGPTView, showChatGPTView, showWebView } from '../webview';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/createOrShowWebview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { formatPath } from '../utils/platform';
import { showWebView } from '../webview';

Expand Down
4 changes: 2 additions & 2 deletions src/commands/generateCode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { genCodeByYapi } from '../genCode/genCodeByYapi';
import { genCodeByJson } from '../genCode/genCodeByJson';
import { genCodeByTypescript } from '../genCode/genCodeByTypescript';
Expand All @@ -12,7 +12,7 @@ export const generateCode = (context: vscode.ExtensionContext) => {
vscode.commands.registerTextEditorCommand(
'lowcode.generateCode',
async () => {
const rawClipboardText = getClipboardText();
const rawClipboardText = await getClipboardText();
let clipboardText = rawClipboardText.trim();

clipboardText = JSON.stringify(jsonParse(clipboardText));
Expand Down
7 changes: 3 additions & 4 deletions src/commands/openSnippet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from 'vscode';
import { TextEditor, TextEditorEdit } from 'vscode';
import vscode, { TextEditor, TextEditorEdit } from 'vscode';
import { getClipboardText, pasteToEditor } from '../utils/editor';
import { compile } from '../utils/ejs';
import { jsonIsValid, jsonParse } from '../utils/json';
Expand All @@ -9,11 +8,11 @@ export const openSnippet = (context: vscode.ExtensionContext) => {
context.subscriptions.push(
vscode.commands.registerTextEditorCommand(
'lowcode.openSnippetByWebview',
(textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => {
async (textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => {
const name = args[0];
const template = args[1];

const rawClipboardText = getClipboardText();
const rawClipboardText = await getClipboardText();
let clipboardText = rawClipboardText.trim();
clipboardText = JSON.stringify(jsonParse(clipboardText));

Expand Down
2 changes: 1 addition & 1 deletion src/commands/registerCompletion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { compile as compileEjs } from '../utils/ejs';
import { getSnippets } from '../utils/materials';

Expand Down
6 changes: 3 additions & 3 deletions src/commands/runSnippetScript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs-extra';
import vscode from 'vscode';
import path from 'path';
import fs from 'fs-extra';
import { getSnippets } from '../utils/materials';
import { getEnv, rootPath } from '../utils/vscodeEnv';
import { getInnerLibs } from '../utils/lib';
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import vscode from 'vscode';
import { generateCode } from './commands/generateCode';
import { createOrShowWebview } from './commands/createOrShowWebview';
import { createOrShowWebview as createOrShowAddSnippetWebview } from './commands/addSnippet';
Expand Down
4 changes: 2 additions & 2 deletions src/lifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import path from 'path';
import fs from 'fs-extra';
import { window, ExtensionContext } from 'vscode';
import { getSnippets } from './utils/materials';
import { getEnv, rootPath } from './utils/vscodeEnv';
Expand Down
4 changes: 2 additions & 2 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as os from 'os';
import path from 'path';
import os from 'os';

import { runTests } from 'vscode-test';

Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
import path from 'path';
import Mocha from 'mocha';
import glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/lib.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as os from 'os';
import path from 'path';
import os from 'os';
import { compileScaffold, downloadScaffoldFromGit } from '../../utils/scaffold';
import { selectDirectory } from '../../utils/editor';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import path from 'path';
import fs from 'fs-extra';
import { workspace } from 'vscode';
import { getFileContent } from './file';
import { rootPath } from './vscodeEnv';
Expand Down
6 changes: 3 additions & 3 deletions src/utils/download.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import * as path from 'path';
import * as execa from 'execa';
import * as fs from 'fs-extra';
import path from 'path';
import execa from 'execa';
import fs from 'fs-extra';
import { tempDir } from './env';

const tar = require('tar');
Expand Down
11 changes: 8 additions & 3 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as copyPaste from 'copy-paste';
import { OpenDialogOptions, Range, SnippetString, window } from 'vscode';
import { OpenDialogOptions, Range, SnippetString, window, env } from 'vscode';
import { getLastActiveTextEditor } from '../context';

export const getClipboardText = () => copyPaste.paste();
export const getClipboardText = async () => {
let text = '';
try {
text = await env.clipboard.readText();
} catch (e) {}
return text;
};

export const getSelectedText = () => {
const { selection, document } = window.activeTextEditor!;
Expand Down
10 changes: 5 additions & 5 deletions src/utils/ejs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as ejs from 'ejs';
import * as fse from 'fs-extra';
import * as path from 'path';
import * as glob from 'glob';
import * as prettier from 'prettier';
import ejs from 'ejs';
import fse from 'fs-extra';
import path from 'path';
import glob from 'glob';
import prettier from 'prettier';

export type YapiInfo = {
query_path: { path: string };
Expand Down
4 changes: 2 additions & 2 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as os from 'os';
import path from 'path';
import os from 'os';

export const commands = {
openDownloadMaterials: 'lowcode.openDownloadMaterials',
Expand Down
4 changes: 2 additions & 2 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as fs from 'fs';
import path from 'path';
import fs from 'fs';
import { rootPath } from './vscodeEnv';

export const getFileContent = (filePath: string, fullPath = false) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-eval */
import * as path from 'path';
import * as vscode from 'vscode';
import * as fs from 'fs-extra';
import path from 'path';
import vscode from 'vscode';
import fs from 'fs-extra';
import {
blockMaterialsPath,
getEnv,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs-extra';
import * as TJS from 'typescript-json-schema';
import os from 'os';
import path from 'path';
import fs from 'fs-extra';
import TJS from 'typescript-json-schema';
import { compile } from 'json-schema-to-typescript';
import { getConfig } from './config';

Expand Down
Loading