Skip to content

Commit e88dbc2

Browse files
committed
Initial
0 parents  commit e88dbc2

15 files changed

+365
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
out
2+
node_modules
3+
.vscode-test/
4+
*.vsix

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"ms-vscode.vscode-typescript-tslint-plugin"
6+
]
7+
}

.vscode/launch.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [{
8+
"name": "Run Extension",
9+
"type": "extensionHost",
10+
"request": "launch",
11+
"runtimeExecutable": "${execPath}",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "npm: watch"
19+
},
20+
{
21+
"name": "Extension Tests",
22+
"type": "extensionHost",
23+
"request": "launch",
24+
"runtimeExecutable": "${execPath}",
25+
"args": [
26+
"--extensionDevelopmentPath=${workspaceFolder}",
27+
"--extensionTestsPath=${workspaceFolder}/out/test"
28+
],
29+
"outFiles": [
30+
"${workspaceFolder}/out/test/**/*.js"
31+
],
32+
"preLaunchTask": "npm: watch"
33+
}
34+
]
35+
}

.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off"
11+
}

.vscode/tasks.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}

.vscodeignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
src/**
5+
.gitignore
6+
vsc-extension-quickstart.md
7+
**/tsconfig.json
8+
**/tslint.json
9+
**/*.map
10+
**/*.ts

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "flutter-stateful-widget-generator" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# TO USE
2+
3+
```
4+
CMD + Shift + P
5+
```
6+
```
7+
Flutter Stateful Widget Generator : Create Stateful Widget
8+
```
9+
```
10+
Input the name of your widget,
11+
```

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "flutter-stateful-widget-generator",
3+
"displayName": "Flutter Stateful Widget Generator",
4+
"description": "Generates a stateful widget into a new file.",
5+
"version": "0.0.1",
6+
"publisher": "yum650350",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/yum650350/flutter-stateful-widget-generator.git"
10+
},
11+
"engines": {
12+
"vscode": "^1.32.0"
13+
},
14+
"categories": [
15+
"Other"
16+
],
17+
"activationEvents": [
18+
"onCommand:extension.create"
19+
],
20+
"main": "./out/extension.js",
21+
"contributes": {
22+
"commands": [{
23+
"command": "extension.create",
24+
"title": "Flutter Stateful Widget Generator : Create Stateful Widget"
25+
}]
26+
},
27+
"scripts": {
28+
"vscode:prepublish": "npm run compile",
29+
"compile": "tsc -p ./",
30+
"watch": "tsc -watch -p ./",
31+
"postinstall": "node ./node_modules/vscode/bin/install",
32+
"test": "npm run compile && node ./node_modules/vscode/bin/test"
33+
},
34+
"devDependencies": {
35+
"typescript": "^3.3.1",
36+
"vscode": "^1.1.28",
37+
"tslint": "^5.12.1",
38+
"@types/node": "^10.12.21",
39+
"@types/mocha": "^2.2.42"
40+
}
41+
}

src/extension.ts

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// The module 'vscode' contains the VS Code extensibility API
2+
// Import the module and reference it with the alias vscode in your code below
3+
import * as vscode from 'vscode';
4+
import * as path from 'path';
5+
import * as fs from 'fs';
6+
7+
// this method is called when your extension is activated
8+
// your extension is activated the very first time the command is executed
9+
export function activate(context: vscode.ExtensionContext) {
10+
11+
// Use the console to output diagnostic information (console.log) and errors (console.error)
12+
// This line of code will only be executed once when your extension is activated
13+
console.log('Congratulations, your extension "flutter-stateful-widget-generator" is now active!');
14+
15+
// The command has been defined in the package.json file
16+
// Now provide the implementation of the command with registerCommand
17+
// The commandId parameter must match the command field in package.json
18+
let disposable = vscode.commands.registerCommand('extension.create', () => {
19+
// The code you place here will be executed every time your command is executed
20+
21+
// Display a message box to the user
22+
var options: vscode.InputBoxOptions = {
23+
prompt: "Name the widget",
24+
placeHolder: "ex: MyWidget"
25+
};
26+
vscode.window.showInputBox(options).then((x) => {
27+
if (x !== undefined && String(x) !== '') {
28+
var dialogoptions: vscode.OpenDialogOptions = {
29+
canSelectFiles: false,
30+
canSelectFolders: true,
31+
canSelectMany: false,
32+
openLabel: 'Create here'
33+
};
34+
vscode.window.showOpenDialog(dialogoptions).then((y) => {
35+
if (y !== undefined && String(y) !== '') {
36+
var folderPath = y[0];
37+
var widgetName = String(x);
38+
var i: number;
39+
var fileName = '';
40+
for (i = 0; i < x.length; i++) {
41+
var t = x[i];
42+
if (i === 0) {
43+
t = x[i].toLocaleLowerCase();
44+
}
45+
fileName += t;
46+
}
47+
fileName += '.dart';
48+
var fullPath = path.join(folderPath.toString(), fileName);
49+
var theu = vscode.Uri.parse(fullPath);
50+
fs.exists(theu.fsPath, (exists) => {
51+
if (exists) {
52+
vscode.window.showErrorMessage(`Widget Generator: File Exists -> ${fileName} `);
53+
} else {
54+
var content =
55+
`
56+
import 'package:flutter/material.dart';
57+
58+
class ${widgetName} extends StatefulWidget {
59+
@override
60+
${widgetName}View createState() {
61+
return ${widgetName}View();
62+
}
63+
}
64+
65+
class ${widgetName}View extends ${widgetName}State {
66+
@override
67+
Widget build(BuildContext context) {
68+
// TODO: implement build
69+
return Text('${widgetName}');
70+
}
71+
}
72+
73+
abstract class ${widgetName}State extends State<${widgetName}> {
74+
// TODO: implement state
75+
}
76+
`;
77+
78+
fs.writeFile(theu.fsPath, content, function (err) {
79+
if (err) {
80+
console.log(err);
81+
}
82+
else {
83+
console.log('Write operation complete.');
84+
vscode.workspace.openTextDocument(theu.fsPath).then(doc => {
85+
vscode.window.showTextDocument(doc);
86+
});
87+
}
88+
});
89+
}
90+
});
91+
}
92+
});
93+
}
94+
});
95+
});
96+
97+
context.subscriptions.push(disposable);
98+
}
99+
100+
// this method is called when your extension is deactivated
101+
export function deactivate() { }

