From 6b83dcbf8fa08b4efe9974c7d7a667458f7c595c Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Sat, 9 Jan 2021 02:02:16 +0100 Subject: [PATCH] move application.yaml to collections/windows.yaml #40 --- CONTRIBUTING.md | 4 +- README.md | 12 ++-- ...pplication-file.md => collection-files.md} | 34 +++++------ src/application/Parser/ApplicationParser.ts | 12 ++-- .../Parser/CategoryCollectionParser.ts | 6 +- src/application/Parser/CategoryParser.ts | 36 +++++------ .../Parser/Compiler/IScriptCompiler.ts | 6 +- .../Parser/Compiler/ScriptCompiler.ts | 34 +++++------ src/application/Parser/DocumentationParser.ts | 6 +- src/application/Parser/ScriptParser.ts | 36 +++++------ .../Parser/ScriptingDefinitionParser.ts | 4 +- src/application/application.yaml.d.ts | 56 ----------------- .../collections/collection.yaml.d.ts | 56 +++++++++++++++++ .../windows.yaml} | 28 +-------- .../Parser/ApplicationParser.spec.ts | 15 ++--- .../Parser/CategoryCollectionParser.spec.ts | 12 ++-- .../application/Parser/CategoryParser.spec.ts | 38 ++++++------ .../Parser/Compiler/ScriptCompiler.spec.ts | 60 +++++++++---------- .../Parser/DocumentationParser.spec.ts | 8 +-- .../application/Parser/ScriptParser.spec.ts | 24 ++++---- .../Parser/ScriptingDefinitionParser.spec.ts | 4 +- ...plicationStub.ts => CollectionDataStub.ts} | 20 +++---- tests/unit/stubs/ScriptCompilerStub.ts | 10 ++-- .../{YamlScriptStub.ts => ScriptDataStub.ts} | 30 +++++----- 24 files changed, 265 insertions(+), 286 deletions(-) rename docs/{application-file.md => collection-files.md} (86%) delete mode 100644 src/application/application.yaml.d.ts create mode 100644 src/application/collections/collection.yaml.d.ts rename src/application/{application.yaml => collections/windows.yaml} (99%) rename tests/unit/stubs/{YamlApplicationStub.ts => CollectionDataStub.ts} (58%) rename tests/unit/stubs/{YamlScriptStub.ts => ScriptDataStub.ts} (55%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3eca5bc0..f2f25280 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 415bb199..b433bf8b 100644 --- a/README.md +++ b/README.md @@ -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). -- 🙏 For any new script, please add `revertCode` and `docs` values if possible. +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) diff --git a/docs/application-file.md b/docs/collection-files.md similarity index 86% rename from docs/application-file.md rename to docs/collection-files.md index d2b1a5c3..6c87855e 100644 --- a/docs/application-file.md +++ b/docs/collection-files.md @@ -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 diff --git a/src/application/Parser/ApplicationParser.ts b/src/application/Parser/ApplicationParser.ts index bd85c068..2803304f 100644 --- a/src/application/Parser/ApplicationParser.ts +++ b/src/application/Parser/ApplicationParser.ts @@ -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; diff --git a/src/application/Parser/CategoryCollectionParser.ts b/src/application/Parser/CategoryCollectionParser.ts index 7270c9c7..74a4697a 100644 --- a/src/application/Parser/CategoryCollectionParser.ts +++ b/src/application/Parser/CategoryCollectionParser.ts @@ -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'); } diff --git a/src/application/Parser/CategoryParser.ts b/src/application/Parser/CategoryParser.ts index 50b38852..ee0d8ac3 100644 --- a/src/application/Parser/CategoryParser.ts +++ b/src/application/Parser/CategoryParser.ts @@ -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(), subScripts: new Array