-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the task « Tool - Create a File »
- Loading branch information
Showing
15 changed files
with
338 additions
and
10 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
{ | ||
"name": "CreateFile", | ||
"dependencies": { | ||
"azure-pipelines-task-lib": "2.8.0" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
} | ||
} |
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,118 @@ | ||
{ | ||
"id": "81152B68-7A9D-4471-8579-4CDA672AC509", | ||
"name": "ToolCreateFile", | ||
"friendlyName": "Tool - Create a File", | ||
"description": "Provide the ability to create a file and perform an action on his content.", | ||
"helpMarkDown": "", | ||
"category": "Utility", | ||
"visibility": [ | ||
"Build", | ||
"Release" | ||
], | ||
"author": "Fizcko", | ||
"version": { | ||
"Major": 2, | ||
"Minor": 5, | ||
"Patch": 0 | ||
}, | ||
"instanceNameFormat": "Tool - Create a File", | ||
"groups": [ | ||
{ | ||
"name": "groupSettings", | ||
"displayName": "Settings", | ||
"isExpanded": true | ||
} | ||
], | ||
"inputs": [ | ||
{ | ||
"name": "targetDirectory", | ||
"type": "filePath", | ||
"label": "Target directory", | ||
"defaultValue": "$(System.DefaultWorkingDirectory)", | ||
"required": true, | ||
"helpMarkDown": "Directory to save the file.", | ||
"groupName": "groupSettings" | ||
}, | ||
{ | ||
"name": "targetName", | ||
"type": "string", | ||
"label": "File name", | ||
"defaultValue": "myCert.pem", | ||
"required": true, | ||
"helpMarkDown": "Enter the file name with the extension.", | ||
"groupName": "groupSettings" | ||
}, | ||
{ | ||
"name": "fileContent", | ||
"type": "multiLine", | ||
"label": "File Content", | ||
"defaultValue": "", | ||
"required": true, | ||
"helpMarkDown": "Enter the content of the file.", | ||
"groupName": "groupSettings" | ||
}, | ||
{ | ||
"name": "fileEncoding", | ||
"type": "pickList", | ||
"label": "Encoding", | ||
"defaultValue": "utf8", | ||
"required": true, | ||
"helpMarkDown": "Specifies the file encoding. More defails in NodeJS documentation (Buffers and Character Encodings).", | ||
"groupName": "groupSettings", | ||
"options": { | ||
"ascii": "ASCII", | ||
"utf8": "UTF8", | ||
"utf16le": "BigEndianUTF32", | ||
"ucs2": "UCS-2 (Alias of UTF-16LE)", | ||
"base64": "Base64 encoding", | ||
"latin1": "Latin-1", | ||
"binary": "Binary (Latin-1)", | ||
"hex": "HEX" | ||
} | ||
}, | ||
{ | ||
"name": "actionType", | ||
"type": "pickList", | ||
"label": "Action to perform", | ||
"defaultValue": "none", | ||
"required": true, | ||
"helpMarkDown": "Choose an action to perform on the file content.", | ||
"groupName": "groupSettings", | ||
"options": { | ||
"none": "No action", | ||
"replaceToken": "Replace token by a new line", | ||
"decodeBase64": "Decode from base64" | ||
} | ||
}, | ||
{ | ||
"name": "actionToken", | ||
"type": "string", | ||
"label": "Token to replace", | ||
"defaultValue": "", | ||
"required": true, | ||
"helpMarkDown": "Enter the token to replace by a new line.", | ||
"groupName": "groupSettings", | ||
"visibleRule": "actionType = replaceToken" | ||
}, | ||
{ | ||
"name": "actionNewLineType", | ||
"type": "pickList", | ||
"label": "New line type", | ||
"defaultValue": "crlf", | ||
"required": true, | ||
"helpMarkDown": "Choose the new line type", | ||
"groupName": "groupSettings", | ||
"options": { | ||
"cr": "Carriage Return (CR, \\r)", | ||
"lf": "Line Feed (LF, \\n)", | ||
"crlf": "CR followed by LF (CRLF, \\r\\n)" | ||
}, | ||
"visibleRule": "actionType = replaceToken" | ||
} | ||
], | ||
"execution": { | ||
"Node": { | ||
"target": "tool_create_file.js" | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 @@ | ||
import tl = require('azure-pipelines-task-lib/task'); | ||
import path = require('path'); | ||
import fs = require('fs'); | ||
|
||
async function run() { | ||
|
||
try { | ||
|
||
var targetDirectory = tl.getInput('targetDirectory', true); | ||
var targetName = tl.getInput('targetName', true); | ||
var fileContent = tl.getInput('fileContent', true); | ||
var fileEncoding = tl.getInput('fileEncoding', true); | ||
var actionType = tl.getInput('actionType', true); | ||
if(actionType == "replaceToken"){ | ||
var actionToken = tl.getInput('actionToken', true); | ||
var actionNewLineType = tl.getInput('actionNewLineType', true); | ||
} | ||
|
||
// Define output path | ||
var outputFilePath = path.join(targetDirectory,targetName); | ||
|
||
// Create ouptuf folder is needed | ||
if(!fs.existsSync(targetDirectory)){ | ||
|
||
try{ | ||
fs.mkdirSync(targetDirectory,{ recursive: true }); | ||
} catch (err) { | ||
throw new Error("Mkdir error. " + err); | ||
} | ||
} | ||
|
||
var finalContent = null; | ||
var actionToPerform = null; | ||
|
||
// Perform actions | ||
switch(actionType){ | ||
case "replaceToken": | ||
// Create regex | ||
var newLine = null; | ||
var newLineType = null; | ||
switch(actionNewLineType){ | ||
case "cr": | ||
newLine = "\r"; | ||
newLineType = "Carriage Return (CR, \\r)"; | ||
break; | ||
case "lf": | ||
newLine = "\n"; | ||
newLineType = "Line Feed (LF, \\n)"; | ||
break; | ||
default: | ||
newLine = "\r\n"; | ||
newLineType = "CR followed by LF (CRLF, \\r\\n)"; | ||
break; | ||
} | ||
finalContent = fileContent.replace(new RegExp(actionToken,"g"),newLine); | ||
actionToPerform = "Replace token"; | ||
break; | ||
case "decodeBase64": | ||
finalContent = new Buffer(fileContent, 'base64'); | ||
actionToPerform = "Decode from base64"; | ||
break; | ||
default: | ||
finalContent = fileContent; | ||
actionToPerform = "None"; | ||
} | ||
|
||
// Create file | ||
try{ | ||
fs.writeFileSync(outputFilePath,finalContent,fileEncoding); | ||
} catch (err) { | ||
throw new Error("Write error. " + err); | ||
} | ||
|
||
// Display results | ||
console.log("[INFO] The file saved in : '" + outputFilePath + "'"); | ||
console.log("[INFO] Encoding : '" + fileEncoding + "'"); | ||
console.log("[INFO] Action to perform : '" + actionToPerform + "'"); | ||
if(actionType == "replaceToken"){ | ||
console.log("[INFO] Token to replace : '" + actionToken + "'"); | ||
console.log("[INFO] New line type : '" + newLineType + "'"); | ||
} | ||
|
||
tl.setResult(tl.TaskResult.Succeeded, "Wrapping successfull."); | ||
|
||
} catch (err) { | ||
tl.setResult(tl.TaskResult.Failed, err); | ||
} | ||
|
||
|
||
} | ||
|
||
run(); |
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
Oops, something went wrong.