src/test/extension.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Note: This example test is leveraging the Mocha test framework.
3+
// Please refer to their documentation on https://mochajs.org/ for help.
4+
//
5+
6+
// The module 'assert' provides assertion methods from node
7+
import * as assert from 'assert';
8+
9+
// You can import and use all API from the 'vscode' module
10+
// as well as import your extension to test it
11+
// import * as vscode from 'vscode';
12+
// import * as myExtension from '../extension';
13+
14+
// Defines a Mocha test suite to group tests of similar kind together
15+
suite("Extension Tests", function () {
16+
17+
// Defines a Mocha unit test
18+
test("Something 1", function() {
19+
assert.equal(-1, [1, 2, 3].indexOf(5));
20+
assert.equal(-1, [1, 2, 3].indexOf(0));
21+
});
22+
});

src/test/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3+
//
4+
// This file is providing the test runner to use when running extension tests.
5+
// By default the test runner in use is Mocha based.
6+
//
7+
// You can provide your own test runner if you want to override it by exporting
8+
// a function run(testsRoot: string, clb: (error: Error, failures?: number) => void): void
9+
// that the extension host can call to run the tests. The test runner is expected to use console.log
10+
// to report the results back to the caller. When the tests are finished, return
11+
// a possible error to the callback or null if none.
12+
13+
import * as testRunner from 'vscode/lib/testrunner';
14+
15+
// You can directly control Mocha options by configuring the test runner below
16+
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options
17+
// for more info
18+
testRunner.configure({
19+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
20+
useColors: true // colored output from test results
21+
});
22+
23+
module.exports = testRunner;

tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"outDir": "out",
6+
"lib": [
7+
"es6"
8+
],
9+
"sourceMap": true,
10+
"rootDir": "src",
11+
"strict": true /* enable all strict type-checking options */
12+
/* Additional Checks */
13+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
14+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
15+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
16+
},
17+
"exclude": [
18+
"node_modules",
19+
".vscode-test"
20+
]
21+
}

tslint.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"rules": {
3+
"no-string-throw": true,
4+
"no-unused-expression": true,
5+
"no-duplicate-variable": true,
6+
"curly": true,
7+
"class-name": true,
8+
"semicolon": [
9+
true,
10+
"always"
11+
],
12+
"triple-equals": true
13+
},
14+
"defaultSeverity": "warning"
15+
}

vsc-extension-quickstart.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Welcome to your VS Code Extension
2+
3+
## What's in the folder
4+
5+
* This folder contains all of the files necessary for your extension.
6+
* `package.json` - this is the manifest file in which you declare your extension and command.
7+
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
8+
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
9+
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
10+
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
11+
12+
## Get up and running straight away
13+
14+
* Press `F5` to open a new window with your extension loaded.
15+
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
16+
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
17+
* Find output from your extension in the debug console.
18+
19+
## Make changes
20+
21+
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
22+
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
23+
24+
## Explore the API
25+
26+
* You can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`.
27+
28+
## Run tests
29+
30+
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
31+
* Press `F5` to run the tests in a new window with your extension loaded.
32+
* See the output of the test result in the debug console.
33+
* Make changes to `test/extension.test.ts` or create new test files inside the `test` folder.
34+
* By convention, the test runner will only consider files matching the name pattern `**.test.ts`.
35+
* You can create folders inside the `test` folder to structure your tests any way you want.

0 commit comments

Comments
 (0)