move application.yaml to collections/windows.yaml #40
This commit is contained in:
@@ -30,8 +30,8 @@
|
|||||||
- There are two types of components:
|
- There are two types of components:
|
||||||
- **Stateless**, extends `Vue`
|
- **Stateless**, extends `Vue`
|
||||||
- **Stateful**, extends [`StatefulVue`](./src/presentation/StatefulVue.ts)
|
- **Stateful**, extends [`StatefulVue`](./src/presentation/StatefulVue.ts)
|
||||||
- The source of truth for the state lies in application layer (`./src/application/`) and must be updated from the views if they're mutating the state
|
- The source of truth for the state lies in application layer ([`./src/application/`](src/application/)) and must be updated from the views if they're mutating the state
|
||||||
- They mutate or/and react to changes in [application state](src/application/Context/State/CategoryCollectionState.ts).
|
- They mutate or/and react to state changes in [ApplicationContext](src/application/Context/ApplicationContext.ts).
|
||||||
- You can react by getting the state and listening to it and update the view accordingly in [`mounted()`](https://vuejs.org/v2/api/#mounted) method.
|
- You can react by getting the state and listening to it and update the view accordingly in [`mounted()`](https://vuejs.org/v2/api/#mounted) method.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -32,9 +32,11 @@
|
|||||||
|
|
||||||
## Extend scripts
|
## Extend scripts
|
||||||
|
|
||||||
- Fork it & add more scripts in [application.yaml](src/application/application.yaml) and send a pull request 👌
|
1. Fork the repository
|
||||||
- 📖 If you're unsure about the syntax you can refer to the [application file | documentation](docs/application-file.md).
|
2. Add more scripts in respective script collection in [collections](src/application/collections/) folder.
|
||||||
|
- 📖 If you're unsure about the syntax you can refer to the [collection files | documentation](docs/collection-files.md).
|
||||||
- 🙏 For any new script, please add `revertCode` and `docs` values if possible.
|
- 🙏 For any new script, please add `revertCode` and `docs` values if possible.
|
||||||
|
3. Send a pull request 👌
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
@@ -69,7 +71,9 @@
|
|||||||
- [ApplicationContext](src/application/Context/ApplicationContext.ts)
|
- [ApplicationContext](src/application/Context/ApplicationContext.ts)
|
||||||
- Holds the [CategoryCollectionState](src/application/Context/State/CategoryCollectionState.ts)] for each OS
|
- Holds the [CategoryCollectionState](src/application/Context/State/CategoryCollectionState.ts)] for each OS
|
||||||
- Same instance is shared throughout the application
|
- Same instance is shared throughout the application
|
||||||
- The application is defined & controlled in a [single YAML file](src/application/application.yaml) using[data-driven programming](https://en.wikipedia.org/wiki/Data-driven_programming)
|
- The scripts are defined and controlled in [yaml files](src/application/collections/) per OS
|
||||||
|
- Uses [data-driven programming](https://en.wikipedia.org/wiki/Data-driven_programming)
|
||||||
|
- 📖 See [extend scripts](#extend-scripts) to read about how to extend them.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
# Application file
|
# Collection files
|
||||||
|
|
||||||
- privacy.sexy is a data-driven application where it reads the necessary OS-specific logic from [`application.yaml`](./../src/application/application.yaml)
|
- privacy.sexy is a data-driven application where it reads the necessary OS-specific logic from yaml files in [`application/collections`](./../src/application/collections/)
|
||||||
- 💡 Best practices
|
- 💡 Best practices
|
||||||
- If you repeat yourself, try to utilize [YAML-defined functions](#function)
|
- If you repeat yourself, try to utilize [YAML-defined functions](#Function)
|
||||||
- Always try to add documentation and a way to revert a tweak in [scripts](#script)
|
- Always try to add documentation and a way to revert a tweak in [scripts](#Script)
|
||||||
- 📖 Types in code: [`application.d.ts`](./../src/application/application.yaml.d.ts)
|
- 📖 Types in code: [`collection.yaml.d.ts`](./../src/application/collections/collection.yaml.d.ts)
|
||||||
|
|
||||||
## Objects
|
## Objects
|
||||||
|
|
||||||
### `Application`
|
### `Collection`
|
||||||
|
|
||||||
- Application file simply defines:
|
- A collection simply defines:
|
||||||
- different categories and their scripts in a tree structure
|
- different categories and their scripts in a tree structure
|
||||||
- OS specific details
|
- OS specific details
|
||||||
- Application file also allows defining common [function](#function)s to be used throughout the application if you'd like different scripts to share same code.
|
- Also allows defining common [function](#Function)s to be used throughout the collection if you'd like different scripts to share same code.
|
||||||
|
|
||||||
#### `Application` syntax
|
#### `Collection` syntax
|
||||||
|
|
||||||
- `os:` *`string`* (**required**)
|
- `os:` *`string`* (**required**)
|
||||||
- Operating system that the application file is written for.
|
- Operating system that the [Collection](#collection) is written for.
|
||||||
- 📖 See [OperatingSystem.ts](./../src/domain/OperatingSystem.ts) enumeration for allowed values.
|
- 📖 See [OperatingSystem.ts](./../src/domain/OperatingSystem.ts) enumeration for allowed values.
|
||||||
- `actions: [` ***[`Category`](#Category)*** `, ... ]` **(required)**
|
- `actions: [` ***[`Category`](#Category)*** `, ... ]` **(required)**
|
||||||
- Each [category](#category) is rendered as different cards in card presentation.
|
- Each [category](#category) is rendered as different cards in card presentation.
|
||||||
- ❗ Application must consist of at least one category.
|
- ❗ A [Collection](#collection) must consist of at least one category.
|
||||||
- `functions: [` ***[`Function`](#Function)*** `, ... ]`
|
- `functions: [` ***[`Function`](#Function)*** `, ... ]`
|
||||||
- Functions are optionally defined to re-use the same code throughout different scripts.
|
- Functions are optionally defined to re-use the same code throughout different scripts.
|
||||||
- `scripting:` ***[`ScriptingDefinition`](#ScriptingDefinition)*** **(required)**
|
- `scripting:` ***[`ScriptingDefinition`](#ScriptingDefinition)*** **(required)**
|
||||||
@@ -37,8 +37,8 @@
|
|||||||
|
|
||||||
- `category:` *`string`* (**required**)
|
- `category:` *`string`* (**required**)
|
||||||
- Name of the category
|
- Name of the category
|
||||||
- ❗ Must be unique throughout the application
|
- ❗ Must be unique throughout the [Collection](#collection)
|
||||||
- `children: [` ***[`Category`](#category)*** `|` [***`Script`***](#Script) `, ... ]` (**required**)
|
- `children: [` ***[`Category`](#Category)*** `|` [***`Script`***](#Script) `, ... ]` (**required**)
|
||||||
- ❗ Category must consist of at least one subcategory or script.
|
- ❗ Category must consist of at least one subcategory or script.
|
||||||
- Children can be combination of scripts and subcategories.
|
- Children can be combination of scripts and subcategories.
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
- `name`: *`string`* (**required**)
|
- `name`: *`string`* (**required**)
|
||||||
- Name of the script
|
- Name of the script
|
||||||
- ❗ Must be unique throughout the application
|
- ❗ Must be unique throughout the [Collection](#collection)
|
||||||
- E.g. `Disable targeted ads`
|
- E.g. `Disable targeted ads`
|
||||||
- `code`: *`string`* (may be **required**)
|
- `code`: *`string`* (may be **required**)
|
||||||
- Batch file commands that will be executed
|
- Batch file commands that will be executed
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
- `function`: *`string`* (**required**)
|
- `function`: *`string`* (**required**)
|
||||||
- Name of the function to call.
|
- Name of the function to call.
|
||||||
- ❗ Function with same name must defined in `functions` property of [Application](#application)
|
- ❗ Function with same name must defined in `functions` property of [Collection](#collection)
|
||||||
- `parameters`: `[ parameterName:` *`parameterValue`*`, ... ]`
|
- `parameters`: `[ parameterName:` *`parameterValue`*`, ... ]`
|
||||||
- Defines key value dictionary for each parameter and its value
|
- Defines key value dictionary for each parameter and its value
|
||||||
- E.g.
|
- E.g.
|
||||||
@@ -134,7 +134,7 @@ It would print "Hello world" if it's called in a [script](#script) as following:
|
|||||||
- ❗ Function names must be unique
|
- ❗ Function names must be unique
|
||||||
- `parameters`: `[` *`string`* `, ... ]`
|
- `parameters`: `[` *`string`* `, ... ]`
|
||||||
- Name of the parameters that the function has.
|
- Name of the parameters that the function has.
|
||||||
- Parameter values are provided by a [Script](#script) through a [FunctionCall](#functioncall)
|
- Parameter values are provided by a [Script](#script) through a [FunctionCall](#FunctionCall)
|
||||||
- Parameter names must be defined to be used in expressions such as [parameter substitution](#parameter-substitution)
|
- Parameter names must be defined to be used in expressions such as [parameter substitution](#parameter-substitution)
|
||||||
- ❗ Parameter names must be unique
|
- ❗ Parameter names must be unique
|
||||||
`code`: *`string`* (**required**)
|
`code`: *`string`* (**required**)
|
||||||
@@ -147,7 +147,7 @@ It would print "Hello world" if it's called in a [script](#script) as following:
|
|||||||
|
|
||||||
### `ScriptingDefinition`
|
### `ScriptingDefinition`
|
||||||
|
|
||||||
- Defines global properties for scripting that's used throughout the application file.
|
- Defines global properties for scripting that's used throughout its parent [Collection](#collection).
|
||||||
|
|
||||||
#### `ScriptingDefinition` syntax
|
#### `ScriptingDefinition` syntax
|
||||||
|
|
||||||
@@ -2,14 +2,15 @@ import { IApplication } from '@/domain/IApplication';
|
|||||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||||
import { parseCategoryCollection } from './CategoryCollectionParser';
|
import { parseCategoryCollection } from './CategoryCollectionParser';
|
||||||
import applicationFile, { YamlApplication } from 'js-yaml-loader!@/application/application.yaml';
|
import WindowsData from 'js-yaml-loader!@/application/collections/windows.yaml';
|
||||||
|
import { CollectionData } from 'js-yaml-loader!@/*';
|
||||||
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
||||||
import { Application } from '@/domain/Application';
|
import { Application } from '@/domain/Application';
|
||||||
|
|
||||||
export function parseApplication(
|
export function parseApplication(
|
||||||
parser = CategoryCollectionParser,
|
parser = CategoryCollectionParser,
|
||||||
processEnv: NodeJS.ProcessEnv = process.env,
|
processEnv: NodeJS.ProcessEnv = process.env,
|
||||||
collectionData = CollectionData): IApplication {
|
collectionData = LoadedCollectionData): IApplication {
|
||||||
const information = parseProjectInformation(processEnv);
|
const information = parseProjectInformation(processEnv);
|
||||||
const collection = parser(collectionData, information);
|
const collection = parser(collectionData, information);
|
||||||
const app = new Application(information, [ collection ]);
|
const app = new Application(information, [ collection ]);
|
||||||
@@ -17,11 +18,10 @@ export function parseApplication(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CategoryCollectionParserType
|
export type CategoryCollectionParserType
|
||||||
= (file: YamlApplication, info: IProjectInformation) => ICategoryCollection;
|
= (file: CollectionData, info: IProjectInformation) => ICategoryCollection;
|
||||||
|
|
||||||
const CategoryCollectionParser: CategoryCollectionParserType
|
const CategoryCollectionParser: CategoryCollectionParserType
|
||||||
= (file, info) => parseCategoryCollection(file, info);
|
= (file, info) => parseCategoryCollection(file, info);
|
||||||
|
|
||||||
const CollectionData: YamlApplication
|
const LoadedCollectionData: CollectionData
|
||||||
= applicationFile;
|
= WindowsData;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Category } from '@/domain/Category';
|
import { Category } from '@/domain/Category';
|
||||||
import { YamlApplication } from 'js-yaml-loader!@/application.yaml';
|
import { CollectionData } from 'js-yaml-loader!@/*';
|
||||||
import { parseCategory } from './CategoryParser';
|
import { parseCategory } from './CategoryParser';
|
||||||
import { ScriptCompiler } from './Compiler/ScriptCompiler';
|
import { ScriptCompiler } from './Compiler/ScriptCompiler';
|
||||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||||
@@ -10,7 +10,7 @@ import { CategoryCollection } from '@/domain/CategoryCollection';
|
|||||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||||
|
|
||||||
export function parseCategoryCollection(
|
export function parseCategoryCollection(
|
||||||
content: YamlApplication,
|
content: CollectionData,
|
||||||
info: IProjectInformation,
|
info: IProjectInformation,
|
||||||
osParser = createEnumParser(OperatingSystem)): ICategoryCollection {
|
osParser = createEnumParser(OperatingSystem)): ICategoryCollection {
|
||||||
validate(content);
|
validate(content);
|
||||||
@@ -29,7 +29,7 @@ export function parseCategoryCollection(
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate(content: YamlApplication): void {
|
function validate(content: CollectionData): void {
|
||||||
if (!content) {
|
if (!content) {
|
||||||
throw new Error('content is null or undefined');
|
throw new Error('content is null or undefined');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { YamlCategory, YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { CategoryData, ScriptData, CategoryOrScriptData } from 'js-yaml-loader!@/*';
|
||||||
import { Script } from '@/domain/Script';
|
import { Script } from '@/domain/Script';
|
||||||
import { Category } from '@/domain/Category';
|
import { Category } from '@/domain/Category';
|
||||||
import { parseDocUrls } from './DocumentationParser';
|
import { parseDocUrls } from './DocumentationParser';
|
||||||
@@ -12,7 +12,7 @@ interface ICategoryChildren {
|
|||||||
subScripts: Script[];
|
subScripts: Script[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseCategory(category: YamlCategory, compiler: IScriptCompiler): Category {
|
export function parseCategory(category: CategoryData, compiler: IScriptCompiler): Category {
|
||||||
if (!compiler) {
|
if (!compiler) {
|
||||||
throw new Error('undefined compiler');
|
throw new Error('undefined compiler');
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,8 @@ export function parseCategory(category: YamlCategory, compiler: IScriptCompiler)
|
|||||||
subCategories: new Array<Category>(),
|
subCategories: new Array<Category>(),
|
||||||
subScripts: new Array<Script>(),
|
subScripts: new Array<Script>(),
|
||||||
};
|
};
|
||||||
for (const categoryOrScript of category.children) {
|
for (const data of category.children) {
|
||||||
parseCategoryChild(categoryOrScript, children, category, compiler);
|
parseCategoryChild(data, children, category, compiler);
|
||||||
}
|
}
|
||||||
return new Category(
|
return new Category(
|
||||||
/*id*/ categoryIdCounter++,
|
/*id*/ categoryIdCounter++,
|
||||||
@@ -33,7 +33,7 @@ export function parseCategory(category: YamlCategory, compiler: IScriptCompiler)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureValid(category: YamlCategory) {
|
function ensureValid(category: CategoryData) {
|
||||||
if (!category) {
|
if (!category) {
|
||||||
throw Error('category is null or undefined');
|
throw Error('category is null or undefined');
|
||||||
}
|
}
|
||||||
@@ -46,28 +46,28 @@ function ensureValid(category: YamlCategory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseCategoryChild(
|
function parseCategoryChild(
|
||||||
categoryOrScript: any,
|
data: CategoryOrScriptData,
|
||||||
children: ICategoryChildren,
|
children: ICategoryChildren,
|
||||||
parent: YamlCategory,
|
parent: CategoryData,
|
||||||
compiler: IScriptCompiler) {
|
compiler: IScriptCompiler) {
|
||||||
if (isCategory(categoryOrScript)) {
|
if (isCategory(data)) {
|
||||||
const subCategory = parseCategory(categoryOrScript as YamlCategory, compiler);
|
const subCategory = parseCategory(data as CategoryData, compiler);
|
||||||
children.subCategories.push(subCategory);
|
children.subCategories.push(subCategory);
|
||||||
} else if (isScript(categoryOrScript)) {
|
} else if (isScript(data)) {
|
||||||
const yamlScript = categoryOrScript as YamlScript;
|
const scriptData = data as ScriptData;
|
||||||
const script = parseScript(yamlScript, compiler);
|
const script = parseScript(scriptData, compiler);
|
||||||
children.subScripts.push(script);
|
children.subScripts.push(script);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Child element is neither a category or a script.
|
throw new Error(`Child element is neither a category or a script.
|
||||||
Parent: ${parent.category}, element: ${JSON.stringify(categoryOrScript)}`);
|
Parent: ${parent.category}, element: ${JSON.stringify(data)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isScript(categoryOrScript: any): boolean {
|
function isScript(data: any): boolean {
|
||||||
return (categoryOrScript.code && categoryOrScript.code.length > 0)
|
return (data.code && data.code.length > 0)
|
||||||
|| categoryOrScript.call;
|
|| data.call;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCategory(categoryOrScript: any): boolean {
|
function isCategory(data: any): boolean {
|
||||||
return categoryOrScript.category && categoryOrScript.category.length > 0;
|
return data.category && data.category.length > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptData } from 'js-yaml-loader!@/*';
|
||||||
|
|
||||||
export interface IScriptCompiler {
|
export interface IScriptCompiler {
|
||||||
canCompile(script: YamlScript): boolean;
|
canCompile(script: ScriptData): boolean;
|
||||||
compile(script: YamlScript): IScriptCode;
|
compile(script: ScriptData): IScriptCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { generateIlCode, IILCode } from './ILCode';
|
import { generateIlCode, IILCode } from './ILCode';
|
||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { ScriptCode } from '@/domain/ScriptCode';
|
import { ScriptCode } from '@/domain/ScriptCode';
|
||||||
import { YamlScript, YamlFunction, FunctionCall, ScriptFunctionCall, FunctionCallParameters } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptData, FunctionData, FunctionCallData, ScriptFunctionCallData, FunctionCallParametersData } from 'js-yaml-loader!@/*';
|
||||||
import { IScriptCompiler } from './IScriptCompiler';
|
import { IScriptCompiler } from './IScriptCompiler';
|
||||||
|
|
||||||
interface ICompiledCode {
|
interface ICompiledCode {
|
||||||
@@ -10,16 +10,16 @@ interface ICompiledCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ScriptCompiler implements IScriptCompiler {
|
export class ScriptCompiler implements IScriptCompiler {
|
||||||
constructor(private readonly functions: readonly YamlFunction[]) {
|
constructor(private readonly functions: readonly FunctionData[]) {
|
||||||
ensureValidFunctions(functions);
|
ensureValidFunctions(functions);
|
||||||
}
|
}
|
||||||
public canCompile(script: YamlScript): boolean {
|
public canCompile(script: ScriptData): boolean {
|
||||||
if (!script.call) {
|
if (!script.call) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public compile(script: YamlScript): IScriptCode {
|
public compile(script: ScriptData): IScriptCode {
|
||||||
this.ensureCompilable(script.call);
|
this.ensureCompilable(script.call);
|
||||||
const compiledCodes = new Array<ICompiledCode>();
|
const compiledCodes = new Array<ICompiledCode>();
|
||||||
const calls = getCallSequence(script.call);
|
const calls = getCallSequence(script.call);
|
||||||
@@ -36,7 +36,7 @@ export class ScriptCompiler implements IScriptCompiler {
|
|||||||
return new ScriptCode(script.name, scriptCode.code, scriptCode.revertCode);
|
return new ScriptCode(script.name, scriptCode.code, scriptCode.revertCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFunctionByName(name: string): YamlFunction {
|
private getFunctionByName(name: string): FunctionData {
|
||||||
const func = this.functions.find((f) => f.name === name);
|
const func = this.functions.find((f) => f.name === name);
|
||||||
if (!func) {
|
if (!func) {
|
||||||
throw new Error(`called function is not defined "${name}"`);
|
throw new Error(`called function is not defined "${name}"`);
|
||||||
@@ -44,7 +44,7 @@ export class ScriptCompiler implements IScriptCompiler {
|
|||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureCompilable(call: ScriptFunctionCall) {
|
private ensureCompilable(call: ScriptFunctionCallData) {
|
||||||
if (!this.functions || this.functions.length === 0) {
|
if (!this.functions || this.functions.length === 0) {
|
||||||
throw new Error('cannot compile without shared functions');
|
throw new Error('cannot compile without shared functions');
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ function printList(list: readonly string[]): string {
|
|||||||
return `"${list.join('","')}"`;
|
return `"${list.join('","')}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoDuplicatesInFunctionNames(functions: readonly YamlFunction[]) {
|
function ensureNoDuplicatesInFunctionNames(functions: readonly FunctionData[]) {
|
||||||
const duplicateFunctionNames = getDuplicates(functions
|
const duplicateFunctionNames = getDuplicates(functions
|
||||||
.map((func) => func.name.toLowerCase()));
|
.map((func) => func.name.toLowerCase()));
|
||||||
if (duplicateFunctionNames.length) {
|
if (duplicateFunctionNames.length) {
|
||||||
@@ -70,7 +70,7 @@ function ensureNoDuplicatesInFunctionNames(functions: readonly YamlFunction[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoDuplicatesInParameterNames(functions: readonly YamlFunction[]) {
|
function ensureNoDuplicatesInParameterNames(functions: readonly FunctionData[]) {
|
||||||
const functionsWithParameters = functions
|
const functionsWithParameters = functions
|
||||||
.filter((func) => func.parameters && func.parameters.length > 0);
|
.filter((func) => func.parameters && func.parameters.length > 0);
|
||||||
for (const func of functionsWithParameters) {
|
for (const func of functionsWithParameters) {
|
||||||
@@ -81,7 +81,7 @@ function ensureNoDuplicatesInParameterNames(functions: readonly YamlFunction[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoDuplicateCode(functions: readonly YamlFunction[]) {
|
function ensureNoDuplicateCode(functions: readonly FunctionData[]) {
|
||||||
const duplicateCodes = getDuplicates(functions.map((func) => func.code));
|
const duplicateCodes = getDuplicates(functions.map((func) => func.code));
|
||||||
if (duplicateCodes.length > 0) {
|
if (duplicateCodes.length > 0) {
|
||||||
throw new Error(`duplicate "code" in functions: ${printList(duplicateCodes)}`);
|
throw new Error(`duplicate "code" in functions: ${printList(duplicateCodes)}`);
|
||||||
@@ -94,7 +94,7 @@ function ensureNoDuplicateCode(functions: readonly YamlFunction[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureValidFunctions(functions: readonly YamlFunction[]) {
|
function ensureValidFunctions(functions: readonly FunctionData[]) {
|
||||||
if (!functions) {
|
if (!functions) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -118,20 +118,20 @@ function merge(codes: readonly ICompiledCode[]): ICompiledCode {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileCode(func: YamlFunction, parameters: FunctionCallParameters): ICompiledCode {
|
function compileCode(func: FunctionData, parameters: FunctionCallParametersData): ICompiledCode {
|
||||||
return {
|
return {
|
||||||
code: compileExpressions(func.code, parameters),
|
code: compileExpressions(func.code, parameters),
|
||||||
revertCode: compileExpressions(func.revertCode, parameters),
|
revertCode: compileExpressions(func.revertCode, parameters),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileExpressions(code: string, parameters: FunctionCallParameters): string {
|
function compileExpressions(code: string, parameters: FunctionCallParametersData): string {
|
||||||
let intermediateCode = generateIlCode(code);
|
let intermediateCode = generateIlCode(code);
|
||||||
intermediateCode = substituteParameters(intermediateCode, parameters);
|
intermediateCode = substituteParameters(intermediateCode, parameters);
|
||||||
return intermediateCode.compile();
|
return intermediateCode.compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
function substituteParameters(intermediateCode: IILCode, parameters: FunctionCallParameters): IILCode {
|
function substituteParameters(intermediateCode: IILCode, parameters: FunctionCallParametersData): IILCode {
|
||||||
const parameterNames = intermediateCode.getUniqueParameterNames();
|
const parameterNames = intermediateCode.getUniqueParameterNames();
|
||||||
if (parameterNames.length && !parameters) {
|
if (parameterNames.length && !parameters) {
|
||||||
throw new Error(`no parameters defined, expected: ${printList(parameterNames)}`);
|
throw new Error(`no parameters defined, expected: ${printList(parameterNames)}`);
|
||||||
@@ -146,7 +146,7 @@ function substituteParameters(intermediateCode: IILCode, parameters: FunctionCal
|
|||||||
return intermediateCode;
|
return intermediateCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureValidCall(call: FunctionCall, scriptName: string) {
|
function ensureValidCall(call: FunctionCallData, scriptName: string) {
|
||||||
if (!call) {
|
if (!call) {
|
||||||
throw new Error(`undefined function call in script "${scriptName}"`);
|
throw new Error(`undefined function call in script "${scriptName}"`);
|
||||||
}
|
}
|
||||||
@@ -155,9 +155,9 @@ function ensureValidCall(call: FunctionCall, scriptName: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCallSequence(call: ScriptFunctionCall): FunctionCall[] {
|
function getCallSequence(call: ScriptFunctionCallData): FunctionCallData[] {
|
||||||
if (call instanceof Array) {
|
if (call instanceof Array) {
|
||||||
return call as FunctionCall[];
|
return call as FunctionCallData[];
|
||||||
}
|
}
|
||||||
return [ call as FunctionCall ];
|
return [ call as FunctionCallData ];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { YamlDocumentable, DocumentationUrls } from 'js-yaml-loader!./application.yaml';
|
import { DocumentableData, DocumentationUrlsData } from 'js-yaml-loader!@/*';
|
||||||
|
|
||||||
export function parseDocUrls(documentable: YamlDocumentable): ReadonlyArray<string> {
|
export function parseDocUrls(documentable: DocumentableData): ReadonlyArray<string> {
|
||||||
if (!documentable) {
|
if (!documentable) {
|
||||||
throw new Error('documentable is null or undefined');
|
throw new Error('documentable is null or undefined');
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ export function parseDocUrls(documentable: YamlDocumentable): ReadonlyArray<stri
|
|||||||
return result.getAll();
|
return result.getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDocs(docs: DocumentationUrls, urls: DocumentationUrlContainer): DocumentationUrlContainer {
|
function addDocs(docs: DocumentationUrlsData, urls: DocumentationUrlContainer): DocumentationUrlContainer {
|
||||||
if (docs instanceof Array) {
|
if (docs instanceof Array) {
|
||||||
urls.addUrls(docs);
|
urls.addUrls(docs);
|
||||||
} else if (typeof docs === 'string') {
|
} else if (typeof docs === 'string') {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Script } from '@/domain/Script';
|
import { Script } from '@/domain/Script';
|
||||||
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptData } from 'js-yaml-loader!@/*';
|
||||||
import { parseDocUrls } from './DocumentationParser';
|
import { parseDocUrls } from './DocumentationParser';
|
||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
import { IScriptCompiler } from './Compiler/IScriptCompiler';
|
import { IScriptCompiler } from './Compiler/IScriptCompiler';
|
||||||
@@ -8,17 +8,17 @@ import { ScriptCode } from '@/domain/ScriptCode';
|
|||||||
import { createEnumParser, IEnumParser } from '../Common/Enum';
|
import { createEnumParser, IEnumParser } from '../Common/Enum';
|
||||||
|
|
||||||
export function parseScript(
|
export function parseScript(
|
||||||
yamlScript: YamlScript, compiler: IScriptCompiler,
|
data: ScriptData, compiler: IScriptCompiler,
|
||||||
levelParser = createEnumParser(RecommendationLevel)): Script {
|
levelParser = createEnumParser(RecommendationLevel)): Script {
|
||||||
validateScript(yamlScript);
|
validateScript(data);
|
||||||
if (!compiler) {
|
if (!compiler) {
|
||||||
throw new Error('undefined compiler');
|
throw new Error('undefined compiler');
|
||||||
}
|
}
|
||||||
const script = new Script(
|
const script = new Script(
|
||||||
/* name */ yamlScript.name,
|
/* name */ data.name,
|
||||||
/* code */ parseCode(yamlScript, compiler),
|
/* code */ parseCode(data, compiler),
|
||||||
/* docs */ parseDocUrls(yamlScript),
|
/* docs */ parseDocUrls(data),
|
||||||
/* level */ parseLevel(yamlScript.recommend, levelParser));
|
/* level */ parseLevel(data.recommend, levelParser));
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,28 +29,28 @@ function parseLevel(level: string, parser: IEnumParser<RecommendationLevel>): Re
|
|||||||
return parser.parseEnum(level, 'level');
|
return parser.parseEnum(level, 'level');
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCode(yamlScript: YamlScript, compiler: IScriptCompiler): IScriptCode {
|
function parseCode(script: ScriptData, compiler: IScriptCompiler): IScriptCode {
|
||||||
if (compiler.canCompile(yamlScript)) {
|
if (compiler.canCompile(script)) {
|
||||||
return compiler.compile(yamlScript);
|
return compiler.compile(script);
|
||||||
}
|
}
|
||||||
return new ScriptCode(yamlScript.name, yamlScript.code, yamlScript.revertCode);
|
return new ScriptCode(script.name, script.code, script.revertCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNotBothCallAndCode(yamlScript: YamlScript) {
|
function ensureNotBothCallAndCode(script: ScriptData) {
|
||||||
if (yamlScript.code && yamlScript.call) {
|
if (script.code && script.call) {
|
||||||
throw new Error('cannot define both "call" and "code"');
|
throw new Error('cannot define both "call" and "code"');
|
||||||
}
|
}
|
||||||
if (yamlScript.revertCode && yamlScript.call) {
|
if (script.revertCode && script.call) {
|
||||||
throw new Error('cannot define "revertCode" if "call" is defined');
|
throw new Error('cannot define "revertCode" if "call" is defined');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateScript(yamlScript: YamlScript) {
|
function validateScript(script: ScriptData) {
|
||||||
if (!yamlScript) {
|
if (!script) {
|
||||||
throw new Error('undefined script');
|
throw new Error('undefined script');
|
||||||
}
|
}
|
||||||
if (!yamlScript.code && !yamlScript.call) {
|
if (!script.code && !script.call) {
|
||||||
throw new Error('must define either "call" or "code"');
|
throw new Error('must define either "call" or "code"');
|
||||||
}
|
}
|
||||||
ensureNotBothCallAndCode(yamlScript);
|
ensureNotBothCallAndCode(script);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||||
import { YamlScriptingDefinition } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptingDefinitionData } from 'js-yaml-loader!@/*';
|
||||||
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||||
@@ -7,7 +7,7 @@ import { createEnumParser } from '../Common/Enum';
|
|||||||
import { generateIlCode } from './Compiler/ILCode';
|
import { generateIlCode } from './Compiler/ILCode';
|
||||||
|
|
||||||
export function parseScriptingDefinition(
|
export function parseScriptingDefinition(
|
||||||
definition: YamlScriptingDefinition,
|
definition: ScriptingDefinitionData,
|
||||||
info: IProjectInformation,
|
info: IProjectInformation,
|
||||||
date = new Date(),
|
date = new Date(),
|
||||||
languageParser = createEnumParser(ScriptingLanguage)): IScriptingDefinition {
|
languageParser = createEnumParser(ScriptingLanguage)): IScriptingDefinition {
|
||||||
|
|||||||
56
src/application/application.yaml.d.ts
vendored
56
src/application/application.yaml.d.ts
vendored
@@ -1,56 +0,0 @@
|
|||||||
declare module 'js-yaml-loader!*' {
|
|
||||||
export interface YamlApplication {
|
|
||||||
readonly os: string;
|
|
||||||
readonly scripting: YamlScriptingDefinition;
|
|
||||||
readonly actions: ReadonlyArray<YamlCategory>;
|
|
||||||
readonly functions?: ReadonlyArray<YamlFunction>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface YamlCategory extends YamlDocumentable {
|
|
||||||
readonly children: ReadonlyArray<CategoryOrScript>;
|
|
||||||
readonly category: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CategoryOrScript = YamlCategory | YamlScript;
|
|
||||||
export type DocumentationUrls = ReadonlyArray<string> | string;
|
|
||||||
|
|
||||||
export interface YamlDocumentable {
|
|
||||||
readonly docs?: DocumentationUrls;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface YamlFunction {
|
|
||||||
name: string;
|
|
||||||
code: string;
|
|
||||||
revertCode?: string;
|
|
||||||
parameters?: readonly string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FunctionCallParameters {
|
|
||||||
[index: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FunctionCall {
|
|
||||||
function: string;
|
|
||||||
parameters?: FunctionCallParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ScriptFunctionCall = readonly FunctionCall[] | FunctionCall | undefined;
|
|
||||||
|
|
||||||
export interface YamlScript extends YamlDocumentable {
|
|
||||||
name: string;
|
|
||||||
code: string | undefined;
|
|
||||||
revertCode: string | undefined;
|
|
||||||
call: ScriptFunctionCall;
|
|
||||||
recommend: string | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface YamlScriptingDefinition {
|
|
||||||
readonly language: string;
|
|
||||||
readonly fileExtension: string;
|
|
||||||
readonly startCode: string;
|
|
||||||
readonly endCode: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const content: YamlApplication;
|
|
||||||
export default content;
|
|
||||||
}
|
|
||||||
56
src/application/collections/collection.yaml.d.ts
vendored
Normal file
56
src/application/collections/collection.yaml.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
declare module 'js-yaml-loader!*' {
|
||||||
|
export interface CollectionData {
|
||||||
|
readonly os: string;
|
||||||
|
readonly scripting: ScriptingDefinitionData;
|
||||||
|
readonly actions: ReadonlyArray<CategoryData>;
|
||||||
|
readonly functions?: ReadonlyArray<FunctionData>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CategoryData extends DocumentableData {
|
||||||
|
readonly children: ReadonlyArray<CategoryOrScriptData>;
|
||||||
|
readonly category: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CategoryOrScriptData = CategoryData | ScriptData;
|
||||||
|
export type DocumentationUrlsData = ReadonlyArray<string> | string;
|
||||||
|
|
||||||
|
export interface DocumentableData {
|
||||||
|
readonly docs?: DocumentationUrlsData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FunctionData {
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
revertCode?: string;
|
||||||
|
parameters?: readonly string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FunctionCallParametersData {
|
||||||
|
[index: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FunctionCallData {
|
||||||
|
function: string;
|
||||||
|
parameters?: FunctionCallParametersData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ScriptFunctionCallData = readonly FunctionCallData[] | FunctionCallData | undefined;
|
||||||
|
|
||||||
|
export interface ScriptData extends DocumentableData {
|
||||||
|
name: string;
|
||||||
|
code: string | undefined;
|
||||||
|
revertCode: string | undefined;
|
||||||
|
call: ScriptFunctionCallData;
|
||||||
|
recommend: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScriptingDefinitionData {
|
||||||
|
readonly language: string;
|
||||||
|
readonly fileExtension: string;
|
||||||
|
readonly startCode: string;
|
||||||
|
readonly endCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const content: CollectionData;
|
||||||
|
export default content;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Structure documented in "docs/application-file.md"
|
# Structure documented in "docs/collections.md"
|
||||||
os: windows
|
os: windows
|
||||||
scripting:
|
scripting:
|
||||||
language: batchfile
|
language: batchfile
|
||||||
@@ -1333,32 +1333,6 @@ actions:
|
|||||||
docs: https://www.tenforums.com/tutorials/4077-turn-off-sync-settings-microsoft-account-windows-10-a.html
|
docs: https://www.tenforums.com/tutorials/4077-turn-off-sync-settings-microsoft-account-windows-10-a.html
|
||||||
code: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 0 /f
|
code: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 0 /f
|
||||||
revertCode: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 1 /f
|
revertCode: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 1 /f
|
||||||
-
|
|
||||||
category: Prevent Microsoft family safety monitoring
|
|
||||||
children:
|
|
||||||
-
|
|
||||||
name: Disable Microsoft Family Safety Monitor
|
|
||||||
recommend: standard
|
|
||||||
code: |-
|
|
||||||
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyMonitor"
|
|
||||||
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyRefresh"
|
|
||||||
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyUpload"
|
|
||||||
revertCode: |-
|
|
||||||
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyMonitor"
|
|
||||||
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyRefresh"
|
|
||||||
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyUpload"
|
|
||||||
-
|
|
||||||
name: Uninstall Microsoft Family Safety Monitor
|
|
||||||
recommend: strict
|
|
||||||
call:
|
|
||||||
-
|
|
||||||
function: RenameSystemFile
|
|
||||||
parameters:
|
|
||||||
filePath: '%SystemRoot%\System32\WpcTok.exe'
|
|
||||||
-
|
|
||||||
function: RenameSystemFile
|
|
||||||
parameters:
|
|
||||||
filePath: '%SystemRoot%\System32\WpcMon.exe'
|
|
||||||
-
|
-
|
||||||
category: Configure programs
|
category: Configure programs
|
||||||
children:
|
children:
|
||||||
@@ -2,14 +2,15 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
||||||
import { CategoryCollectionParserType, parseApplication } from '@/application/Parser/ApplicationParser';
|
import { CategoryCollectionParserType, parseApplication } from '@/application/Parser/ApplicationParser';
|
||||||
import applicationFile, { YamlApplication } from 'js-yaml-loader!@/application/application.yaml';
|
import WindowsData from 'js-yaml-loader!@/application/collections/windows.yaml';
|
||||||
|
import { CollectionData } from 'js-yaml-loader!@/*';
|
||||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||||
import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
|
||||||
import { getProcessEnvironmentStub } from '../../stubs/ProcessEnvironmentStub';
|
import { getProcessEnvironmentStub } from '../../stubs/ProcessEnvironmentStub';
|
||||||
import { YamlApplicationStub } from '../../stubs/YamlApplicationStub';
|
import { CollectionDataStub } from '../../stubs/CollectionDataStub';
|
||||||
|
|
||||||
describe('ApplicationParser', () => {
|
describe('ApplicationParser', () => {
|
||||||
describe('parseApplication', () => {
|
describe('parseApplication', () => {
|
||||||
@@ -64,7 +65,7 @@ describe('ApplicationParser', () => {
|
|||||||
describe('collectionData', () => {
|
describe('collectionData', () => {
|
||||||
it('parsed with expected data', () => {
|
it('parsed with expected data', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = new YamlApplicationStub();
|
const expected = new CollectionDataStub();
|
||||||
const env = getProcessEnvironmentStub();
|
const env = getProcessEnvironmentStub();
|
||||||
const parserSpy = new CategoryCollectionParserSpy();
|
const parserSpy = new CategoryCollectionParserSpy();
|
||||||
const parserMock = parserSpy.mockParser();
|
const parserMock = parserSpy.mockParser();
|
||||||
@@ -73,9 +74,9 @@ describe('ApplicationParser', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(expected).to.equal(parserSpy.lastArguments.file);
|
expect(expected).to.equal(parserSpy.lastArguments.file);
|
||||||
});
|
});
|
||||||
it('defaults to applicationFile', () => {
|
it('defaults to windows data', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = applicationFile;
|
const expected = WindowsData;
|
||||||
const parserSpy = new CategoryCollectionParserSpy();
|
const parserSpy = new CategoryCollectionParserSpy();
|
||||||
const parserMock = parserSpy.mockParser();
|
const parserMock = parserSpy.mockParser();
|
||||||
// act
|
// act
|
||||||
@@ -89,7 +90,7 @@ describe('ApplicationParser', () => {
|
|||||||
|
|
||||||
class CategoryCollectionParserSpy {
|
class CategoryCollectionParserSpy {
|
||||||
public lastArguments: {
|
public lastArguments: {
|
||||||
file: YamlApplication;
|
file: CollectionData;
|
||||||
info: ProjectInformation;
|
info: ProjectInformation;
|
||||||
} = { file: undefined, info: undefined };
|
} = { file: undefined, info: undefined };
|
||||||
private result: ICategoryCollection = new CategoryCollectionStub();
|
private result: ICategoryCollection = new CategoryCollectionStub();
|
||||||
@@ -99,7 +100,7 @@ class CategoryCollectionParserSpy {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public mockParser(): CategoryCollectionParserType {
|
public mockParser(): CategoryCollectionParserType {
|
||||||
return (file: YamlApplication, info: IProjectInformation) => {
|
return (file: CollectionData, info: IProjectInformation) => {
|
||||||
this.lastArguments.file = file;
|
this.lastArguments.file = file;
|
||||||
this.lastArguments.info = info;
|
this.lastArguments.info = info;
|
||||||
return this.result;
|
return this.result;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefiniti
|
|||||||
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
||||||
import { ProjectInformationStub } from '../../stubs/ProjectInformationStub';
|
import { ProjectInformationStub } from '../../stubs/ProjectInformationStub';
|
||||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||||
import { getCategoryStub, YamlApplicationStub } from '../../stubs/YamlApplicationStub';
|
import { getCategoryStub, CollectionDataStub } from '../../stubs/CollectionDataStub';
|
||||||
|
|
||||||
describe('CategoryCollectionParser', () => {
|
describe('CategoryCollectionParser', () => {
|
||||||
describe('parseCategoryCollection', () => {
|
describe('parseCategoryCollection', () => {
|
||||||
@@ -26,7 +26,7 @@ describe('CategoryCollectionParser', () => {
|
|||||||
it('throws when undefined actions', () => {
|
it('throws when undefined actions', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'content does not define any action';
|
const expectedError = 'content does not define any action';
|
||||||
const collection = new YamlApplicationStub()
|
const collection = new CollectionDataStub()
|
||||||
.withActions(undefined);
|
.withActions(undefined);
|
||||||
const info = new ProjectInformationStub();
|
const info = new ProjectInformationStub();
|
||||||
// act
|
// act
|
||||||
@@ -37,7 +37,7 @@ describe('CategoryCollectionParser', () => {
|
|||||||
it('throws when has no actions', () => {
|
it('throws when has no actions', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'content does not define any action';
|
const expectedError = 'content does not define any action';
|
||||||
const collection = new YamlApplicationStub()
|
const collection = new CollectionDataStub()
|
||||||
.withActions([]);
|
.withActions([]);
|
||||||
const info = new ProjectInformationStub();
|
const info = new ProjectInformationStub();
|
||||||
// act
|
// act
|
||||||
@@ -50,7 +50,7 @@ describe('CategoryCollectionParser', () => {
|
|||||||
const actions = [ getCategoryStub('test1'), getCategoryStub('test2') ];
|
const actions = [ getCategoryStub('test1'), getCategoryStub('test2') ];
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
|
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
|
||||||
const collection = new YamlApplicationStub()
|
const collection = new CollectionDataStub()
|
||||||
.withActions(actions);
|
.withActions(actions);
|
||||||
const info = new ProjectInformationStub();
|
const info = new ProjectInformationStub();
|
||||||
// act
|
// act
|
||||||
@@ -68,7 +68,7 @@ describe('CategoryCollectionParser', () => {
|
|||||||
describe('scripting definition', () => {
|
describe('scripting definition', () => {
|
||||||
it('parses scripting definition as expected', () => {
|
it('parses scripting definition as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const collection = new YamlApplicationStub();
|
const collection = new CollectionDataStub();
|
||||||
const information = parseProjectInformation(process.env);
|
const information = parseProjectInformation(process.env);
|
||||||
const expected = parseScriptingDefinition(collection.scripting, information);
|
const expected = parseScriptingDefinition(collection.scripting, information);
|
||||||
// act
|
// act
|
||||||
@@ -83,7 +83,7 @@ describe('CategoryCollectionParser', () => {
|
|||||||
const expectedOs = OperatingSystem.macOS;
|
const expectedOs = OperatingSystem.macOS;
|
||||||
const osText = 'macos';
|
const osText = 'macos';
|
||||||
const expectedName = 'os';
|
const expectedName = 'os';
|
||||||
const collection = new YamlApplicationStub()
|
const collection = new CollectionDataStub()
|
||||||
.withOs(osText);
|
.withOs(osText);
|
||||||
const parserMock = mockEnumParser(expectedName, osText, expectedOs);
|
const parserMock = mockEnumParser(expectedName, osText, expectedOs);
|
||||||
const info = new ProjectInformationStub();
|
const info = new ProjectInformationStub();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||||
import { YamlCategory, CategoryOrScript, YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { CategoryData, CategoryOrScriptData } from 'js-yaml-loader!@/*';
|
||||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
|
||||||
|
|
||||||
describe('CategoryParser', () => {
|
describe('CategoryParser', () => {
|
||||||
describe('parseCategory', () => {
|
describe('parseCategory', () => {
|
||||||
@@ -24,7 +24,7 @@ describe('CategoryParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const categoryName = 'test';
|
const categoryName = 'test';
|
||||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
const expectedMessage = `category has no children: "${categoryName}"`;
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: categoryName,
|
category: categoryName,
|
||||||
children: [],
|
children: [],
|
||||||
};
|
};
|
||||||
@@ -38,7 +38,7 @@ describe('CategoryParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const categoryName = 'test';
|
const categoryName = 'test';
|
||||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
const expectedMessage = `category has no children: "${categoryName}"`;
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: categoryName,
|
category: categoryName,
|
||||||
children: undefined,
|
children: undefined,
|
||||||
};
|
};
|
||||||
@@ -53,7 +53,7 @@ describe('CategoryParser', () => {
|
|||||||
const expectedMessage = 'category has no name';
|
const expectedMessage = 'category has no name';
|
||||||
const invalidNames = ['', undefined];
|
const invalidNames = ['', undefined];
|
||||||
invalidNames.forEach((invalidName) => {
|
invalidNames.forEach((invalidName) => {
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: invalidName,
|
category: invalidName,
|
||||||
children: getTestChildren(),
|
children: getTestChildren(),
|
||||||
};
|
};
|
||||||
@@ -80,7 +80,7 @@ describe('CategoryParser', () => {
|
|||||||
const url = 'https://privacy.sexy';
|
const url = 'https://privacy.sexy';
|
||||||
const expected = parseDocUrls({ docs: url });
|
const expected = parseDocUrls({ docs: url });
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: getTestChildren(),
|
children: getTestChildren(),
|
||||||
docs: url,
|
docs: url,
|
||||||
@@ -93,10 +93,10 @@ describe('CategoryParser', () => {
|
|||||||
describe('parses expected subscript', () => {
|
describe('parses expected subscript', () => {
|
||||||
it('single script with code', () => {
|
it('single script with code', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const script = YamlScriptStub.createWithCode();
|
const script = ScriptDataStub.createWithCode();
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const expected = [ parseScript(script, compiler) ];
|
const expected = [ parseScript(script, compiler) ];
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: [ script ],
|
children: [ script ],
|
||||||
};
|
};
|
||||||
@@ -107,11 +107,11 @@ describe('CategoryParser', () => {
|
|||||||
});
|
});
|
||||||
it('single script with function call', () => {
|
it('single script with function call', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const script = YamlScriptStub.createWithCall();
|
const script = ScriptDataStub.createWithCall();
|
||||||
const compiler = new ScriptCompilerStub()
|
const compiler = new ScriptCompilerStub()
|
||||||
.withCompileAbility(script);
|
.withCompileAbility(script);
|
||||||
const expected = [ parseScript(script, compiler) ];
|
const expected = [ parseScript(script, compiler) ];
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: [ script ],
|
children: [ script ],
|
||||||
};
|
};
|
||||||
@@ -122,12 +122,12 @@ describe('CategoryParser', () => {
|
|||||||
});
|
});
|
||||||
it('multiple scripts with function call and code', () => {
|
it('multiple scripts with function call and code', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const callableScript = YamlScriptStub.createWithCall();
|
const callableScript = ScriptDataStub.createWithCall();
|
||||||
const scripts = [ callableScript, YamlScriptStub.createWithCode() ];
|
const scripts = [ callableScript, ScriptDataStub.createWithCode() ];
|
||||||
const compiler = new ScriptCompilerStub()
|
const compiler = new ScriptCompilerStub()
|
||||||
.withCompileAbility(callableScript);
|
.withCompileAbility(callableScript);
|
||||||
const expected = scripts.map((script) => parseScript(script, compiler));
|
const expected = scripts.map((script) => parseScript(script, compiler));
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: scripts,
|
children: scripts,
|
||||||
};
|
};
|
||||||
@@ -139,11 +139,11 @@ describe('CategoryParser', () => {
|
|||||||
});
|
});
|
||||||
it('returns expected subcategories', () => {
|
it('returns expected subcategories', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected: YamlCategory[] = [ {
|
const expected: CategoryData[] = [ {
|
||||||
category: 'test category',
|
category: 'test category',
|
||||||
children: [ YamlScriptStub.createWithCode() ],
|
children: [ ScriptDataStub.createWithCode() ],
|
||||||
}];
|
}];
|
||||||
const category: YamlCategory = {
|
const category: CategoryData = {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: expected,
|
children: expected,
|
||||||
};
|
};
|
||||||
@@ -158,7 +158,7 @@ describe('CategoryParser', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getValidCategory(): YamlCategory {
|
function getValidCategory(): CategoryData {
|
||||||
return {
|
return {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: getTestChildren(),
|
children: getTestChildren(),
|
||||||
@@ -166,8 +166,8 @@ function getValidCategory(): YamlCategory {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
|
function getTestChildren(): ReadonlyArray<CategoryOrScriptData> {
|
||||||
return [
|
return [
|
||||||
YamlScriptStub.createWithCode(),
|
ScriptDataStub.createWithCode(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ScriptCompiler } from '@/application/Parser/Compiler/ScriptCompiler';
|
import { ScriptCompiler } from '@/application/Parser/Compiler/ScriptCompiler';
|
||||||
import { YamlScriptStub } from '../../../stubs/YamlScriptStub';
|
import { ScriptDataStub } from '../../../stubs/ScriptDataStub';
|
||||||
import { YamlFunction, YamlScript, FunctionCall, ScriptFunctionCall, FunctionCallParameters } from 'js-yaml-loader!@/application.yaml';
|
import { FunctionData, ScriptData, FunctionCallData, ScriptFunctionCallData, FunctionCallParametersData } from 'js-yaml-loader!@/*';
|
||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ describe('ScriptCompiler', () => {
|
|||||||
it('throws when functions have same names', () => {
|
it('throws when functions have same names', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = `duplicate function name: "same-func-name"`;
|
const expectedError = `duplicate function name: "same-func-name"`;
|
||||||
const functions: YamlFunction[] = [ {
|
const functions: FunctionData[] = [ {
|
||||||
name: 'same-func-name',
|
name: 'same-func-name',
|
||||||
code: 'non-empty-code',
|
code: 'non-empty-code',
|
||||||
}, {
|
}, {
|
||||||
@@ -25,7 +25,7 @@ describe('ScriptCompiler', () => {
|
|||||||
});
|
});
|
||||||
it('throws when function parameters have same names', () => {
|
it('throws when function parameters have same names', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const func: YamlFunction = {
|
const func: FunctionData = {
|
||||||
name: 'function-name',
|
name: 'function-name',
|
||||||
code: 'non-empty-code',
|
code: 'non-empty-code',
|
||||||
parameters: [ 'duplicate', 'duplicate' ],
|
parameters: [ 'duplicate', 'duplicate' ],
|
||||||
@@ -40,7 +40,7 @@ describe('ScriptCompiler', () => {
|
|||||||
it('code', () => {
|
it('code', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = `duplicate "code" in functions: "duplicate-code"`;
|
const expectedError = `duplicate "code" in functions: "duplicate-code"`;
|
||||||
const functions: YamlFunction[] = [ {
|
const functions: FunctionData[] = [ {
|
||||||
name: 'func-1',
|
name: 'func-1',
|
||||||
code: 'duplicate-code',
|
code: 'duplicate-code',
|
||||||
}, {
|
}, {
|
||||||
@@ -55,7 +55,7 @@ describe('ScriptCompiler', () => {
|
|||||||
it('revertCode', () => {
|
it('revertCode', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = `duplicate "revertCode" in functions: "duplicate-revert-code"`;
|
const expectedError = `duplicate "revertCode" in functions: "duplicate-revert-code"`;
|
||||||
const functions: YamlFunction[] = [ {
|
const functions: FunctionData[] = [ {
|
||||||
name: 'func-1',
|
name: 'func-1',
|
||||||
code: 'code-1',
|
code: 'code-1',
|
||||||
revertCode: 'duplicate-revert-code',
|
revertCode: 'duplicate-revert-code',
|
||||||
@@ -75,7 +75,7 @@ describe('ScriptCompiler', () => {
|
|||||||
it('returns true if "call" is defined', () => {
|
it('returns true if "call" is defined', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const sut = new ScriptCompiler([]);
|
const sut = new ScriptCompiler([]);
|
||||||
const script = YamlScriptStub.createWithCall();
|
const script = ScriptDataStub.createWithCall();
|
||||||
// act
|
// act
|
||||||
const actual = sut.canCompile(script);
|
const actual = sut.canCompile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -84,7 +84,7 @@ describe('ScriptCompiler', () => {
|
|||||||
it('returns false if "call" is undefined', () => {
|
it('returns false if "call" is undefined', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const sut = new ScriptCompiler([]);
|
const sut = new ScriptCompiler([]);
|
||||||
const script = YamlScriptStub.createWithCode();
|
const script = ScriptDataStub.createWithCode();
|
||||||
// act
|
// act
|
||||||
const actual = sut.canCompile(script);
|
const actual = sut.canCompile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -98,7 +98,7 @@ describe('ScriptCompiler', () => {
|
|||||||
const expectedError = 'cannot compile without shared functions';
|
const expectedError = 'cannot compile without shared functions';
|
||||||
const functions = [];
|
const functions = [];
|
||||||
const sut = new ScriptCompiler(functions);
|
const sut = new ScriptCompiler(functions);
|
||||||
const script = YamlScriptStub.createWithCall();
|
const script = ScriptDataStub.createWithCall();
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(script);
|
const act = () => sut.compile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -110,7 +110,7 @@ describe('ScriptCompiler', () => {
|
|||||||
const invalidValues = [undefined, 'string', 33];
|
const invalidValues = [undefined, 'string', 33];
|
||||||
const sut = new ScriptCompiler(createFunctions());
|
const sut = new ScriptCompiler(createFunctions());
|
||||||
invalidValues.forEach((invalidValue) => {
|
invalidValues.forEach((invalidValue) => {
|
||||||
const script = YamlScriptStub.createWithoutCallOrCodes() // because call ctor overwrites "undefined"
|
const script = ScriptDataStub.createWithoutCallOrCodes() // because call ctor overwrites "undefined"
|
||||||
.withCall(invalidValue as any);
|
.withCall(invalidValue as any);
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(script);
|
const act = () => sut.compile(script);
|
||||||
@@ -124,8 +124,8 @@ describe('ScriptCompiler', () => {
|
|||||||
const sut = new ScriptCompiler(createFunctions());
|
const sut = new ScriptCompiler(createFunctions());
|
||||||
const nonExistingFunctionName = 'non-existing-func';
|
const nonExistingFunctionName = 'non-existing-func';
|
||||||
const expectedError = `called function is not defined "${nonExistingFunctionName}"`;
|
const expectedError = `called function is not defined "${nonExistingFunctionName}"`;
|
||||||
const call: ScriptFunctionCall = { function: nonExistingFunctionName };
|
const call: ScriptFunctionCallData = { function: nonExistingFunctionName };
|
||||||
const script = YamlScriptStub.createWithCall(call);
|
const script = ScriptDataStub.createWithCall(call);
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(script);
|
const act = () => sut.compile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -135,11 +135,11 @@ describe('ScriptCompiler', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const existingFunctionName = 'existing-func';
|
const existingFunctionName = 'existing-func';
|
||||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||||
const call: ScriptFunctionCall = [
|
const call: ScriptFunctionCallData = [
|
||||||
{ function: existingFunctionName },
|
{ function: existingFunctionName },
|
||||||
undefined,
|
undefined,
|
||||||
];
|
];
|
||||||
const script = YamlScriptStub.createWithCall(call);
|
const script = ScriptDataStub.createWithCall(call);
|
||||||
const expectedError = `undefined function call in script "${script.name}"`;
|
const expectedError = `undefined function call in script "${script.name}"`;
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(script);
|
const act = () => sut.compile(script);
|
||||||
@@ -150,10 +150,10 @@ describe('ScriptCompiler', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const existingFunctionName = 'existing-func';
|
const existingFunctionName = 'existing-func';
|
||||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||||
const call: FunctionCall[] = [
|
const call: FunctionCallData[] = [
|
||||||
{ function: existingFunctionName },
|
{ function: existingFunctionName },
|
||||||
{ function: undefined }];
|
{ function: undefined }];
|
||||||
const script = YamlScriptStub.createWithCall(call);
|
const script = ScriptDataStub.createWithCall(call);
|
||||||
const expectedError = `empty function name called in script "${script.name}"`;
|
const expectedError = `empty function name called in script "${script.name}"`;
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(script);
|
const act = () => sut.compile(script);
|
||||||
@@ -170,15 +170,15 @@ describe('ScriptCompiler', () => {
|
|||||||
execute: 'expected-code',
|
execute: 'expected-code',
|
||||||
revert: 'expected-revert-code',
|
revert: 'expected-revert-code',
|
||||||
};
|
};
|
||||||
const func: YamlFunction = {
|
const func: FunctionData = {
|
||||||
name: functionName,
|
name: functionName,
|
||||||
parameters: [],
|
parameters: [],
|
||||||
code: expected.execute,
|
code: expected.execute,
|
||||||
revertCode: expected.revert,
|
revertCode: expected.revert,
|
||||||
};
|
};
|
||||||
const sut = new ScriptCompiler([func]);
|
const sut = new ScriptCompiler([func]);
|
||||||
const call: FunctionCall = { function: functionName };
|
const call: FunctionCallData = { function: functionName };
|
||||||
const script = YamlScriptStub.createWithCall(call);
|
const script = ScriptDataStub.createWithCall(call);
|
||||||
// act
|
// act
|
||||||
const actual = sut.compile(script);
|
const actual = sut.compile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -186,13 +186,13 @@ describe('ScriptCompiler', () => {
|
|||||||
});
|
});
|
||||||
it('builds call sequence as expected', () => {
|
it('builds call sequence as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const firstFunction: YamlFunction = {
|
const firstFunction: FunctionData = {
|
||||||
name: 'first-function-name',
|
name: 'first-function-name',
|
||||||
parameters: [],
|
parameters: [],
|
||||||
code: 'first-function-code',
|
code: 'first-function-code',
|
||||||
revertCode: 'first-function-revert-code',
|
revertCode: 'first-function-revert-code',
|
||||||
};
|
};
|
||||||
const secondFunction: YamlFunction = {
|
const secondFunction: FunctionData = {
|
||||||
name: 'second-function-name',
|
name: 'second-function-name',
|
||||||
parameters: [],
|
parameters: [],
|
||||||
code: 'second-function-code',
|
code: 'second-function-code',
|
||||||
@@ -203,11 +203,11 @@ describe('ScriptCompiler', () => {
|
|||||||
revert: 'first-function-revert-code\nsecond-function-revert-code',
|
revert: 'first-function-revert-code\nsecond-function-revert-code',
|
||||||
};
|
};
|
||||||
const sut = new ScriptCompiler([firstFunction, secondFunction]);
|
const sut = new ScriptCompiler([firstFunction, secondFunction]);
|
||||||
const call: FunctionCall[] = [
|
const call: FunctionCallData[] = [
|
||||||
{ function: firstFunction.name },
|
{ function: firstFunction.name },
|
||||||
{ function: secondFunction.name },
|
{ function: secondFunction.name },
|
||||||
];
|
];
|
||||||
const script = YamlScriptStub.createWithCall(call);
|
const script = ScriptDataStub.createWithCall(call);
|
||||||
// act
|
// act
|
||||||
const actual = sut.compile(script);
|
const actual = sut.compile(script);
|
||||||
// assert
|
// assert
|
||||||
@@ -277,26 +277,26 @@ describe('ScriptCompiler', () => {
|
|||||||
|
|
||||||
interface ITestCase {
|
interface ITestCase {
|
||||||
code: string;
|
code: string;
|
||||||
parameters?: FunctionCallParameters;
|
parameters?: FunctionCallParametersData;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestEnvironment {
|
class TestEnvironment {
|
||||||
public readonly sut: IScriptCompiler;
|
public readonly sut: IScriptCompiler;
|
||||||
public readonly script: YamlScript;
|
public readonly script: ScriptData;
|
||||||
constructor(testCase: ITestCase) {
|
constructor(testCase: ITestCase) {
|
||||||
const functionName = 'testFunction';
|
const functionName = 'testFunction';
|
||||||
const func: YamlFunction = {
|
const func: FunctionData = {
|
||||||
name: functionName,
|
name: functionName,
|
||||||
parameters: testCase.parameters ? Object.keys(testCase.parameters) : undefined,
|
parameters: testCase.parameters ? Object.keys(testCase.parameters) : undefined,
|
||||||
code: this.getCode(testCase.code, 'execute'),
|
code: this.getCode(testCase.code, 'execute'),
|
||||||
revertCode: this.getCode(testCase.code, 'revert'),
|
revertCode: this.getCode(testCase.code, 'revert'),
|
||||||
};
|
};
|
||||||
this.sut = new ScriptCompiler([func]);
|
this.sut = new ScriptCompiler([func]);
|
||||||
const call: FunctionCall = {
|
const call: FunctionCallData = {
|
||||||
function: functionName,
|
function: functionName,
|
||||||
parameters: testCase.parameters,
|
parameters: testCase.parameters,
|
||||||
};
|
};
|
||||||
this.script = YamlScriptStub.createWithCall(call);
|
this.script = ScriptDataStub.createWithCall(call);
|
||||||
}
|
}
|
||||||
public expect(code: string): IScriptCode {
|
public expect(code: string): IScriptCode {
|
||||||
return {
|
return {
|
||||||
@@ -309,12 +309,12 @@ class TestEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFunctions(...names: string[]): YamlFunction[] {
|
function createFunctions(...names: string[]): FunctionData[] {
|
||||||
if (!names || names.length === 0) {
|
if (!names || names.length === 0) {
|
||||||
names = ['test-function'];
|
names = ['test-function'];
|
||||||
}
|
}
|
||||||
return names.map((functionName) => {
|
return names.map((functionName) => {
|
||||||
const func: YamlFunction = {
|
const func: FunctionData = {
|
||||||
name: functionName,
|
name: functionName,
|
||||||
parameters: [],
|
parameters: [],
|
||||||
code: `REM test-code (${functionName})`,
|
code: `REM test-code (${functionName})`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { YamlDocumentable } from 'js-yaml-loader!@/application.yaml';
|
import { DocumentableData } from 'js-yaml-loader!@/*';
|
||||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||||
|
|
||||||
describe('DocumentationParser', () => {
|
describe('DocumentationParser', () => {
|
||||||
@@ -10,7 +10,7 @@ describe('DocumentationParser', () => {
|
|||||||
});
|
});
|
||||||
it('returns empty when empty', () => {
|
it('returns empty when empty', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const empty: YamlDocumentable = { };
|
const empty: DocumentableData = { };
|
||||||
// act
|
// act
|
||||||
const actual = parseDocUrls(empty);
|
const actual = parseDocUrls(empty);
|
||||||
// assert
|
// assert
|
||||||
@@ -20,7 +20,7 @@ describe('DocumentationParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const url = 'https://privacy.sexy';
|
const url = 'https://privacy.sexy';
|
||||||
const expected = [ url ];
|
const expected = [ url ];
|
||||||
const sut: YamlDocumentable = { docs: url };
|
const sut: DocumentableData = { docs: url };
|
||||||
// act
|
// act
|
||||||
const actual = parseDocUrls(sut);
|
const actual = parseDocUrls(sut);
|
||||||
// assert
|
// assert
|
||||||
@@ -29,7 +29,7 @@ describe('DocumentationParser', () => {
|
|||||||
it('returns all when array', () => {
|
it('returns all when array', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = [ 'https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy' ];
|
const expected = [ 'https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy' ];
|
||||||
const sut: YamlDocumentable = { docs: expected };
|
const sut: DocumentableData = { docs: expected };
|
||||||
// act
|
// act
|
||||||
const actual = parseDocUrls(sut);
|
const actual = parseDocUrls(sut);
|
||||||
// assert
|
// assert
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
|||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
import { ScriptCode } from '@/domain/ScriptCode';
|
import { ScriptCode } from '@/domain/ScriptCode';
|
||||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
|
||||||
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
||||||
|
|
||||||
describe('ScriptParser', () => {
|
describe('ScriptParser', () => {
|
||||||
@@ -13,7 +13,7 @@ describe('ScriptParser', () => {
|
|||||||
it('parses name as expected', () => {
|
it('parses name as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = 'test-expected-name';
|
const expected = 'test-expected-name';
|
||||||
const script = YamlScriptStub.createWithCode()
|
const script = ScriptDataStub.createWithCode()
|
||||||
.withName(expected);
|
.withName(expected);
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
// act
|
// act
|
||||||
@@ -24,7 +24,7 @@ describe('ScriptParser', () => {
|
|||||||
it('parses docs as expected', () => {
|
it('parses docs as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const docs = [ 'https://expected-doc1.com', 'https://expected-doc2.com' ];
|
const docs = [ 'https://expected-doc1.com', 'https://expected-doc2.com' ];
|
||||||
const script = YamlScriptStub.createWithCode()
|
const script = ScriptDataStub.createWithCode()
|
||||||
.withDocs(docs);
|
.withDocs(docs);
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const expected = parseDocUrls(script);
|
const expected = parseDocUrls(script);
|
||||||
@@ -48,7 +48,7 @@ describe('ScriptParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'cannot define both "call" and "code"';
|
const expectedError = 'cannot define both "call" and "code"';
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const script = YamlScriptStub
|
const script = ScriptDataStub
|
||||||
.createWithCall()
|
.createWithCall()
|
||||||
.withCode('code');
|
.withCode('code');
|
||||||
// act
|
// act
|
||||||
@@ -60,7 +60,7 @@ describe('ScriptParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'cannot define "revertCode" if "call" is defined';
|
const expectedError = 'cannot define "revertCode" if "call" is defined';
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const script = YamlScriptStub
|
const script = ScriptDataStub
|
||||||
.createWithCall()
|
.createWithCall()
|
||||||
.withRevertCode('revert-code');
|
.withRevertCode('revert-code');
|
||||||
// act
|
// act
|
||||||
@@ -72,7 +72,7 @@ describe('ScriptParser', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'must define either "call" or "code"';
|
const expectedError = 'must define either "call" or "code"';
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const script = YamlScriptStub.createWithoutCallOrCodes();
|
const script = ScriptDataStub.createWithoutCallOrCodes();
|
||||||
// act
|
// act
|
||||||
const act = () => parseScript(script, compiler);
|
const act = () => parseScript(script, compiler);
|
||||||
// assert
|
// assert
|
||||||
@@ -85,7 +85,7 @@ describe('ScriptParser', () => {
|
|||||||
undefinedLevels.forEach((undefinedLevel) => {
|
undefinedLevels.forEach((undefinedLevel) => {
|
||||||
// arrange
|
// arrange
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const script = YamlScriptStub.createWithCode()
|
const script = ScriptDataStub.createWithCode()
|
||||||
.withRecommend(undefinedLevel);
|
.withRecommend(undefinedLevel);
|
||||||
// act
|
// act
|
||||||
const actual = parseScript(script, compiler);
|
const actual = parseScript(script, compiler);
|
||||||
@@ -98,7 +98,7 @@ describe('ScriptParser', () => {
|
|||||||
const expectedLevel = RecommendationLevel.Standard;
|
const expectedLevel = RecommendationLevel.Standard;
|
||||||
const expectedName = 'level';
|
const expectedName = 'level';
|
||||||
const levelText = 'standard';
|
const levelText = 'standard';
|
||||||
const script = YamlScriptStub.createWithCode()
|
const script = ScriptDataStub.createWithCode()
|
||||||
.withRecommend(levelText);
|
.withRecommend(levelText);
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
const parserMock = mockEnumParser(expectedName, levelText, expectedLevel);
|
const parserMock = mockEnumParser(expectedName, levelText, expectedLevel);
|
||||||
@@ -112,7 +112,7 @@ describe('ScriptParser', () => {
|
|||||||
it('parses code as expected', () => {
|
it('parses code as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = 'expected-code';
|
const expected = 'expected-code';
|
||||||
const script = YamlScriptStub
|
const script = ScriptDataStub
|
||||||
.createWithCode()
|
.createWithCode()
|
||||||
.withCode(expected);
|
.withCode(expected);
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
@@ -125,7 +125,7 @@ describe('ScriptParser', () => {
|
|||||||
it('parses revertCode as expected', () => {
|
it('parses revertCode as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = 'expected-revert-code';
|
const expected = 'expected-revert-code';
|
||||||
const script = YamlScriptStub
|
const script = ScriptDataStub
|
||||||
.createWithCode()
|
.createWithCode()
|
||||||
.withRevertCode(expected);
|
.withRevertCode(expected);
|
||||||
const compiler = new ScriptCompilerStub();
|
const compiler = new ScriptCompilerStub();
|
||||||
@@ -138,7 +138,7 @@ describe('ScriptParser', () => {
|
|||||||
describe('compiler', () => {
|
describe('compiler', () => {
|
||||||
it('throws when compiler is not defined', () => {
|
it('throws when compiler is not defined', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const script = YamlScriptStub.createWithCode();
|
const script = ScriptDataStub.createWithCode();
|
||||||
const compiler = undefined;
|
const compiler = undefined;
|
||||||
// act
|
// act
|
||||||
const act = () => parseScript(script, compiler);
|
const act = () => parseScript(script, compiler);
|
||||||
@@ -148,7 +148,7 @@ describe('ScriptParser', () => {
|
|||||||
it('gets code from compiler', () => {
|
it('gets code from compiler', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = new ScriptCode('test-script', 'code', 'revert-code');
|
const expected = new ScriptCode('test-script', 'code', 'revert-code');
|
||||||
const script = YamlScriptStub.createWithCode();
|
const script = ScriptDataStub.createWithCode();
|
||||||
const compiler = new ScriptCompilerStub()
|
const compiler = new ScriptCompilerStub()
|
||||||
.withCompileAbility(script, expected);
|
.withCompileAbility(script, expected);
|
||||||
// act
|
// act
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { YamlScriptingDefinition } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptingDefinitionData } from 'js-yaml-loader!@/*';
|
||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefinitionParser';
|
import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefinitionParser';
|
||||||
import { ProjectInformationStub } from './../../stubs/ProjectInformationStub';
|
import { ProjectInformationStub } from './../../stubs/ProjectInformationStub';
|
||||||
@@ -139,7 +139,7 @@ class ScriptingDefinitionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public construct(): YamlScriptingDefinition {
|
public construct(): ScriptingDefinitionData {
|
||||||
return {
|
return {
|
||||||
language: this.language,
|
language: this.language,
|
||||||
fileExtension: this.fileExtension,
|
fileExtension: this.fileExtension,
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { YamlCategory, YamlScript, YamlApplication, YamlScriptingDefinition } from 'js-yaml-loader!@/application/application.yaml';
|
import { CategoryData, ScriptData, CollectionData, ScriptingDefinitionData } from 'js-yaml-loader!@/*';
|
||||||
|
|
||||||
export class YamlApplicationStub implements YamlApplication {
|
export class CollectionDataStub implements CollectionData {
|
||||||
public os = 'windows';
|
public os = 'windows';
|
||||||
public actions: readonly YamlCategory[] = [ getCategoryStub() ];
|
public actions: readonly CategoryData[] = [ getCategoryStub() ];
|
||||||
public scripting: YamlScriptingDefinition = getTestDefinitionStub();
|
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
|
||||||
|
|
||||||
public withActions(actions: readonly YamlCategory[]): YamlApplicationStub {
|
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
|
||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withOs(os: string): YamlApplicationStub {
|
public withOs(os: string): CollectionDataStub {
|
||||||
this.os = os;
|
this.os = os;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withScripting(scripting: YamlScriptingDefinition): YamlApplicationStub {
|
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
|
||||||
this.scripting = scripting;
|
this.scripting = scripting;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
|
export function getCategoryStub(scriptPrefix = 'testScript'): CategoryData {
|
||||||
return {
|
return {
|
||||||
category: 'category name',
|
category: 'category name',
|
||||||
children: [
|
children: [
|
||||||
@@ -33,7 +33,7 @@ export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestDefinitionStub(): YamlScriptingDefinition {
|
function getTestDefinitionStub(): ScriptingDefinitionData {
|
||||||
return {
|
return {
|
||||||
fileExtension: '.bat',
|
fileExtension: '.bat',
|
||||||
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
||||||
@@ -42,7 +42,7 @@ function getTestDefinitionStub(): YamlScriptingDefinition {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): YamlScript {
|
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): ScriptData {
|
||||||
return {
|
return {
|
||||||
name: scriptName,
|
name: scriptName,
|
||||||
code: 'script code',
|
code: 'script code',
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptData } from 'js-yaml-loader!@/*';
|
||||||
|
|
||||||
export class ScriptCompilerStub implements IScriptCompiler {
|
export class ScriptCompilerStub implements IScriptCompiler {
|
||||||
public compilables = new Map<YamlScript, IScriptCode>();
|
public compilables = new Map<ScriptData, IScriptCode>();
|
||||||
public canCompile(script: YamlScript): boolean {
|
public canCompile(script: ScriptData): boolean {
|
||||||
return this.compilables.has(script);
|
return this.compilables.has(script);
|
||||||
}
|
}
|
||||||
public compile(script: YamlScript): IScriptCode {
|
public compile(script: ScriptData): IScriptCode {
|
||||||
return this.compilables.get(script);
|
return this.compilables.get(script);
|
||||||
}
|
}
|
||||||
public withCompileAbility(script: YamlScript, result?: IScriptCode): ScriptCompilerStub {
|
public withCompileAbility(script: ScriptData, result?: IScriptCode): ScriptCompilerStub {
|
||||||
this.compilables.set(script, result ||
|
this.compilables.set(script, result ||
|
||||||
{ execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` });
|
{ execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` });
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
import { ScriptFunctionCall, YamlScript } from 'js-yaml-loader!@/application.yaml';
|
import { ScriptFunctionCallData, ScriptData } from 'js-yaml-loader!@/*';
|
||||||
|
|
||||||
export class YamlScriptStub implements YamlScript {
|
export class ScriptDataStub implements ScriptData {
|
||||||
public static createWithCode(): YamlScriptStub {
|
public static createWithCode(): ScriptDataStub {
|
||||||
return new YamlScriptStub()
|
return new ScriptDataStub()
|
||||||
.withCode('stub-code')
|
.withCode('stub-code')
|
||||||
.withRevertCode('stub-revert-code');
|
.withRevertCode('stub-revert-code');
|
||||||
}
|
}
|
||||||
public static createWithCall(call?: ScriptFunctionCall): YamlScriptStub {
|
public static createWithCall(call?: ScriptFunctionCallData): ScriptDataStub {
|
||||||
let instance = new YamlScriptStub();
|
let instance = new ScriptDataStub();
|
||||||
if (call) {
|
if (call) {
|
||||||
instance = instance.withCall(call);
|
instance = instance.withCall(call);
|
||||||
} else {
|
} else {
|
||||||
@@ -16,8 +16,8 @@ export class YamlScriptStub implements YamlScript {
|
|||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
public static createWithoutCallOrCodes(): YamlScriptStub {
|
public static createWithoutCallOrCodes(): ScriptDataStub {
|
||||||
return new YamlScriptStub();
|
return new ScriptDataStub();
|
||||||
}
|
}
|
||||||
|
|
||||||
public name = 'valid-name';
|
public name = 'valid-name';
|
||||||
@@ -29,38 +29,38 @@ export class YamlScriptStub implements YamlScript {
|
|||||||
|
|
||||||
private constructor() { }
|
private constructor() { }
|
||||||
|
|
||||||
public withName(name: string): YamlScriptStub {
|
public withName(name: string): ScriptDataStub {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withDocs(docs: string[]): YamlScriptStub {
|
public withDocs(docs: string[]): ScriptDataStub {
|
||||||
this.docs = docs;
|
this.docs = docs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withCode(code: string): YamlScriptStub {
|
public withCode(code: string): ScriptDataStub {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withRevertCode(revertCode: string): YamlScriptStub {
|
public withRevertCode(revertCode: string): ScriptDataStub {
|
||||||
this.revertCode = revertCode;
|
this.revertCode = revertCode;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withMockCall(): YamlScriptStub {
|
public withMockCall(): ScriptDataStub {
|
||||||
this.call = { function: 'func', parameters: [] };
|
this.call = { function: 'func', parameters: [] };
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public withCall(call: ScriptFunctionCall): YamlScriptStub {
|
public withCall(call: ScriptFunctionCallData): ScriptDataStub {
|
||||||
this.call = call;
|
this.call = call;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public withRecommend(recommend: string): YamlScriptStub {
|
public withRecommend(recommend: string): ScriptDataStub {
|
||||||
this.recommend = recommend;
|
this.recommend = recommend;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user