Skip to content

Commit

Permalink
refactor: use prettier to format all file
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-p committed Nov 19, 2020
1 parent e4bf3a8 commit f7e12a8
Show file tree
Hide file tree
Showing 71 changed files with 3,449 additions and 2,767 deletions.
10 changes: 5 additions & 5 deletions config/paths.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const path = require("path");

module.exports = {
babelConfig: path.resolve(__dirname, './babel.config.js'),
mainjs: path.resolve(__dirname, '../src/extension.ts'),
build: path.resolve(__dirname, '../outExtension'),
src: path.resolve(__dirname, '../src'),
babelConfig: path.resolve(__dirname, "./babel.config.js"),
mainjs: path.resolve(__dirname, "../src/extension.ts"),
build: path.resolve(__dirname, "../outExtension"),
src: path.resolve(__dirname, "../src"),
config: path.resolve(__dirname),
};
22 changes: 11 additions & 11 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
const paths = require('./paths');
const paths = require("./paths");
module.exports = {
mode: 'development',
target: 'node',
mode: "development",
target: "node",
node: {
__dirname: false,
__filename: false,
},
entry: paths.mainjs,
output: {
path: paths.build,
filename: 'extension.js',
libraryTarget: 'commonjs2'
filename: "extension.js",
libraryTarget: "commonjs2",
},
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
},
// loader
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
loader: "ts-loader",
},
],
},
resolve: {
extensions: ['.ts', '.js', '.json']
extensions: [".ts", ".js", ".json"],
},
plugins: [],
devtool: 'source-map'
devtool: "source-map",
};
12 changes: 6 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.NODE_ENV = 'production';
const utils = require('../utils/utils');
const paths = require('../config/paths');
const config = require('../config/webpack.config');
const { buildSources } = utils
process.env.NODE_ENV = "production";
const utils = require("../utils/utils");
const paths = require("../config/paths");
const config = require("../config/webpack.config");
const { buildSources } = utils;

buildSources(config, paths.build)
buildSources(config, paths.build);
12 changes: 6 additions & 6 deletions scripts/watch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.NODE_ENV = 'development';
const utils = require('../utils/utils');
const paths = require('../config/paths');
const config = require('../config/webpack.config');
const { watchSources } = utils
process.env.NODE_ENV = "development";
const utils = require("../utils/utils");
const paths = require("../config/paths");
const config = require("../config/webpack.config");
const { watchSources } = utils;

watchSources(config, paths.build)
watchSources(config, paths.build);
89 changes: 55 additions & 34 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
import * as vscode from 'vscode';
import { getDependencyTreeData } from './data-dependencyTree/data-dependencyTree';
import { createView } from './web-dependencyTree/openWebView';
import { postMessageCatchError } from './utils/message/postMessageToWebView';
import { reOpenWebView } from './web-dependencyTree/openWebView';
import { renderTreeView } from './view-dependencyTree/renderTreeView';
import * as vscode from "vscode";
import { getDependencyTreeData } from "./data-dependencyTree/data-dependencyTree";
import { createView } from "./web-dependencyTree/openWebView";
import { postMessageCatchError } from "./utils/message/postMessageToWebView";
import { reOpenWebView } from "./web-dependencyTree/openWebView";
import { renderTreeView } from "./view-dependencyTree/renderTreeView";
import {
MESSAGE_DEPENDENCY_TREE_DATA,
MESSAGE_FOCUS_ON_NODE,
MESSAGE_UPDATE_WEBVIEW
} from './utils/message/messagesKeys';
import * as stringRandom from 'string-random';
MESSAGE_DEPENDENCY_TREE_DATA,
MESSAGE_FOCUS_ON_NODE,
MESSAGE_UPDATE_WEBVIEW,
} from "./utils/message/messagesKeys";
import * as stringRandom from "string-random";

let message = 0;

export const command_createView = vscode.commands.registerCommand('framegraph.createView', () => {
createView();
});
export const command_createView = vscode.commands.registerCommand(
"framegraph.createView",
() => {
createView();
}
);

// export const command_postMessage = vscode.commands.registerCommand('framegraph.postMessage', () => {
// postMessageCatchError({ key: 'postMessageTest', value: message++ });
// });

