Skip to content

Commit

Permalink
v6: Add aliases for renamed inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
qetza committed Mar 12, 2024
1 parent 3a6fff4 commit 74b013a
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 67 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 5.0.2
Task 6.0.2
- Add aliases for renamed inputs to ease upgrade ([#11](https://github.com/qetza/replacetokens-task/issues/11)).

## 5.0.1
Task 6.0.1
- Fix missing default variables due to case-sensitivity ([#8](https://github.com/qetza/replacetokens-task/issues/8)).
Expand All @@ -17,7 +21,7 @@ Task 6.0.0
- renamed input _enableRecursion_ to _recursive_
- renamed input _rootDirectory_ to _root_
- renamed _tokenPattern_ value `rm` to `doubleunderscores`
- renamed input _writeBOM_ to _addBom_
- renamed input _writeBOM_ to _addBOM_
- changed _writeBOM_ default value to `false`
- renamed input _verbosity_ to _logLevel_
- renamed _verbosity_ value `detailed` to `debug`
Expand Down
21 changes: 9 additions & 12 deletions scripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ cp('-Rf', path.join(__dirname, '..', 'images', 'screenshot*.png'), `${packageIma

// update metadata
var public = process.argv.includes('--public');
var taskId = public ? undefined : '0664FF86-F509-4392-A33C-B2D9239B9AE5';
var application = public ? undefined : 'replacetokens-task-dev';

versions.forEach(version => {
console.log();
Expand All @@ -162,24 +160,23 @@ versions.forEach(version => {
console.log(`> version: ${taskVersion}`);

if (!public) {
manifest.friendlyName = `${manifest.friendlyName} (dev ${taskVersion})`;

console.log(`> friendlyName: ${manifest.friendlyName}`);
}
manifest.id = '0664FF86-F509-4392-A33C-B2D9239B9AE5';
console.log(`> id: ${manifest.id}`);

if (taskId) {
manifest.id = taskId;
manifest.name = `${manifest.name}-dev`;
console.log(`> name: ${manifest.name}`);

console.log(`> id: ${manifest.id}`);
manifest.friendlyName = `${manifest.friendlyName} (dev ${taskVersion})`;
console.log(`> friendlyName: ${manifest.friendlyName}`);
}

fs.writeFileSync(path.join(packageTaskDir, 'task.json'), JSON.stringify(manifest, null, 2));

var script = fs.readFileSync(path.join(packageTaskDir, 'index.js'), { encoding: 'utf8' });
if (application) {
script = script.replace(/const\s+application\s*=\s*'[^']*'\s*;/, `const application = '${application}';`);
if (!public) {
script = script.replace(/const\s+application\s*=\s*'[^']*'\s*;/, `const application = 'replacetokens-task-dev';`);

console.log(`> application: ${application}`);
console.log(`> application: replacetokens-task-dev`);
}

script = script.replace(/const\s+version\s*=\s*'[^']*'\s*;/, `const version = '${taskVersion}';`);
Expand Down
2 changes: 1 addition & 1 deletion tasks/ReplaceTokensV5/tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const data = path.join(__dirname, '../../tests/_data');
const tmp = path.join(__dirname, '_tmp');

describe('ReplaceTokens v5 L0 suite', function () {
this.timeout(5000);
this.timeout(10000);

function runValidation(validator: () => void, tr: ttm.MockTestRunner, done: Mocha.Done) {
try {
Expand Down
5 changes: 4 additions & 1 deletion tasks/ReplaceTokensV6/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 6.0.2
- Add aliases for renamed inputs to ease upgrade ([#11](https://github.com/qetza/replacetokens-task/issues/11)).

## 6.0.1
- Fix missing default variables due to case-sensitivity ([#8](https://github.com/qetza/replacetokens-task/issues/8)).

Expand All @@ -17,7 +20,7 @@
- renamed input _enableRecursion_ to _recursive_
- renamed input _rootDirectory_ to _root_
- renamed _tokenPattern_ value `rm` to `doubleunderscores`
- renamed input _writeBOM_ to _addBom_
- renamed input _writeBOM_ to _addBOM_
- changed _writeBOM_ default value to `false`
- renamed input _verbosity_ to _logLevel_
- renamed _verbosity_ value `detailed` to `debug`
Expand Down
33 changes: 18 additions & 15 deletions tasks/ReplaceTokensV6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@ async function run() {

try {
// read and validate inputs
const sources = tl.getDelimitedInput('sources', /\r?\n/, true);
const sources = tl.getDelimitedInput('targetFiles', /\r?\n/);
if (sources.length === 0) throw new Error('Input required: sources');

const options: rt.Options = {
addBOM: tl.getBoolInput('addBOM'),
addBOM: tl.getBoolInput('writeBOM'),
encoding: tl.getInput('encoding') || rt.Encodings.Auto,
escape: {
chars: tl.getInput('charsToEscape'),
escapeChar: tl.getInput('escapeChar'),
type: getChoiceInput('escape', [rt.Escapes.Auto, rt.Escapes.Custom, rt.Escapes.Json, rt.Escapes.Off, rt.Escapes.Xml]) || rt.Escapes.Auto
type: getChoiceInput('escapeType', [rt.Escapes.Auto, rt.Escapes.Custom, rt.Escapes.Json, rt.Escapes.Off, rt.Escapes.Xml], 'escape') || rt.Escapes.Auto
},
missing: {
action:
getChoiceInput('missingVarAction', [rt.MissingVariables.Action.Keep, rt.MissingVariables.Action.None, rt.MissingVariables.Action.Replace]) ||
rt.MissingVariables.Action.None,
default: tl.getInput('missingVarDefault') || '',
default: tl.getInput('defaultValue') || '',
log:
getChoiceInput('missingVarLog', [rt.MissingVariables.Log.Error, rt.MissingVariables.Log.Off, rt.MissingVariables.Log.Warn]) ||
getChoiceInput('actionOnMissing', [rt.MissingVariables.Log.Error, rt.MissingVariables.Log.Off, rt.MissingVariables.Log.Warn], 'missingVarLog') ||
rt.MissingVariables.Log.Warn
},
recursive: tl.getBoolInput('recursive'),
root: tl.getPathInput('root', false, true),
separator: tl.getInput('separator') || rt.Defaults.Separator,
recursive: tl.getBoolInput('enableRecursion'),
root: tl.getPathInput('rootDirectory', false, true),
separator: tl.getInput('variableSeparator') || rt.Defaults.Separator,
token: {
pattern:
getChoiceInput('tokenPattern', [
Expand All @@ -68,9 +70,9 @@ async function run() {
suffix: tl.getInput('tokenSuffix')
},
transforms: {
enabled: tl.getBoolInput('transforms'),
prefix: tl.getInput('transformsPrefix') || rt.Defaults.TransformPrefix,
suffix: tl.getInput('transformsSuffix') || rt.Defaults.TransformSuffix
enabled: tl.getBoolInput('enableTransforms'),
prefix: tl.getInput('transformPrefix') || rt.Defaults.TransformPrefix,
suffix: tl.getInput('transformSuffix') || rt.Defaults.TransformSuffix
}
};

Expand All @@ -83,8 +85,8 @@ async function run() {
await parseVariables(tl.getInput('additionalVariables'), options.root, options.separator)
);

const ifNoFilesFound = tl.getInput('ifNoFilesFound') || 'ignore';
const logLevelStr = tl.getInput('logLevel') || 'info';
const ifNoFilesFound = tl.getInput('actionOnNoFiles') || 'ignore';
const logLevelStr = tl.getInput('verbosity') || 'info';

// set telemetry attributes
telemetryEvent.setAttributes({
Expand Down Expand Up @@ -187,11 +189,12 @@ async function run() {
}
}

var getChoiceInput = function (name: string, choices: string[]): string {
var getChoiceInput = function (name: string, choices: string[], alias?: string): string {
alias = alias || name;
const input = tl.getInput(name)?.trim();
if (!input || choices.includes(input)) return input;

throw new Error(`Unsupported value for input: ${name}\nSupport input list: '${choices.join(' | ')}'`);
throw new Error(`Unsupported value for input: ${alias}\nSupport input list: '${choices.join(' | ')}'`);
};

var parseVariables = async function (input: string, root: string, separator: string): Promise<{ [key: string]: any }> {
Expand Down
49 changes: 31 additions & 18 deletions tasks/ReplaceTokensV6/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@
"version": {
"Major": 6,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"releaseNotes": "breaking changes, see [changelog](https://github.com/qetza/replacetokens-task/blob/master/tasks/ReplaceTokensV6/CHANGELOG.md)",
"instanceNameFormat": "Replace tokens",
"minimumAgentVersion": "2.144.0",
"groups": [],
"inputs": [
{
"name": "root",
"name": "rootDirectory",
"aliases": ["root"],
"type": "filePath",
"required": false,
"defaultValue": "",
"label": "Root",
"helpMarkDown": "The root path to use when reading files with a relative path. Default: $(System.DefaultWorkingDirectory)"
},
{
"name": "sources",
"name": "targetFiles",
"aliases": ["sources"],
"type": "multiLine",
"required": true,
"defaultValue": "",
Expand Down Expand Up @@ -88,7 +90,8 @@
"helpMarkDown": "The encoding to read and write all files. Default: auto"
},
{
"name": "addBom",
"name": "writeBOM",
"aliases": ["addBOM"],
"type": "boolean",
"required": false,
"defaultValue": false,
Expand All @@ -105,7 +108,8 @@
"helpMarkDown": "A YAML formatted string containing additional variables or file or environment variable references."
},
{
"name": "separator",
"name": "variableSeparator",
"aliases": ["separator"],
"type": "string",
"defaultValue": ".",
"required": false,
Expand All @@ -114,7 +118,8 @@
"helpMarkDown": "The separtor to use when flattening keys in variables."
},
{
"name": "escape",
"name": "escapeType",
"aliases": ["escape"],
"type": "pickList",
"required": false,
"defaultValue": "auto",
Expand All @@ -132,20 +137,21 @@
"name": "escapeChar",
"type": "string",
"required": false,
"visibleRule": "escape == custom",
"visibleRule": "escapeType == custom",
"label": "Escape character",
"helpMarkDown": "The escape character to use when using 'custom' escape."
},
{
"name": "charsToEscape",
"type": "string",
"required": false,
"visibleRule": "escape == custom",
"visibleRule": "escapeType == custom",
"label": "Characters to escape",
"helpMarkDown": "The characters to escape when using 'custom' escape."
},
{
"name": "logLevel",
"name": "verbosity",
"aliases": ["logLevel"],
"type": "pickList",
"required": false,
"defaultValue": "info",
Expand All @@ -172,7 +178,8 @@
"helpMarkDown": "The behavior if variable is not found. Default: none"
},
{
"name": "missingVarDefault",
"name": "defaultValue",
"aliases": ["missingVarDefault"],
"type": "string",
"required": false,
"defaultValue": "",
Expand All @@ -181,7 +188,8 @@
"helpMarkDown": "The default value to use when a key is not found. Default: empty string"
},
{
"name": "missingVarLog",
"name": "actionOnMissing",
"aliases": ["missingVarLog"],
"type": "pickList",
"required": false,
"defaultValue": "warn",
Expand All @@ -195,7 +203,8 @@
"helpMarkDown": "The level to log key not found messages. Default: warn"
},
{
"name": "ifNoFilesFound",
"name": "actionOnNoFiles",
"aliases": ["ifNoFilesFound"],
"type": "pickList",
"required": false,
"defaultValue": "ignore",
Expand All @@ -208,36 +217,40 @@
"helpMarkDown": "The behavior if no files are found. Default: ignore"
},
{
"name": "recursive",
"name": "enableRecursion",
"aliases": ["recursive"],
"type": "boolean",
"required": false,
"defaultValue": false,
"label": "Enable recursion in values",
"helpMarkDown": "Enable token replacements in values recusively. Default: false"
},
{
"name": "transforms",
"name": "enableTransforms",
"aliases": ["transforms"],
"type": "boolean",
"required": false,
"defaultValue": false,
"label": "Enable transforms",
"helpMarkDown": "Enable transforms on values. Default: false"
},
{
"name": "transformsPrefix",
"name": "transformPrefix",
"aliases": ["transformsPrefix"],
"type": "string",
"required": false,
"defaultValue": "(",
"visibleRule": "transforms == true",
"visibleRule": "enableTransforms == true",
"label": "Transforms prefix",
"helpMarkDown": "The tranforms prefix when using transforms. Default: ("
},
{
"name": "transformsSuffix",
"name": "transformSuffix",
"aliases": ["transformsSuffix"],
"type": "string",
"required": false,
"defaultValue": ")",
"visibleRule": "transforms == true",
"visibleRule": "enableTransforms == true",
"label": "Transforms suffix",
"helpMarkDown": "The tranforms suffix when using transforms. Default: )"
},
Expand Down
2 changes: 1 addition & 1 deletion tasks/ReplaceTokensV6/tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const data = path.join(__dirname, '..', '..', 'tests', '_data');
const tmp = path.join(__dirname, '_tmp');

describe('ReplaceTokens v6 L0 suite', function () {
this.timeout(5000);
this.timeout(10000);

afterEach(() => {
// clean env
Expand Down
4 changes: 2 additions & 2 deletions tasks/ReplaceTokensV6/tests/L0_IfNoFilesFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const taskPath = path.join(__dirname, '..', 'index.js');
const tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// inputs
tmr.setInput('sources', process.env['__sources__']);
tmr.setInput('ifNoFilesFound', process.env['__ifNoFilesFound__']);
tmr.setInput('targetFiles', process.env['__sources__']);
tmr.setInput('actionOnNoFiles', process.env['__ifNoFilesFound__']);

// mocks
const rt = require('@qetza/replacetokens');
Expand Down
4 changes: 2 additions & 2 deletions tasks/ReplaceTokensV6/tests/L0_LogLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const taskPath = path.join(__dirname, '..', 'index.js');
const tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// inputs
tmr.setInput('sources', process.env['__sources__']);
tmr.setInput('logLevel', process.env['__logLevel__']);
tmr.setInput('targetFiles', process.env['__sources__']);
tmr.setInput('verbosity', process.env['__logLevel__']);

// mocks
const rt = require('@qetza/replacetokens');
Expand Down
26 changes: 13 additions & 13 deletions tasks/ReplaceTokensV6/tests/L0_Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ const taskPath = path.join(__dirname, '..', 'index.js');
const tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// inputs
if (process.env['__sources__']) tmr.setInput('sources', process.env['__sources__']);
if (process.env['__addBOM__']) tmr.setInput('addBOM', process.env['__addBOM__']);
if (process.env['__sources__']) tmr.setInput('targetFiles', process.env['__sources__']);
if (process.env['__addBOM__']) tmr.setInput('writeBOM', process.env['__addBOM__']);
if (process.env['__additionalVariables__']) tmr.setInput('additionalVariables', process.env['__additionalVariables__']);
if (process.env['__charsToEscape__']) tmr.setInput('charsToEscape', process.env['__charsToEscape__']);
if (process.env['__encoding__']) tmr.setInput('encoding', process.env['__encoding__']);
if (process.env['__escape__']) tmr.setInput('escape', process.env['__escape__']);
if (process.env['__escape__']) tmr.setInput('escapeType', process.env['__escape__']);
if (process.env['__escapeChar__']) tmr.setInput('escapeChar', process.env['__escapeChar__']);
if (process.env['__ifNoFilesFound__']) tmr.setInput('ifNoFilesFound', process.env['__ifNoFilesFound__']);
if (process.env['__logLevel__']) tmr.setInput('logLevel', process.env['__logLevel__']);
if (process.env['__ifNoFilesFound__']) tmr.setInput('actionOnNoFiles', process.env['__ifNoFilesFound__']);
if (process.env['__logLevel__']) tmr.setInput('verbosity', process.env['__logLevel__']);
if (process.env['__missingVarAction__']) tmr.setInput('missingVarAction', process.env['__missingVarAction__']);
if (process.env['__missingVarDefault__']) tmr.setInput('missingVarDefault', process.env['__missingVarDefault__']);
if (process.env['__missingVarLog__']) tmr.setInput('missingVarLog', process.env['__missingVarLog__']);
if (process.env['__recursive__']) tmr.setInput('recursive', process.env['__recursive__']);
if (process.env['__root__']) tmr.setInput('root', process.env['__root__']);
if (process.env['__separator__']) tmr.setInput('separator', process.env['__separator__']);
if (process.env['__missingVarDefault__']) tmr.setInput('defaultValue', process.env['__missingVarDefault__']);
if (process.env['__missingVarLog__']) tmr.setInput('actionOnMissing', process.env['__missingVarLog__']);
if (process.env['__recursive__']) tmr.setInput('enableRecursion', process.env['__recursive__']);
if (process.env['__root__']) tmr.setInput('rootDirectory', process.env['__root__']);
if (process.env['__separator__']) tmr.setInput('variableSeparator', process.env['__separator__']);
if (process.env['__telemetryOptout__']) tmr.setInput('telemetryOptout', process.env['__telemetryOptout__']);
if (process.env['__tokenPattern__']) tmr.setInput('tokenPattern', process.env['__tokenPattern__']);
if (process.env['__tokenPrefix__']) tmr.setInput('tokenPrefix', process.env['__tokenPrefix__']);
if (process.env['__tokenSuffix__']) tmr.setInput('tokenSuffix', process.env['__tokenSuffix__']);
if (process.env['__transforms__']) tmr.setInput('transforms', process.env['__transforms__']);
if (process.env['__transformsPrefix__']) tmr.setInput('transformsPrefix', process.env['__transformsPrefix__']);
if (process.env['__transformsSuffix__']) tmr.setInput('transformsSuffix', process.env['__transformsSuffix__']);
if (process.env['__transforms__']) tmr.setInput('enableTransforms', process.env['__transforms__']);
if (process.env['__transformsPrefix__']) tmr.setInput('transformPrefix', process.env['__transformsPrefix__']);
if (process.env['__transformsSuffix__']) tmr.setInput('transformSuffix', process.env['__transformsSuffix__']);

// mocks
const rtClone = Object.assign({}, require('@qetza/replacetokens'));
Expand Down
Loading

0 comments on commit 74b013a

Please sign in to comment.