mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2024-11-26 15:32:05 +00:00
WARM-IDE: Add check for invalid project name when creating new project (#1461)
This commit is contained in:
parent
8a7dd4dc3e
commit
7593668066
|
@ -59,7 +59,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#ipt_projName,
|
#ipt_projName,
|
||||||
#tselect_dropdown,
|
#select_dropdown,
|
||||||
.config_form_body vscode-text-field,
|
.config_form_body vscode-text-field,
|
||||||
.config_form_body vscode-text-area {
|
.config_form_body vscode-text-area {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
import fileSystem = require('fs');
|
import fileSystem = require('fs');
|
||||||
import vscode = require('vscode');
|
import vscode = require('vscode');
|
||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
import os = require('os');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -94,3 +95,26 @@ export function CheckIfDirectoryExist(path: string): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkFolderName(folderName: string) {
|
||||||
|
let invalidCharacterArr: string[] = [];
|
||||||
|
var valid = true;
|
||||||
|
|
||||||
|
if (folderName.length > 255) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (os.platform() === 'win32') {
|
||||||
|
invalidCharacterArr = ['\\', '/', ':', '?', '*', '"', '|', '<', '>'];
|
||||||
|
} else if (os.platform() === 'linux' || os.platform() === 'darwin') {
|
||||||
|
invalidCharacterArr = ['/'];
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidCharacterArr.forEach(function (c) {
|
||||||
|
if (folderName.indexOf(c) !== -1) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,12 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { CreateDirectory, CopyFiles } from '../utilities/directoryUtilities';
|
import * as os from 'os';
|
||||||
|
import {
|
||||||
|
CreateDirectory,
|
||||||
|
CopyFiles,
|
||||||
|
checkFolderName,
|
||||||
|
} from '../utilities/directoryUtilities';
|
||||||
import { getUri } from '../utilities/getUri';
|
import { getUri } from '../utilities/getUri';
|
||||||
|
|
||||||
export class NewProjectPanel {
|
export class NewProjectPanel {
|
||||||
|
@ -15,13 +20,11 @@ export class NewProjectPanel {
|
||||||
private readonly _panel: vscode.WebviewPanel;
|
private readonly _panel: vscode.WebviewPanel;
|
||||||
private _disposables: vscode.Disposable[] = [];
|
private _disposables: vscode.Disposable[] = [];
|
||||||
|
|
||||||
static readonly USER_INTPUT_ERR: number = -2;
|
|
||||||
static readonly DIR_EXSITED_ERR: number = -1;
|
|
||||||
static readonly EXCUTION_SUCCESS: number = 0;
|
static readonly EXCUTION_SUCCESS: number = 0;
|
||||||
|
static readonly DIR_EXSITED_ERR: number = -1;
|
||||||
|
static readonly USER_INTPUT_ERR: number = -2;
|
||||||
|
static readonly DIR_PATH_INVALID_ERR: number = -3;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param context extension context from extension.ts active func
|
|
||||||
*/
|
|
||||||
constructor(extensionUri: vscode.Uri, panel: vscode.WebviewPanel) {
|
constructor(extensionUri: vscode.Uri, panel: vscode.WebviewPanel) {
|
||||||
this._panel = panel;
|
this._panel = panel;
|
||||||
this._panel.webview.html = this._getHtmlForWebview(
|
this._panel.webview.html = this._getHtmlForWebview(
|
||||||
|
@ -33,9 +36,6 @@ export class NewProjectPanel {
|
||||||
this._panel.onDidDispose(this.dispose, null, this._disposables);
|
this._panel.onDidDispose(this.dispose, null, this._disposables);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
public static render(context: vscode.ExtensionContext) {
|
public static render(context: vscode.ExtensionContext) {
|
||||||
NewProjectPanel.USER_SET_WORKSPACE = vscode.workspace
|
NewProjectPanel.USER_SET_WORKSPACE = vscode.workspace
|
||||||
.getConfiguration()
|
.getConfiguration()
|
||||||
|
@ -55,7 +55,6 @@ export class NewProjectPanel {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/* create new project panel obj */
|
|
||||||
NewProjectPanel.currentPanel = new NewProjectPanel(
|
NewProjectPanel.currentPanel = new NewProjectPanel(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
panel
|
panel
|
||||||
|
@ -63,10 +62,6 @@ export class NewProjectPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param projName project name input by user
|
|
||||||
* @param template
|
|
||||||
*/
|
|
||||||
private _creatNewProject(
|
private _creatNewProject(
|
||||||
projName: string,
|
projName: string,
|
||||||
template: string,
|
template: string,
|
||||||
|
@ -76,22 +71,23 @@ export class NewProjectPanel {
|
||||||
return NewProjectPanel.USER_INTPUT_ERR;
|
return NewProjectPanel.USER_INTPUT_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkFolderName(projName)) {
|
||||||
|
return NewProjectPanel.DIR_PATH_INVALID_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
let ROOT_PATH = path.join(NewProjectPanel.USER_SET_WORKSPACE, projName);
|
let ROOT_PATH = path.join(NewProjectPanel.USER_SET_WORKSPACE, projName);
|
||||||
let EXT_PATH = extensionUri.fsPath;
|
let EXT_PATH = extensionUri.fsPath;
|
||||||
|
|
||||||
/* if the direcotry has exsited, then ignore the creation and return */
|
|
||||||
if (fs.existsSync(ROOT_PATH)) {
|
if (fs.existsSync(ROOT_PATH)) {
|
||||||
if (fs.lstatSync(ROOT_PATH).isDirectory()) {
|
if (fs.lstatSync(ROOT_PATH).isDirectory()) {
|
||||||
return NewProjectPanel.DIR_EXSITED_ERR;
|
return NewProjectPanel.DIR_EXSITED_ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create necessary floders under the project directory */
|
|
||||||
CreateDirectory(path.join(ROOT_PATH, '.wamr'));
|
CreateDirectory(path.join(ROOT_PATH, '.wamr'));
|
||||||
CreateDirectory(path.join(ROOT_PATH, 'include'));
|
CreateDirectory(path.join(ROOT_PATH, 'include'));
|
||||||
CreateDirectory(path.join(ROOT_PATH, 'src'));
|
CreateDirectory(path.join(ROOT_PATH, 'src'));
|
||||||
|
|
||||||
/* copy scripts files to project_root_path/.wamr */
|
|
||||||
CopyFiles(
|
CopyFiles(
|
||||||
path.join(EXT_PATH, 'resource/scripts/CMakeLists.txt'),
|
path.join(EXT_PATH, 'resource/scripts/CMakeLists.txt'),
|
||||||
path.join(ROOT_PATH, '.wamr/CMakeLists.txt')
|
path.join(ROOT_PATH, '.wamr/CMakeLists.txt')
|
||||||
|
@ -110,7 +106,6 @@ export class NewProjectPanel {
|
||||||
extensionUri: vscode.Uri,
|
extensionUri: vscode.Uri,
|
||||||
templatePath: string
|
templatePath: string
|
||||||
) {
|
) {
|
||||||
/* get toolkit uri */
|
|
||||||
const toolkitUri = getUri(webview, extensionUri, [
|
const toolkitUri = getUri(webview, extensionUri, [
|
||||||
'node_modules',
|
'node_modules',
|
||||||
'@vscode',
|
'@vscode',
|
||||||
|
@ -147,29 +142,26 @@ export class NewProjectPanel {
|
||||||
webview: vscode.Webview,
|
webview: vscode.Webview,
|
||||||
extensionUri: vscode.Uri
|
extensionUri: vscode.Uri
|
||||||
) {
|
) {
|
||||||
// Handle messages from the webview
|
|
||||||
webview.onDidReceiveMessage(
|
webview.onDidReceiveMessage(
|
||||||
message => {
|
message => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
case 'create_new_project':
|
case 'create_new_project':
|
||||||
|
let createNewProjectStatus = this._creatNewProject(
|
||||||
|
message.projectName,
|
||||||
|
message.template,
|
||||||
|
extensionUri
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
this._creatNewProject(
|
createNewProjectStatus ===
|
||||||
message.projectName,
|
NewProjectPanel.EXCUTION_SUCCESS
|
||||||
message.template,
|
|
||||||
extensionUri
|
|
||||||
) === NewProjectPanel.EXCUTION_SUCCESS
|
|
||||||
) {
|
) {
|
||||||
/* post message to page to inform the project creation has finished */
|
|
||||||
webview.postMessage({
|
webview.postMessage({
|
||||||
command: 'proj_creation_finish',
|
command: 'proj_creation_finish',
|
||||||
prjName: message.projectName,
|
prjName: message.projectName,
|
||||||
});
|
});
|
||||||
} else if (
|
} else if (
|
||||||
this._creatNewProject(
|
createNewProjectStatus ===
|
||||||
message.projectName,
|
NewProjectPanel.DIR_EXSITED_ERR
|
||||||
message.template,
|
|
||||||
extensionUri
|
|
||||||
) === NewProjectPanel.DIR_EXSITED_ERR
|
|
||||||
) {
|
) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
'Project : ' +
|
'Project : ' +
|
||||||
|
@ -178,16 +170,30 @@ export class NewProjectPanel {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else if (
|
} else if (
|
||||||
this._creatNewProject(
|
createNewProjectStatus ===
|
||||||
message.projectName,
|
NewProjectPanel.USER_INTPUT_ERR
|
||||||
message.template,
|
|
||||||
extensionUri
|
|
||||||
) === NewProjectPanel.USER_INTPUT_ERR
|
|
||||||
) {
|
) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
'Please fill chart before your submit!'
|
'Please fill chart before your submit!'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
} else if (
|
||||||
|
createNewProjectStatus ===
|
||||||
|
NewProjectPanel.DIR_PATH_INVALID_ERR
|
||||||
|
) {
|
||||||
|
if (os.platform() === 'win32') {
|
||||||
|
vscode.window.showErrorMessage(
|
||||||
|
"A file name can't contain any of the following characters: ' / \\ : * ? < > | ' and the length should be less than 255"
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
os.platform() === 'linux' ||
|
||||||
|
os.platform() === 'darwin'
|
||||||
|
) {
|
||||||
|
vscode.window.showErrorMessage(
|
||||||
|
"A file name can't contain following characters: '/' and the length should be less than 255"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user