export const command_focusOnNode = vscode.commands.registerCommand('framegraph.focusOnNode', (fileName, fileData) => {
postMessageCatchError({ key: MESSAGE_FOCUS_ON_NODE, value: { fileName, fileData } });
});
export const command_reOpenView = vscode.commands.registerCommand('framegraph.reOpenView', (fileName, fileData) => {
reOpenWebView(global.dependencyTreeData);
});
export const command_refreshFile = vscode.commands.registerCommand('framegraph.refreshFile', (fileName, fileData) => {
// no catch error may be webview is closed
let postMessage = false;
if (global.webViewPanel) {
postMessage = true;
postMessageCatchError({ key: MESSAGE_UPDATE_WEBVIEW, value: stringRandom() });
}
global.dependencyTreeData = getDependencyTreeData(postMessage);
renderTreeView(global.dependencyTreeData);
if (global.webViewPanel) {
postMessageCatchError({ key: MESSAGE_DEPENDENCY_TREE_DATA, value: global.dependencyTreeData });
}
});
export const allCommands = [ command_createView, command_reOpenView ];
export const command_focusOnNode = vscode.commands.registerCommand(
"framegraph.focusOnNode",
(fileName, fileData) => {
postMessageCatchError({
key: MESSAGE_FOCUS_ON_NODE,
value: { fileName, fileData },
});
}
);
export const command_reOpenView = vscode.commands.registerCommand(
"framegraph.reOpenView",
(fileName, fileData) => {
reOpenWebView(global.dependencyTreeData);
}
);
export const command_refreshFile = vscode.commands.registerCommand(
"framegraph.refreshFile",
(fileName, fileData) => {
// no catch error may be webview is closed
let postMessage = false;
if (global.webViewPanel) {
postMessage = true;
postMessageCatchError({
key: MESSAGE_UPDATE_WEBVIEW,
value: stringRandom(),
});
}
global.dependencyTreeData = getDependencyTreeData(postMessage);
renderTreeView(global.dependencyTreeData);
if (global.webViewPanel) {
postMessageCatchError({
key: MESSAGE_DEPENDENCY_TREE_DATA,
value: global.dependencyTreeData,
});
}
}
);
export const allCommands = [command_createView, command_reOpenView];
35 changes: 20 additions & 15 deletions src/data-dependencyTree/data-dependencyTree.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import * as path from 'path';
import { DependencyTreeData } from './dependencyTreeData';
import * as dependencyTree from 'dependency-tree';
import { analysesFile } from '../fileAnalysis/javascript/javascriptAnalysis';
import * as path from "path";
import { DependencyTreeData } from "./dependencyTreeData";
import * as dependencyTree from "dependency-tree";
import { analysesFile } from "../fileAnalysis/javascript/javascriptAnalysis";

import {
statusMsgGetFolderPath,
statusMsgGetPackageJsonPath,
statusMsgGetEntryFile,
statusMsgGetDependencyData,
statusMsgGetDependencyProcessData
} from '../utils/message/messages';
statusMsgGetDependencyProcessData,
} from "../utils/message/messages";

import {
getPackageJsonPath,
getMainFilePath,
getDependencyTree,
processTreeData,
getCurrentFolderPath
} from './dependencyTreeMethods';
getCurrentFolderPath,
} from "./dependencyTreeMethods";

import { getEntryFileRelativePath } from '../utils/config';
import { onError } from '../utils/error/onError';
import { getEntryFileRelativePath } from "../utils/config";
import { onError } from "../utils/error/onError";
import {
NO_DEPENDENCY,
NO_FOLDER,
NO_PACKAGE_JSON,
NO_MAIN_FILE,
GET_DEPENDENCY_TREE_FAIL
} from '../utils/error/errorKey';
GET_DEPENDENCY_TREE_FAIL,
} from "../utils/error/errorKey";

import { pathExists } from '../utils/utils';
import { pathExists } from "../utils/utils";

export const getDependencyTreeData = (postMessage?: boolean): DependencyTreeData | undefined => {
export const getDependencyTreeData = (
postMessage?: boolean
): DependencyTreeData | undefined => {
// find folder Path catch path sendStatus
const folderPath = getCurrentFolderPath();
if (!folderPath || !pathExists(folderPath)) {
Expand Down Expand Up @@ -61,7 +63,10 @@ export const getDependencyTreeData = (postMessage?: boolean): DependencyTreeData
}
postMessage ? statusMsgGetEntryFile.postSuccess() : null;

const { dependencyTree: processedTreeData, dependencyHash } = analysesFile(path.join(folderPath, mainFilePath), folderPath);
const { dependencyTree: processedTreeData, dependencyHash } = analysesFile(
path.join(folderPath, mainFilePath),
folderPath
);
// const dependencyTreeData = getDependencyTree(mainFilePath, folderPath);
// if (!dependencyTreeData || !Object.keys(dependencyTreeData as dependencyTree.DependencyObj).length) {
// onError(GET_DEPENDENCY_TREE_FAIL);
Expand Down
48 changes: 24 additions & 24 deletions src/data-dependencyTree/dependencyTreeData.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { namedTypes } from 'ast-types/gen/namedTypes';
import { namedTypes } from "ast-types/gen/namedTypes";
export interface FileInformation {
introduction?: string;
description?: string;
introduction?: string;
description?: string;
}
export interface Param {
name: string;
type?: string;
name: string;
type?: string;
}
export interface FunctionInformation {
comment?: string;
export: boolean;
code: string;
loc: namedTypes.SourceLocation | null | undefined;
params: Param[] | [];
arrowFunction: boolean;
kind: 'const' | 'let' | 'function' | 'var';
name: string;
comment?: string;
export: boolean;
code: string;
loc: namedTypes.SourceLocation | null | undefined;
params: Param[] | [];
arrowFunction: boolean;
kind: "const" | "let" | "function" | "var";
name: string;
}
export interface DependencyTreeData {
name: string;
name: string;
fileDescription: FileInformation;
circularStructure?:true;
type: string;
lines: number | undefined;
analysed: boolean;
functions: FunctionInformation[] | [];
extension: string;
absolutePath: string;
relativePath: string;
ancestors: string[];
children: Array<DependencyTreeData>;
circularStructure?: true;
type: string;
lines: number | undefined;
analysed: boolean;
functions: FunctionInformation[] | [];
extension: string;
absolutePath: string;
relativePath: string;
ancestors: string[];
children: Array<DependencyTreeData>;
}
Loading

0 comments on commit f7e12a8

Please sign in to comment.