Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaDhruv committed Mar 12, 2021
2 parents 076da1b + 9ac1b34 commit 4b5ea39
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
Binary file modified media/demo/create-parent-set.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.

26 changes: 13 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createFile, createFolder, isParentSetExist } from './resources/utils/fi
import { getParentName, getParentPath, saveParentSet } from './resources/utils/storage';
import { addSetToParent, getParentSetMiddlewareCode, getParentSetReducerCode, getParentSetStateCode } from './resources/gen/parent_set';
import * as fs from 'fs';
import * as path from 'path';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand All @@ -17,7 +18,7 @@ export function activate(context: vscode.ExtensionContext): void {
// Create State Command Registering
let createState = vscode.commands.registerCommand('flutter-redux-gen.createState', (args) => {

let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
if (isParentSetExist(context)) {
Expand Down Expand Up @@ -47,7 +48,7 @@ export function activate(context: vscode.ExtensionContext): void {
// Create State Command Registering
let createReducer = vscode.commands.registerCommand('flutter-redux-gen.createReducer', (args) => {

let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
if (isParentSetExist(context)) {
Expand Down Expand Up @@ -77,7 +78,7 @@ export function activate(context: vscode.ExtensionContext): void {
// Create State Command Registering
let createMiddleware = vscode.commands.registerCommand('flutter-redux-gen.createMiddleware', (args) => {

let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
if (isParentSetExist(context)) {
Expand Down Expand Up @@ -107,7 +108,7 @@ export function activate(context: vscode.ExtensionContext): void {
// Create State Command Registering
let createAction = vscode.commands.registerCommand('flutter-redux-gen.createAction', (args) => {

let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
if (isParentSetExist(context)) {
Expand Down Expand Up @@ -137,7 +138,7 @@ export function activate(context: vscode.ExtensionContext): void {
// Create Redux Set Command Registering
let createReduxSet = vscode.commands.registerCommand('flutter-redux-gen.createReduxSet', (args) => {

let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
nameField.placeholder = CREATE_ACTION_PLACE_HOLDER;
Expand Down Expand Up @@ -172,13 +173,12 @@ export function activate(context: vscode.ExtensionContext): void {

context.subscriptions.push(createReduxSet);

// Create Redux Set Command Registering
// Create Redux Parent Set Command Registering
let createParentSet = vscode.commands.registerCommand('flutter-redux-gen.createParentSet', (args) => {

if (context.workspaceState.get("PARENT_PATH") && fs.existsSync(context.workspaceState.get("PARENT_PATH") as string)) {
if (isParentSetExist(context)) {
vscode.window.showErrorMessage('Parent Set Already Exist');
} else {
let focusedFilePath = getFilePath(args.path);
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
nameField.placeholder = CREATE_ACTION_PLACE_HOLDER;
Expand All @@ -194,10 +194,10 @@ export function activate(context: vscode.ExtensionContext): void {

var isCreated = createFolder(focusedFilePath, 'store');
if (isCreated) {
createFile(focusedFilePath + "/store", name, REDUCER_EXTENSION, getParentSetReducerCode, false);
createFile(focusedFilePath + "/store", name, MIDDLEWARE_EXTENSION, getParentSetMiddlewareCode, false);
createFile(focusedFilePath + "/store", name, STATE_EXTENSION, getParentSetStateCode, false);
saveParentSet(focusedFilePath + "/store", name, context);
createFile(path.join(focusedFilePath, 'store'), name, REDUCER_EXTENSION, getParentSetReducerCode, false);
createFile(path.join(focusedFilePath, 'store'), name, MIDDLEWARE_EXTENSION, getParentSetMiddlewareCode, false);
createFile(path.join(focusedFilePath, 'store'), name, STATE_EXTENSION, getParentSetStateCode, false);
saveParentSet(path.join(focusedFilePath, 'store'), name, context);
vscode.window.showInformationMessage(name + ' Parent Set Created.');
}
nameField.validationMessage = '';
Expand Down
7 changes: 4 additions & 3 deletions src/resources/utils/file-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { clearParentSet } from './storage';

function _createFile(fPath: string, name: string, extention: string, getGenCode: Function, showInfo: boolean) {
const pathWithFileName = fPath + '/' + name.toLocaleLowerCase() + extention;
const pathWithFileName = path.join(fPath, name.toLocaleLowerCase() + extention);
fs.writeFile(pathWithFileName, getGenCode(name), err => {
if (err) {
vscode.window.showInformationMessage('Please check your path. Otherwise file a issue in Git Repo. Let me help.');
Expand All @@ -14,8 +15,8 @@ function _createFile(fPath: string, name: string, extention: string, getGenCode:
}

function _createFolder(fPath: string, name: string): boolean {
if (!fs.existsSync(fPath + "/" + name)) {
fs.mkdirSync(fPath + "/" + name);
if (!fs.existsSync(path.join(fPath, name))) {
fs.mkdirSync(path.join(fPath, name));
return true;
} else {
vscode.window.showErrorMessage('Folder Already Exist');
Expand Down
12 changes: 5 additions & 7 deletions src/resources/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';

function _getFormattedStateName(name: string) {
return name.split('_').map(word => word[0].toLocaleUpperCase() + word.substring(1)).join('');
Expand All @@ -8,15 +9,12 @@ function _getFormattedReducerName(name: string) {
return name.split('_').map(word => word[0].toLocaleLowerCase() + word.substring(1)).join('');
}

function _getFilePath(path: string) {
const syncPath = fs.statSync(path);
function _getFilePath(fPath: string) {
const syncPath = fs.statSync(fPath);
if (syncPath.isFile()) {
var paths = path.split('/');
paths.pop();
return paths.join('/');
return path.dirname(fPath);
}
return path;

return fPath;
}

export var getFormattedStateName = _getFormattedStateName;
Expand Down

0 comments on commit 4b5ea39

Please sign in to comment.