Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rumengkai1 committed Jun 14, 2022
0 parents commit eaf7d4d
Show file tree
Hide file tree
Showing 21 changed files with 1,836 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
out
dist
node_modules
.vscode-test/
*.vsix
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": 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"
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
10 changes: 10 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-engines true
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "fecg" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1 align="center">feco 🚀</h1>

## 关于

> Front end code generator

## 使用
```sh
npm install fecg -g
```
### 在项目工程文件夹右击,点击 `FE Code Generator`,选择要生成的页面类型

62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "fecg",
"displayName": "fecg",
"description": "Front end code generator",
"publisher": "rumengkai",
"version": "0.0.1",
"engines": {
"vscode": "^1.68.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:fecg.cg-page"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "fecg.cg-page",
"title": "FE Code Generator"
}
],
"menus": {
"explorer/context": [
{
"command": "fecg.cg-page",
"group": "navigation",
"when": "explorerResourceIsFolder"
}
]
},
"keybindings": [
{
"command": "fecg.cg-page",
"mac": "cmd+Shift+C",
"key": "ctrl+Shift+C"
}
]
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.68.0",
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.1",
"@types/node": "16.x",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^8.16.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typescript": "^4.7.2",
"@vscode/test-electron": "^2.1.3"
}
}
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const pageTypes = ["table: 基础列表页面", "form: 基础form表单页面"];
59 changes: 59 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import { pageTypes } from "./config";
import runScript from "./terminal/runScript";

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "fecg" is now active!');

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand("fecg.cg-page", (node) => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
let path = "";
if (node) {
path = node.path;
} else {
path = (vscode.workspace.workspaceFolders as any)[0].uri.path + "/src"; // 文件夹根路径
}
vscode.window
.showQuickPick(pageTypes, {
canPickMany: false,
ignoreFocusOut: true,
placeHolder: "请选择需要生成的页面类型",
})
.then(function (type) {
if (type) {
createPage(type.split(":")[0], path);
}
});
});

context.subscriptions.push(disposable);
}
//
function createPage(type: string, path: string) {
vscode.window
.showInputBox({
ignoreFocusOut: true,
placeHolder: "请输入名称", // 在输入框内的提示信息
prompt: "用于文件名称、文件夹名称", // 在输入框下方的提示信息
})
.then(function (name) {
if (!name) {
return;
}
const res = runScript("fe-terminal", path!, `fe ${type} ${name}`);
vscode.window.showInformationMessage("success");
});
}

// this method is called when your extension is deactivated
export function deactivate() {}
30 changes: 30 additions & 0 deletions src/terminal/runScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as vscode from "vscode";
import { Terminal, TerminalOptions } from "vscode";
import { mkdir } from "../utils";
// 运行script命令
export default function runScript(
terminalName: string,
cwd: string,
script: string
) {
if (!script) {
return;
}
mkdir(cwd);
const { terminals } = vscode.window;
let terminal: Terminal | undefined = terminals.find(({ name }) => {
return name === terminalName;
});
if (!terminal) {
const terminalOptions: TerminalOptions = { cwd, name: terminalName };
terminal = vscode.window.createTerminal(terminalOptions);
}
try {
terminal.show();
terminal.sendText(`cd ${cwd}`);
terminal.sendText(script);
return true;
} catch (error) {
return error;
}
}
23 changes: 23 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
15 changes: 15 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

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));
});
});
38 changes: 38 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});

const testsRoot = path.resolve(__dirname, '..');

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
9 changes: 9 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as fs from "fs";
import * as path from "path";

export const mkdir = (dir: string) => {
if (!fs.existsSync(dir)) {
mkdir(path.dirname(dir));
fs.mkdirSync(dir);
}
};
Loading

0 comments on commit eaf7d4d

Please sign in to comment.