-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-2) Added add sample build file command
- Loading branch information
Showing
13 changed files
with
240 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,35 @@ | ||
// 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", | ||
"version": "0.1.0", | ||
"configurations": [ | ||
{ | ||
"type": "PowerShell", | ||
"name": "Launch Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"name": "PowerShell Launch Current File", | ||
"script": "${file}", | ||
"args": [], | ||
"cwd": "${file}" | ||
"runtimeExecutable": "${execPath}", | ||
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ], | ||
"stopOnEntry": false, | ||
"sourceMaps": true, | ||
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ], | ||
"preLaunchTask": "npm" | ||
}, | ||
{ | ||
"type": "PowerShell", | ||
"name": "Launch Tests", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"name": "PowerShell Launch Current File in Temporary Console", | ||
"script": "${file}", | ||
"args": [], | ||
"cwd": "${file}", | ||
"createTemporaryIntegratedConsole": true | ||
"runtimeExecutable": "${execPath}", | ||
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], | ||
"stopOnEntry": false, | ||
"sourceMaps": true, | ||
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ], | ||
"preLaunchTask": "npm" | ||
}, | ||
{ | ||
"type": "PowerShell", | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"name": "PowerShell Launch Current File w/Args Prompt", | ||
"script": "${file}", | ||
"args": [ | ||
"${command:SpecifyScriptArgs}" | ||
], | ||
"cwd": "${file}" | ||
}, | ||
{ | ||
"type": "PowerShell", | ||
"request": "attach", | ||
"name": "PowerShell Attach to Host Process", | ||
"processId": "${command:PickPSHostProcess}", | ||
"runspaceId": 1 | ||
}, | ||
{ | ||
"type": "PowerShell", | ||
"request": "launch", | ||
"name": "PowerShell Interactive Session", | ||
"cwd": "${workspaceRoot}" | ||
"mode": "debug", | ||
"program": "${workspaceRoot}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{ | ||
"files.trimTrailingWhitespace": true, | ||
"files.insertFinalNewline": true, | ||
"editor.insertSpaces": true, | ||
"editor.tabSize": 4, | ||
"files.exclude": { | ||
"out": false // set this to true to hide the "out" folder with the compiled JS files | ||
}, | ||
"search.exclude": { | ||
"?.?.?/": true | ||
"**/node_modules": true, | ||
"**/bower_components": true, | ||
"logs/": true, | ||
"out/": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Available variables which can be used inside of strings. | ||
// ${workspaceRoot}: the root folder of the team | ||
// ${file}: the current opened file | ||
// ${fileBasename}: the current opened file's basename | ||
// ${fileDirname}: the current opened file's dirname | ||
// ${fileExtname}: the current opened file's extension | ||
// ${cwd}: the current working directory of the spawned process | ||
|
||
// A task runner that calls a custom npm script that compiles the extension. | ||
{ | ||
"version": "0.1.0", | ||
|
||
// we want to run npm | ||
"command": "npm", | ||
|
||
// the command is a shell script | ||
"isShellCommand": true, | ||
|
||
// show the output window only if unrecognized errors occur. | ||
"showOutput": "silent", | ||
|
||
// we run the custom script "compile" as defined in package.json | ||
"args": ["run", "compile", "--loglevel", "silent"], | ||
|
||
// The tsc compiler is started in watching mode | ||
"isBackground": true, | ||
|
||
// use the standard tsc in watch mode problem matcher to find compile problems in the output. | ||
"problemMatcher": "$tsc-watch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { DEFAULT_SCRIPT_NAME } from "../constants"; | ||
|
||
export class psakeBuildFile { | ||
|
||
constructor(public scriptName: string = DEFAULT_SCRIPT_NAME) { } | ||
|
||
public getTargetPath(): string { | ||
if (vscode.workspace.rootPath) { | ||
return path.join(vscode.workspace.rootPath, this.scriptName); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
public create(): Thenable<boolean> { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
let buildFile = fs.createWriteStream(this.getTargetPath(), { | ||
flags: 'a' | ||
}); | ||
|
||
buildFile.write('Task default -Depends Test\n'); | ||
buildFile.write('\n'); | ||
buildFile.write('Task Test -Depends Compile, Clean {\n'); | ||
buildFile.write('\t"This is a test"\n'); | ||
buildFile.write('}\n'); | ||
buildFile.write('\n'); | ||
buildFile.write('Task Compile -Depends Clean {\n'); | ||
buildFile.write('\t"Compile"\n'); | ||
buildFile.write('}\n'); | ||
buildFile.write('\n'); | ||
buildFile.write('Task Clean {\n'); | ||
buildFile.write('\t"Clean"\n'); | ||
buildFile.write('}\n'); | ||
buildFile.end(); | ||
|
||
buildFile.on('finish', function() { | ||
vscode.workspace.openTextDocument(buildFile.path.toString()).then((document) => { | ||
vscode.window.showTextDocument(document); | ||
}); | ||
resolve(true); | ||
}); | ||
} catch (error) { | ||
reject(false); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { window, workspace } from 'vscode'; | ||
import { psakeBuildFile } from './psakeBuildFile'; | ||
import { messages, utils } from "../shared"; | ||
import { DEFAULT_SCRIPT_NAME, CANCEL } from "../constants"; | ||
|
||
export async function installBuildFileCommand() { | ||
// Check if there is an open folder in workspace | ||
if (workspace.rootPath === undefined) { | ||
window.showErrorMessage('You have not yet opened a folder.'); | ||
return; | ||
} | ||
|
||
var name = await window.showInputBox({ | ||
placeHolder: messages.PROMPT_SCRIPT_NAME, | ||
value: DEFAULT_SCRIPT_NAME | ||
}); | ||
|
||
if (!name) { | ||
window.showWarningMessage('No script name provided! Try again and make sure to provide a file name.'); | ||
return; | ||
} | ||
|
||
var result = await installBuildFile(name); | ||
|
||
if (result) { | ||
window.showInformationMessage("Sample psake build file successfully created."); | ||
} else { | ||
window.showErrorMessage("Error creating sample psake buile file."); | ||
} | ||
} | ||
|
||
export async function installBuildFile(fileName: string): Promise<boolean> { | ||
// Create the buildFile object | ||
let buildFile = new psakeBuildFile(fileName); | ||
|
||
var targetPath = buildFile.getTargetPath(); | ||
var ready = await utils.checkForExisting(targetPath); | ||
|
||
if (!ready) { | ||
Promise.reject(CANCEL); | ||
} | ||
|
||
var result = await buildFile.create(); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const CANCEL = '__CANCEL__'; | ||
export const DEFAULT_SCRIPT_NAME = 'psakefile.ps1'; | ||
export const ERROR_NO_WORKSPACE = 'You have not yet opened a folder.'; | ||
export const OUTPUT_CHANNEL_NAME = 'psake Workspace'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as vscode from 'vscode'; | ||
import { installBuildFileCommand } from './buildFile/psakeBuildFileCommand'; | ||
|
||
export function activate(context: vscode.ExtensionContext): void { | ||
// Register the build file command. | ||
context.subscriptions.push(vscode.commands.registerCommand('psake.buildFile', async () => { | ||
installBuildFileCommand(); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as logger from './log'; | ||
import * as utils from './utility'; | ||
import * as messages from './messages'; | ||
|
||
export { logger, messages, utils }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { window, OutputChannel } from 'vscode'; | ||
import { OUTPUT_CHANNEL_NAME } from "../constants"; | ||
|
||
let channel: OutputChannel; | ||
|
||
export function logToOutput(...items: string[]): void { | ||
var channel = getChannel(OUTPUT_CHANNEL_NAME); | ||
items.forEach(item => { | ||
channel.appendLine(item); | ||
}); | ||
} | ||
|
||
export function logError(error: string, notify: boolean = true) { | ||
var channel = getChannel(OUTPUT_CHANNEL_NAME); | ||
channel.appendLine('Error encountered during psake operation.') | ||
channel.appendLine(`E: ${error}`); | ||
|
||
if (notify) { | ||
window.showErrorMessage(error); | ||
} | ||
} | ||
|
||
function getChannel(name: string): OutputChannel { | ||
if (!channel) { | ||
channel = window.createOutputChannel(name); | ||
} | ||
|
||
return channel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PROMPT_SCRIPT_NAME = 'Enter the name for your new build script'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { window } from 'vscode'; | ||
import * as fs from 'fs'; | ||
|
||
export async function checkForExisting(path: string): Promise<boolean> { | ||
if (fs.existsSync(path)) { | ||
var message = `Overwrite the existing \'${path}\' file in this folder?`; | ||
var option = await window.showWarningMessage(message, 'Overwrite'); | ||
return option === 'Overwrite'; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": [ | ||
"es6" | ||
], | ||
"sourceMap": true, | ||
"noUnusedParameters": true, | ||
"noUnusedLocals": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"allowUnreachableCode": false, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"alwaysStrict": true, | ||
"noImplicitThis": true, | ||
"strict": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |