move application.yaml to collections/windows.yaml #40

This commit is contained in:
undergroundwires
2021-01-09 02:02:16 +01:00
parent 72e925fb6f
commit 6b83dcbf8f
24 changed files with 265 additions and 286 deletions

View File

@@ -30,8 +30,8 @@
- There are two types of components:
- **Stateless**, extends `Vue`
- **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
- They mutate or/and react to changes in [application state](src/application/Context/State/CategoryCollectionState.ts).
- 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 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.
## License

View File

@@ -32,9 +32,11 @@
## Extend scripts
- Fork it & add more scripts in [application.yaml](src/application/application.yaml) and send a pull request 👌
- 📖 If you're unsure about the syntax you can refer to the [application file | documentation](docs/application-file.md).
1. Fork the repository
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.
3. Send a pull request 👌
## Commands
@@ -69,7 +71,9 @@
- [ApplicationContext](src/application/Context/ApplicationContext.ts)
- Holds the [CategoryCollectionState](src/application/Context/State/CategoryCollectionState.ts)] for each OS
- 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.
![DDD + vue.js](img/architecture/app-ddd.png)

View File

@@ -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
- 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)
- 📖 Types in code: [`application.d.ts`](./../src/application/application.yaml.d.ts)
- 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)
- 📖 Types in code: [`collection.yaml.d.ts`](./../src/application/collections/collection.yaml.d.ts)
## Objects
### `Application`
### `Collection`
- Application file simply defines:
- A collection simply defines:
- different categories and their scripts in a tree structure
- 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**)
- 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.
- `actions: [` ***[`Category`](#Category)*** `, ... ]` **(required)**
- 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 are optionally defined to re-use the same code throughout different scripts.
- `scripting:` ***[`ScriptingDefinition`](#ScriptingDefinition)*** **(required)**
@@ -37,8 +37,8 @@
- `category:` *`string`* (**required**)
- Name of the category
- ❗ Must be unique throughout the application
- `children: [` ***[`Category`](#category)*** `|` [***`Script`***](#Script) `, ... ]` (**required**)
- ❗ Must be unique throughout the [Collection](#collection)
- `children: [` ***[`Category`](#Category)*** `|` [***`Script`***](#Script) `, ... ]` (**required**)
- ❗ Category must consist of at least one subcategory or script.
- Children can be combination of scripts and subcategories.
@@ -54,7 +54,7 @@
- `name`: *`string`* (**required**)
- Name of the script
- ❗ Must be unique throughout the application
- ❗ Must be unique throughout the [Collection](#collection)
- E.g. `Disable targeted ads`
- `code`: *`string`* (may be **required**)
- Batch file commands that will be executed
@@ -86,7 +86,7 @@
- `function`: *`string`* (**required**)
- 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`*`, ... ]`
- Defines key value dictionary for each parameter and its value
- 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
- `parameters`: `[` *`string`* `, ... ]`
- 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 unique
`code`: *`string`* (**required**)
@@ -147,7 +147,7 @@ It would print "Hello world" if it's called in a [script](#script) as following:
### `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

View File

@@ -2,14 +2,15 @@ import { IApplication } from '@/domain/IApplication';
import { IProjectInformation } from '@/domain/IProjectInformation';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
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 { Application } from '@/domain/Application';
export function parseApplication(
parser = CategoryCollectionParser,
processEnv: NodeJS.ProcessEnv = process.env,
collectionData = CollectionData): IApplication {
collectionData = LoadedCollectionData): IApplication {
const information = parseProjectInformation(processEnv);
const collection = parser(collectionData, information);
const app = new Application(information, [ collection ]);
@@ -17,11 +18,10 @@ export function parseApplication(
}
export type CategoryCollectionParserType
= (file: YamlApplication, info: IProjectInformation) => ICategoryCollection;
= (file: CollectionData, info: IProjectInformation) => ICategoryCollection;
const CategoryCollectionParser: CategoryCollectionParserType
= (file, info) => parseCategoryCollection(file, info);
const CollectionData: YamlApplication
= applicationFile;
const LoadedCollectionData: CollectionData
= WindowsData;

View File

@@ -1,5 +1,5 @@
import { Category } from '@/domain/Category';
import { YamlApplication } from 'js-yaml-loader!@/application.yaml';
import { CollectionData } from 'js-yaml-loader!@/*';
import { parseCategory } from './CategoryParser';
import { ScriptCompiler } from './Compiler/ScriptCompiler';
import { OperatingSystem } from '@/domain/OperatingSystem';
@@ -10,7 +10,7 @@ import { CategoryCollection } from '@/domain/CategoryCollection';
import { IProjectInformation } from '@/domain/IProjectInformation';
export function parseCategoryCollection(
content: YamlApplication,
content: CollectionData,
info: IProjectInformation,
osParser = createEnumParser(OperatingSystem)): ICategoryCollection {
validate(content);
@@ -29,7 +29,7 @@ export function parseCategoryCollection(
return collection;
}
function validate(content: YamlApplication): void {
function validate(content: CollectionData): void {
if (!content) {
throw new Error('content is null or undefined');
}

View File

@@ -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 { Category } from '@/domain/Category';
import { parseDocUrls } from './DocumentationParser';
@@ -12,7 +12,7 @@ interface ICategoryChildren {
subScripts: Script[];
}
export function parseCategory(category: YamlCategory, compiler: IScriptCompiler): Category {
export function parseCategory(category: CategoryData, compiler: IScriptCompiler): Category {
if (!compiler) {
throw new Error('undefined compiler');
}
@@ -21,8 +21,8 @@ export function parseCategory(category: YamlCategory, compiler: IScriptCompiler)
subCategories: new Array<Category>(),
subScripts: new Array<Script>(),
};
for (const categoryOrScript of category.children) {
parseCategoryChild(categoryOrScript, children, category, compiler);
for (const data of category.children) {
parseCategoryChild(data, children, category, compiler);
}
return new Category(
/*id*/ categoryIdCounter++,
@@ -33,7 +33,7 @@ export function parseCategory(category: YamlCategory, compiler: IScriptCompiler)
);
}
function ensureValid(category: YamlCategory) {
function ensureValid(category: CategoryData) {
if (!category) {
throw Error('category is null or undefined');
}
@@ -46,28 +46,28 @@ function ensureValid(category: YamlCategory) {
}
function parseCategoryChild(
categoryOrScript: any,
data: CategoryOrScriptData,
children: ICategoryChildren,
parent: YamlCategory,
parent: CategoryData,
compiler: IScriptCompiler) {
if (isCategory(categoryOrScript)) {
const subCategory = parseCategory(categoryOrScript as YamlCategory, compiler);
if (isCategory(data)) {
const subCategory = parseCategory(data as CategoryData, compiler);
children.subCategories.push(subCategory);
} else if (isScript(categoryOrScript)) {
const yamlScript = categoryOrScript as YamlScript;
const script = parseScript(yamlScript, compiler);
} else if (isScript(data)) {
const scriptData = data as ScriptData;
const script = parseScript(scriptData, compiler);
children.subScripts.push(script);
} else {
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 {
return (categoryOrScript.code && categoryOrScript.code.length > 0)
|| categoryOrScript.call;
function isScript(data: any): boolean {
return (data.code && data.code.length > 0)
|| data.call;
}
function isCategory(categoryOrScript: any): boolean {
return categoryOrScript.category && categoryOrScript.category.length > 0;
function isCategory(data: any): boolean {
return data.category && data.category.length > 0;
}

View File

@@ -1,7 +1,7 @@
import { IScriptCode } from '@/domain/IScriptCode';
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
import { ScriptData } from 'js-yaml-loader!@/*';
export interface IScriptCompiler {
canCompile(script: YamlScript): boolean;
compile(script: YamlScript): IScriptCode;
canCompile(script: ScriptData): boolean;
compile(script: ScriptData): IScriptCode;
}

View File

@@ -1,7 +1,7 @@
import { generateIlCode, IILCode } from './ILCode';
import { IScriptCode } from '@/domain/IScriptCode';
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';
interface ICompiledCode {
@@ -10,16 +10,16 @@ interface ICompiledCode {
}
export class ScriptCompiler implements IScriptCompiler {
constructor(private readonly functions: readonly YamlFunction[]) {
constructor(private readonly functions: readonly FunctionData[]) {
ensureValidFunctions(functions);
}
public canCompile(script: YamlScript): boolean {
public canCompile(script: ScriptData): boolean {
if (!script.call) {
return false;
}
return true;
}
public compile(script: YamlScript): IScriptCode {
public compile(script: ScriptData): IScriptCode {
this.ensureCompilable(script.call);
const compiledCodes = new Array<ICompiledCode>();
const calls = getCallSequence(script.call);
@@ -36,7 +36,7 @@ export class ScriptCompiler implements IScriptCompiler {
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);
if (!func) {
throw new Error(`called function is not defined "${name}"`);
@@ -44,7 +44,7 @@ export class ScriptCompiler implements IScriptCompiler {
return func;
}
private ensureCompilable(call: ScriptFunctionCall) {
private ensureCompilable(call: ScriptFunctionCallData) {
if (!this.functions || this.functions.length === 0) {
throw new Error('cannot compile without shared functions');
}
@@ -62,7 +62,7 @@ function printList(list: readonly string[]): string {
return `"${list.join('","')}"`;
}
function ensureNoDuplicatesInFunctionNames(functions: readonly YamlFunction[]) {
function ensureNoDuplicatesInFunctionNames(functions: readonly FunctionData[]) {
const duplicateFunctionNames = getDuplicates(functions
.map((func) => func.name.toLowerCase()));
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
.filter((func) => func.parameters && func.parameters.length > 0);
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));
if (duplicateCodes.length > 0) {
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) {
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 {
code: compileExpressions(func.code, parameters),
revertCode: compileExpressions(func.revertCode, parameters),
};
}
function compileExpressions(code: string, parameters: FunctionCallParameters): string {
function compileExpressions(code: string, parameters: FunctionCallParametersData): string {
let intermediateCode = generateIlCode(code);
intermediateCode = substituteParameters(intermediateCode, parameters);
return intermediateCode.compile();
}
function substituteParameters(intermediateCode: IILCode, parameters: FunctionCallParameters): IILCode {
function substituteParameters(intermediateCode: IILCode, parameters: FunctionCallParametersData): IILCode {
const parameterNames = intermediateCode.getUniqueParameterNames();
if (parameterNames.length && !parameters) {
throw new Error(`no parameters defined, expected: ${printList(parameterNames)}`);
@@ -146,7 +146,7 @@ function substituteParameters(intermediateCode: IILCode, parameters: FunctionCal
return intermediateCode;
}
function ensureValidCall(call: FunctionCall, scriptName: string) {
function ensureValidCall(call: FunctionCallData, scriptName: string) {
if (!call) {
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) {
return call as FunctionCall[];
return call as FunctionCallData[];
}
return [ call as FunctionCall ];
return [ call as FunctionCallData ];
}

View File

@@ -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) {
throw new Error('documentable is null or undefined');
}
@@ -13,7 +13,7 @@ export function parseDocUrls(documentable: YamlDocumentable): ReadonlyArray<stri
return result.getAll();
}
function addDocs(docs: DocumentationUrls, urls: DocumentationUrlContainer): DocumentationUrlContainer {
function addDocs(docs: DocumentationUrlsData, urls: DocumentationUrlContainer): DocumentationUrlContainer {
if (docs instanceof Array) {
urls.addUrls(docs);
} else if (typeof docs === 'string') {

View File

@@ -1,5 +1,5 @@
import { Script } from '@/domain/Script';
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
import { ScriptData } from 'js-yaml-loader!@/*';
import { parseDocUrls } from './DocumentationParser';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { IScriptCompiler } from './Compiler/IScriptCompiler';
@@ -8,17 +8,17 @@ import { ScriptCode } from '@/domain/ScriptCode';
import { createEnumParser, IEnumParser } from '../Common/Enum';
export function parseScript(
yamlScript: YamlScript, compiler: IScriptCompiler,
data: ScriptData, compiler: IScriptCompiler,
levelParser = createEnumParser(RecommendationLevel)): Script {
validateScript(yamlScript);
validateScript(data);
if (!compiler) {
throw new Error('undefined compiler');
}
const script = new Script(
/* name */ yamlScript.name,
/* code */ parseCode(yamlScript, compiler),
/* docs */ parseDocUrls(yamlScript),
/* level */ parseLevel(yamlScript.recommend, levelParser));
/* name */ data.name,
/* code */ parseCode(data, compiler),
/* docs */ parseDocUrls(data),
/* level */ parseLevel(data.recommend, levelParser));
return script;
}
@@ -29,28 +29,28 @@ function parseLevel(level: string, parser: IEnumParser<RecommendationLevel>): Re
return parser.parseEnum(level, 'level');
}
function parseCode(yamlScript: YamlScript, compiler: IScriptCompiler): IScriptCode {
if (compiler.canCompile(yamlScript)) {
return compiler.compile(yamlScript);
function parseCode(script: ScriptData, compiler: IScriptCompiler): IScriptCode {
if (compiler.canCompile(script)) {
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) {
if (yamlScript.code && yamlScript.call) {
function ensureNotBothCallAndCode(script: ScriptData) {
if (script.code && script.call) {
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');
}
}
function validateScript(yamlScript: YamlScript) {
if (!yamlScript) {
function validateScript(script: ScriptData) {
if (!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"');
}
ensureNotBothCallAndCode(yamlScript);
ensureNotBothCallAndCode(script);
}

View File

@@ -1,5 +1,5 @@
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 { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { IProjectInformation } from '@/domain/IProjectInformation';
@@ -7,7 +7,7 @@ import { createEnumParser } from '../Common/Enum';
import { generateIlCode } from './Compiler/ILCode';
export function parseScriptingDefinition(
definition: YamlScriptingDefinition,
definition: ScriptingDefinitionData,
info: IProjectInformation,
date = new Date(),
languageParser = createEnumParser(ScriptingLanguage)): IScriptingDefinition {

View File

@@ -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;
}

View 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;
}

View File

@@ -1,4 +1,4 @@
# Structure documented in "docs/application-file.md"
# Structure documented in "docs/collections.md"
os: windows
scripting:
language: batchfile
@@ -1333,32 +1333,6 @@ actions:
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
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
children:

View File

@@ -2,14 +2,15 @@ import 'mocha';
import { expect } from 'chai';
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
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 { ProjectInformation } from '@/domain/ProjectInformation';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
import { getProcessEnvironmentStub } from '../../stubs/ProcessEnvironmentStub';
import { YamlApplicationStub } from '../../stubs/YamlApplicationStub';
import { CollectionDataStub } from '../../stubs/CollectionDataStub';
describe('ApplicationParser', () => {
describe('parseApplication', () => {
@@ -64,7 +65,7 @@ describe('ApplicationParser', () => {
describe('collectionData', () => {
it('parsed with expected data', () => {
// arrange
const expected = new YamlApplicationStub();
const expected = new CollectionDataStub();
const env = getProcessEnvironmentStub();
const parserSpy = new CategoryCollectionParserSpy();
const parserMock = parserSpy.mockParser();
@@ -73,9 +74,9 @@ describe('ApplicationParser', () => {
// assert
expect(expected).to.equal(parserSpy.lastArguments.file);
});
it('defaults to applicationFile', () => {
it('defaults to windows data', () => {
// arrange
const expected = applicationFile;
const expected = WindowsData;
const parserSpy = new CategoryCollectionParserSpy();
const parserMock = parserSpy.mockParser();
// act
@@ -89,7 +90,7 @@ describe('ApplicationParser', () => {
class CategoryCollectionParserSpy {
public lastArguments: {
file: YamlApplication;
file: CollectionData;
info: ProjectInformation;
} = { file: undefined, info: undefined };
private result: ICategoryCollection = new CategoryCollectionStub();
@@ -99,7 +100,7 @@ class CategoryCollectionParserSpy {
return this;
}
public mockParser(): CategoryCollectionParserType {
return (file: YamlApplication, info: IProjectInformation) => {
return (file: CollectionData, info: IProjectInformation) => {
this.lastArguments.file = file;
this.lastArguments.info = info;
return this.result;

View File

@@ -9,7 +9,7 @@ import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefiniti
import { mockEnumParser } from '../../stubs/EnumParserStub';
import { ProjectInformationStub } from '../../stubs/ProjectInformationStub';
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
import { getCategoryStub, YamlApplicationStub } from '../../stubs/YamlApplicationStub';
import { getCategoryStub, CollectionDataStub } from '../../stubs/CollectionDataStub';
describe('CategoryCollectionParser', () => {
describe('parseCategoryCollection', () => {
@@ -26,7 +26,7 @@ describe('CategoryCollectionParser', () => {
it('throws when undefined actions', () => {
// arrange
const expectedError = 'content does not define any action';
const collection = new YamlApplicationStub()
const collection = new CollectionDataStub()
.withActions(undefined);
const info = new ProjectInformationStub();
// act
@@ -37,7 +37,7 @@ describe('CategoryCollectionParser', () => {
it('throws when has no actions', () => {
// arrange
const expectedError = 'content does not define any action';
const collection = new YamlApplicationStub()
const collection = new CollectionDataStub()
.withActions([]);
const info = new ProjectInformationStub();
// act
@@ -50,7 +50,7 @@ describe('CategoryCollectionParser', () => {
const actions = [ getCategoryStub('test1'), getCategoryStub('test2') ];
const compiler = new ScriptCompilerStub();
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
const collection = new YamlApplicationStub()
const collection = new CollectionDataStub()
.withActions(actions);
const info = new ProjectInformationStub();
// act
@@ -68,7 +68,7 @@ describe('CategoryCollectionParser', () => {
describe('scripting definition', () => {
it('parses scripting definition as expected', () => {
// arrange
const collection = new YamlApplicationStub();
const collection = new CollectionDataStub();
const information = parseProjectInformation(process.env);
const expected = parseScriptingDefinition(collection.scripting, information);
// act
@@ -83,7 +83,7 @@ describe('CategoryCollectionParser', () => {
const expectedOs = OperatingSystem.macOS;
const osText = 'macos';
const expectedName = 'os';
const collection = new YamlApplicationStub()
const collection = new CollectionDataStub()
.withOs(osText);
const parserMock = mockEnumParser(expectedName, osText, expectedOs);
const info = new ProjectInformationStub();

View File

@@ -1,11 +1,11 @@
import 'mocha';
import { expect } from 'chai';
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 { parseDocUrls } from '@/application/Parser/DocumentationParser';
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
describe('CategoryParser', () => {
describe('parseCategory', () => {
@@ -24,7 +24,7 @@ describe('CategoryParser', () => {
// arrange
const categoryName = 'test';
const expectedMessage = `category has no children: "${categoryName}"`;
const category: YamlCategory = {
const category: CategoryData = {
category: categoryName,
children: [],
};
@@ -38,7 +38,7 @@ describe('CategoryParser', () => {
// arrange
const categoryName = 'test';
const expectedMessage = `category has no children: "${categoryName}"`;
const category: YamlCategory = {
const category: CategoryData = {
category: categoryName,
children: undefined,
};
@@ -53,7 +53,7 @@ describe('CategoryParser', () => {
const expectedMessage = 'category has no name';
const invalidNames = ['', undefined];
invalidNames.forEach((invalidName) => {
const category: YamlCategory = {
const category: CategoryData = {
category: invalidName,
children: getTestChildren(),
};
@@ -80,7 +80,7 @@ describe('CategoryParser', () => {
const url = 'https://privacy.sexy';
const expected = parseDocUrls({ docs: url });
const compiler = new ScriptCompilerStub();
const category: YamlCategory = {
const category: CategoryData = {
category: 'category name',
children: getTestChildren(),
docs: url,
@@ -93,10 +93,10 @@ describe('CategoryParser', () => {
describe('parses expected subscript', () => {
it('single script with code', () => {
// arrange
const script = YamlScriptStub.createWithCode();
const script = ScriptDataStub.createWithCode();
const compiler = new ScriptCompilerStub();
const expected = [ parseScript(script, compiler) ];
const category: YamlCategory = {
const category: CategoryData = {
category: 'category name',
children: [ script ],
};
@@ -107,11 +107,11 @@ describe('CategoryParser', () => {
});
it('single script with function call', () => {
// arrange
const script = YamlScriptStub.createWithCall();
const script = ScriptDataStub.createWithCall();
const compiler = new ScriptCompilerStub()
.withCompileAbility(script);
const expected = [ parseScript(script, compiler) ];
const category: YamlCategory = {
const category: CategoryData = {
category: 'category name',
children: [ script ],
};
@@ -122,12 +122,12 @@ describe('CategoryParser', () => {
});
it('multiple scripts with function call and code', () => {
// arrange
const callableScript = YamlScriptStub.createWithCall();
const scripts = [ callableScript, YamlScriptStub.createWithCode() ];
const callableScript = ScriptDataStub.createWithCall();
const scripts = [ callableScript, ScriptDataStub.createWithCode() ];
const compiler = new ScriptCompilerStub()
.withCompileAbility(callableScript);
const expected = scripts.map((script) => parseScript(script, compiler));
const category: YamlCategory = {
const category: CategoryData = {
category: 'category name',
children: scripts,
};
@@ -139,11 +139,11 @@ describe('CategoryParser', () => {
});
it('returns expected subcategories', () => {
// arrange
const expected: YamlCategory[] = [ {
const expected: CategoryData[] = [ {
category: 'test category',
children: [ YamlScriptStub.createWithCode() ],
children: [ ScriptDataStub.createWithCode() ],
}];
const category: YamlCategory = {
const category: CategoryData = {
category: 'category name',
children: expected,
};
@@ -158,7 +158,7 @@ describe('CategoryParser', () => {
});
});
function getValidCategory(): YamlCategory {
function getValidCategory(): CategoryData {
return {
category: 'category name',
children: getTestChildren(),
@@ -166,8 +166,8 @@ function getValidCategory(): YamlCategory {
};
}
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
function getTestChildren(): ReadonlyArray<CategoryOrScriptData> {
return [
YamlScriptStub.createWithCode(),
ScriptDataStub.createWithCode(),
];
}

View File

@@ -1,8 +1,8 @@
import 'mocha';
import { expect } from 'chai';
import { ScriptCompiler } from '@/application/Parser/Compiler/ScriptCompiler';
import { YamlScriptStub } from '../../../stubs/YamlScriptStub';
import { YamlFunction, YamlScript, FunctionCall, ScriptFunctionCall, FunctionCallParameters } from 'js-yaml-loader!@/application.yaml';
import { ScriptDataStub } from '../../../stubs/ScriptDataStub';
import { FunctionData, ScriptData, FunctionCallData, ScriptFunctionCallData, FunctionCallParametersData } from 'js-yaml-loader!@/*';
import { IScriptCode } from '@/domain/IScriptCode';
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
@@ -11,7 +11,7 @@ describe('ScriptCompiler', () => {
it('throws when functions have same names', () => {
// arrange
const expectedError = `duplicate function name: "same-func-name"`;
const functions: YamlFunction[] = [ {
const functions: FunctionData[] = [ {
name: 'same-func-name',
code: 'non-empty-code',
}, {
@@ -25,7 +25,7 @@ describe('ScriptCompiler', () => {
});
it('throws when function parameters have same names', () => {
// arrange
const func: YamlFunction = {
const func: FunctionData = {
name: 'function-name',
code: 'non-empty-code',
parameters: [ 'duplicate', 'duplicate' ],
@@ -40,7 +40,7 @@ describe('ScriptCompiler', () => {
it('code', () => {
// arrange
const expectedError = `duplicate "code" in functions: "duplicate-code"`;
const functions: YamlFunction[] = [ {
const functions: FunctionData[] = [ {
name: 'func-1',
code: 'duplicate-code',
}, {
@@ -55,7 +55,7 @@ describe('ScriptCompiler', () => {
it('revertCode', () => {
// arrange
const expectedError = `duplicate "revertCode" in functions: "duplicate-revert-code"`;
const functions: YamlFunction[] = [ {
const functions: FunctionData[] = [ {
name: 'func-1',
code: 'code-1',
revertCode: 'duplicate-revert-code',
@@ -75,7 +75,7 @@ describe('ScriptCompiler', () => {
it('returns true if "call" is defined', () => {
// arrange
const sut = new ScriptCompiler([]);
const script = YamlScriptStub.createWithCall();
const script = ScriptDataStub.createWithCall();
// act
const actual = sut.canCompile(script);
// assert
@@ -84,7 +84,7 @@ describe('ScriptCompiler', () => {
it('returns false if "call" is undefined', () => {
// arrange
const sut = new ScriptCompiler([]);
const script = YamlScriptStub.createWithCode();
const script = ScriptDataStub.createWithCode();
// act
const actual = sut.canCompile(script);
// assert
@@ -98,7 +98,7 @@ describe('ScriptCompiler', () => {
const expectedError = 'cannot compile without shared functions';
const functions = [];
const sut = new ScriptCompiler(functions);
const script = YamlScriptStub.createWithCall();
const script = ScriptDataStub.createWithCall();
// act
const act = () => sut.compile(script);
// assert
@@ -110,7 +110,7 @@ describe('ScriptCompiler', () => {
const invalidValues = [undefined, 'string', 33];
const sut = new ScriptCompiler(createFunctions());
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);
// act
const act = () => sut.compile(script);
@@ -124,8 +124,8 @@ describe('ScriptCompiler', () => {
const sut = new ScriptCompiler(createFunctions());
const nonExistingFunctionName = 'non-existing-func';
const expectedError = `called function is not defined "${nonExistingFunctionName}"`;
const call: ScriptFunctionCall = { function: nonExistingFunctionName };
const script = YamlScriptStub.createWithCall(call);
const call: ScriptFunctionCallData = { function: nonExistingFunctionName };
const script = ScriptDataStub.createWithCall(call);
// act
const act = () => sut.compile(script);
// assert
@@ -135,11 +135,11 @@ describe('ScriptCompiler', () => {
// arrange
const existingFunctionName = 'existing-func';
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
const call: ScriptFunctionCall = [
const call: ScriptFunctionCallData = [
{ function: existingFunctionName },
undefined,
];
const script = YamlScriptStub.createWithCall(call);
const script = ScriptDataStub.createWithCall(call);
const expectedError = `undefined function call in script "${script.name}"`;
// act
const act = () => sut.compile(script);
@@ -150,10 +150,10 @@ describe('ScriptCompiler', () => {
// arrange
const existingFunctionName = 'existing-func';
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
const call: FunctionCall[] = [
const call: FunctionCallData[] = [
{ function: existingFunctionName },
{ function: undefined }];
const script = YamlScriptStub.createWithCall(call);
const script = ScriptDataStub.createWithCall(call);
const expectedError = `empty function name called in script "${script.name}"`;
// act
const act = () => sut.compile(script);
@@ -170,15 +170,15 @@ describe('ScriptCompiler', () => {
execute: 'expected-code',
revert: 'expected-revert-code',
};
const func: YamlFunction = {
const func: FunctionData = {
name: functionName,
parameters: [],
code: expected.execute,
revertCode: expected.revert,
};
const sut = new ScriptCompiler([func]);
const call: FunctionCall = { function: functionName };
const script = YamlScriptStub.createWithCall(call);
const call: FunctionCallData = { function: functionName };
const script = ScriptDataStub.createWithCall(call);
// act
const actual = sut.compile(script);
// assert
@@ -186,13 +186,13 @@ describe('ScriptCompiler', () => {
});
it('builds call sequence as expected', () => {
// arrange
const firstFunction: YamlFunction = {
const firstFunction: FunctionData = {
name: 'first-function-name',
parameters: [],
code: 'first-function-code',
revertCode: 'first-function-revert-code',
};
const secondFunction: YamlFunction = {
const secondFunction: FunctionData = {
name: 'second-function-name',
parameters: [],
code: 'second-function-code',
@@ -203,11 +203,11 @@ describe('ScriptCompiler', () => {
revert: 'first-function-revert-code\nsecond-function-revert-code',
};
const sut = new ScriptCompiler([firstFunction, secondFunction]);
const call: FunctionCall[] = [
const call: FunctionCallData[] = [
{ function: firstFunction.name },
{ function: secondFunction.name },
];
const script = YamlScriptStub.createWithCall(call);
const script = ScriptDataStub.createWithCall(call);
// act
const actual = sut.compile(script);
// assert
@@ -277,26 +277,26 @@ describe('ScriptCompiler', () => {
interface ITestCase {
code: string;
parameters?: FunctionCallParameters;
parameters?: FunctionCallParametersData;
}
class TestEnvironment {
public readonly sut: IScriptCompiler;
public readonly script: YamlScript;
public readonly script: ScriptData;
constructor(testCase: ITestCase) {
const functionName = 'testFunction';
const func: YamlFunction = {
const func: FunctionData = {
name: functionName,
parameters: testCase.parameters ? Object.keys(testCase.parameters) : undefined,
code: this.getCode(testCase.code, 'execute'),
revertCode: this.getCode(testCase.code, 'revert'),
};
this.sut = new ScriptCompiler([func]);
const call: FunctionCall = {
const call: FunctionCallData = {
function: functionName,
parameters: testCase.parameters,
};
this.script = YamlScriptStub.createWithCall(call);
this.script = ScriptDataStub.createWithCall(call);
}
public expect(code: string): IScriptCode {
return {
@@ -309,12 +309,12 @@ class TestEnvironment {
}
}
function createFunctions(...names: string[]): YamlFunction[] {
function createFunctions(...names: string[]): FunctionData[] {
if (!names || names.length === 0) {
names = ['test-function'];
}
return names.map((functionName) => {
const func: YamlFunction = {
const func: FunctionData = {
name: functionName,
parameters: [],
code: `REM test-code (${functionName})`,

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { YamlDocumentable } from 'js-yaml-loader!@/application.yaml';
import { DocumentableData } from 'js-yaml-loader!@/*';
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
describe('DocumentationParser', () => {
@@ -10,7 +10,7 @@ describe('DocumentationParser', () => {
});
it('returns empty when empty', () => {
// arrange
const empty: YamlDocumentable = { };
const empty: DocumentableData = { };
// act
const actual = parseDocUrls(empty);
// assert
@@ -20,7 +20,7 @@ describe('DocumentationParser', () => {
// arrange
const url = 'https://privacy.sexy';
const expected = [ url ];
const sut: YamlDocumentable = { docs: url };
const sut: DocumentableData = { docs: url };
// act
const actual = parseDocUrls(sut);
// assert
@@ -29,7 +29,7 @@ describe('DocumentationParser', () => {
it('returns all when array', () => {
// arrange
const expected = [ 'https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy' ];
const sut: YamlDocumentable = { docs: expected };
const sut: DocumentableData = { docs: expected };
// act
const actual = parseDocUrls(sut);
// assert

View File

@@ -5,7 +5,7 @@ import { parseDocUrls } from '@/application/Parser/DocumentationParser';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { ScriptCode } from '@/domain/ScriptCode';
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
import { mockEnumParser } from '../../stubs/EnumParserStub';
describe('ScriptParser', () => {
@@ -13,7 +13,7 @@ describe('ScriptParser', () => {
it('parses name as expected', () => {
// arrange
const expected = 'test-expected-name';
const script = YamlScriptStub.createWithCode()
const script = ScriptDataStub.createWithCode()
.withName(expected);
const compiler = new ScriptCompilerStub();
// act
@@ -24,7 +24,7 @@ describe('ScriptParser', () => {
it('parses docs as expected', () => {
// arrange
const docs = [ 'https://expected-doc1.com', 'https://expected-doc2.com' ];
const script = YamlScriptStub.createWithCode()
const script = ScriptDataStub.createWithCode()
.withDocs(docs);
const compiler = new ScriptCompilerStub();
const expected = parseDocUrls(script);
@@ -48,7 +48,7 @@ describe('ScriptParser', () => {
// arrange
const expectedError = 'cannot define both "call" and "code"';
const compiler = new ScriptCompilerStub();
const script = YamlScriptStub
const script = ScriptDataStub
.createWithCall()
.withCode('code');
// act
@@ -60,7 +60,7 @@ describe('ScriptParser', () => {
// arrange
const expectedError = 'cannot define "revertCode" if "call" is defined';
const compiler = new ScriptCompilerStub();
const script = YamlScriptStub
const script = ScriptDataStub
.createWithCall()
.withRevertCode('revert-code');
// act
@@ -72,7 +72,7 @@ describe('ScriptParser', () => {
// arrange
const expectedError = 'must define either "call" or "code"';
const compiler = new ScriptCompilerStub();
const script = YamlScriptStub.createWithoutCallOrCodes();
const script = ScriptDataStub.createWithoutCallOrCodes();
// act
const act = () => parseScript(script, compiler);
// assert
@@ -85,7 +85,7 @@ describe('ScriptParser', () => {
undefinedLevels.forEach((undefinedLevel) => {
// arrange
const compiler = new ScriptCompilerStub();
const script = YamlScriptStub.createWithCode()
const script = ScriptDataStub.createWithCode()
.withRecommend(undefinedLevel);
// act
const actual = parseScript(script, compiler);
@@ -98,7 +98,7 @@ describe('ScriptParser', () => {
const expectedLevel = RecommendationLevel.Standard;
const expectedName = 'level';
const levelText = 'standard';
const script = YamlScriptStub.createWithCode()
const script = ScriptDataStub.createWithCode()
.withRecommend(levelText);
const compiler = new ScriptCompilerStub();
const parserMock = mockEnumParser(expectedName, levelText, expectedLevel);
@@ -112,7 +112,7 @@ describe('ScriptParser', () => {
it('parses code as expected', () => {
// arrange
const expected = 'expected-code';
const script = YamlScriptStub
const script = ScriptDataStub
.createWithCode()
.withCode(expected);
const compiler = new ScriptCompilerStub();
@@ -125,7 +125,7 @@ describe('ScriptParser', () => {
it('parses revertCode as expected', () => {
// arrange
const expected = 'expected-revert-code';
const script = YamlScriptStub
const script = ScriptDataStub
.createWithCode()
.withRevertCode(expected);
const compiler = new ScriptCompilerStub();
@@ -138,7 +138,7 @@ describe('ScriptParser', () => {
describe('compiler', () => {
it('throws when compiler is not defined', () => {
// arrange
const script = YamlScriptStub.createWithCode();
const script = ScriptDataStub.createWithCode();
const compiler = undefined;
// act
const act = () => parseScript(script, compiler);
@@ -148,7 +148,7 @@ describe('ScriptParser', () => {
it('gets code from compiler', () => {
// arrange
const expected = new ScriptCode('test-script', 'code', 'revert-code');
const script = YamlScriptStub.createWithCode();
const script = ScriptDataStub.createWithCode();
const compiler = new ScriptCompilerStub()
.withCompileAbility(script, expected);
// act

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { YamlScriptingDefinition } from 'js-yaml-loader!@/application.yaml';
import { ScriptingDefinitionData } from 'js-yaml-loader!@/*';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefinitionParser';
import { ProjectInformationStub } from './../../stubs/ProjectInformationStub';
@@ -139,7 +139,7 @@ class ScriptingDefinitionBuilder {
return this;
}
public construct(): YamlScriptingDefinition {
public construct(): ScriptingDefinitionData {
return {
language: this.language,
fileExtension: this.fileExtension,

View File

@@ -1,29 +1,29 @@
import { RecommendationLevel } from '@/domain/RecommendationLevel';
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 actions: readonly YamlCategory[] = [ getCategoryStub() ];
public scripting: YamlScriptingDefinition = getTestDefinitionStub();
public actions: readonly CategoryData[] = [ getCategoryStub() ];
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
public withActions(actions: readonly YamlCategory[]): YamlApplicationStub {
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
this.actions = actions;
return this;
}
public withOs(os: string): YamlApplicationStub {
public withOs(os: string): CollectionDataStub {
this.os = os;
return this;
}
public withScripting(scripting: YamlScriptingDefinition): YamlApplicationStub {
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
this.scripting = scripting;
return this;
}
}
export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
export function getCategoryStub(scriptPrefix = 'testScript'): CategoryData {
return {
category: 'category name',
children: [
@@ -33,7 +33,7 @@ export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
};
}
function getTestDefinitionStub(): YamlScriptingDefinition {
function getTestDefinitionStub(): ScriptingDefinitionData {
return {
fileExtension: '.bat',
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 {
name: scriptName,
code: 'script code',

View File

@@ -1,16 +1,16 @@
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
import { IScriptCode } from '@/domain/IScriptCode';
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
import { ScriptData } from 'js-yaml-loader!@/*';
export class ScriptCompilerStub implements IScriptCompiler {
public compilables = new Map<YamlScript, IScriptCode>();
public canCompile(script: YamlScript): boolean {
public compilables = new Map<ScriptData, IScriptCode>();
public canCompile(script: ScriptData): boolean {
return this.compilables.has(script);
}
public compile(script: YamlScript): IScriptCode {
public compile(script: ScriptData): IScriptCode {
return this.compilables.get(script);
}
public withCompileAbility(script: YamlScript, result?: IScriptCode): ScriptCompilerStub {
public withCompileAbility(script: ScriptData, result?: IScriptCode): ScriptCompilerStub {
this.compilables.set(script, result ||
{ execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` });
return this;

View File

@@ -1,14 +1,14 @@
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 {
public static createWithCode(): YamlScriptStub {
return new YamlScriptStub()
export class ScriptDataStub implements ScriptData {
public static createWithCode(): ScriptDataStub {
return new ScriptDataStub()
.withCode('stub-code')
.withRevertCode('stub-revert-code');
}
public static createWithCall(call?: ScriptFunctionCall): YamlScriptStub {
let instance = new YamlScriptStub();
public static createWithCall(call?: ScriptFunctionCallData): ScriptDataStub {
let instance = new ScriptDataStub();
if (call) {
instance = instance.withCall(call);
} else {
@@ -16,8 +16,8 @@ export class YamlScriptStub implements YamlScript {
}
return instance;
}
public static createWithoutCallOrCodes(): YamlScriptStub {
return new YamlScriptStub();
public static createWithoutCallOrCodes(): ScriptDataStub {
return new ScriptDataStub();
}
public name = 'valid-name';
@@ -29,38 +29,38 @@ export class YamlScriptStub implements YamlScript {
private constructor() { }
public withName(name: string): YamlScriptStub {
public withName(name: string): ScriptDataStub {
this.name = name;
return this;
}
public withDocs(docs: string[]): YamlScriptStub {
public withDocs(docs: string[]): ScriptDataStub {
this.docs = docs;
return this;
}
public withCode(code: string): YamlScriptStub {
public withCode(code: string): ScriptDataStub {
this.code = code;
return this;
}
public withRevertCode(revertCode: string): YamlScriptStub {
public withRevertCode(revertCode: string): ScriptDataStub {
this.revertCode = revertCode;
return this;
}
public withMockCall(): YamlScriptStub {
public withMockCall(): ScriptDataStub {
this.call = { function: 'func', parameters: [] };
return this;
}
public withCall(call: ScriptFunctionCall): YamlScriptStub {
public withCall(call: ScriptFunctionCallData): ScriptDataStub {
this.call = call;
return this;
}
public withRecommend(recommend: string): YamlScriptStub {
public withRecommend(recommend: string): ScriptDataStub {
this.recommend = recommend;
return this;
}