Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab7d617886 | ||
|
|
b247b12c3f | ||
|
|
c26bc209eb | ||
|
|
ad1872e7cd | ||
|
|
29c7704e0b | ||
|
|
e41e40c5bf | ||
|
|
31e08d231d | ||
|
|
45b8dd972b | ||
|
|
4e72673373 | ||
|
|
92c3dd9232 | ||
|
|
2c5ab3ea7d | ||
|
|
ffa279f3df | ||
|
|
89dddfbb23 | ||
|
|
cfedcd724c | ||
|
|
fd28eaad06 | ||
|
|
8ce06facbd | ||
|
|
1a9db31c77 | ||
|
|
ac70b063b8 | ||
|
|
d0019c2c9b | ||
|
|
4c68408f1e | ||
|
|
1072505219 | ||
|
|
07fc555324 | ||
|
|
50fb29038a | ||
|
|
3785c623f8 | ||
|
|
14be3017c5 | ||
|
|
978bab0b81 | ||
|
|
d9d7f62d81 | ||
|
|
11e0613165 | ||
|
|
77c3d2bbb8 | ||
|
|
784a67afff | ||
|
|
19a092dd31 | ||
|
|
4c2f74949b | ||
|
|
a3fc3782ef | ||
|
|
cdc93f032a | ||
|
|
7dd15ed064 | ||
|
|
d169434157 | ||
|
|
6efed72bf2 | ||
|
|
15db311801 | ||
|
|
82d509129b | ||
|
|
939d838e35 | ||
|
|
6de4ce58c4 | ||
|
|
ee66196d9a | ||
|
|
3c13a9e837 | ||
|
|
22b23a9ece | ||
|
|
4ae385b7fc | ||
|
|
d9abc7f0b2 | ||
|
|
1f19b2528a | ||
|
|
1f11c39773 | ||
|
|
b6ccb5927a | ||
|
|
1d465ee318 | ||
|
|
3ab48b1cf5 | ||
|
|
de4ac978bd | ||
|
|
8df5faf4ef | ||
|
|
99a2035fdb | ||
|
|
a0d61728ea | ||
|
|
312bf6102c |
2
.github/workflows/deploy-site.yaml
vendored
2
.github/workflows/deploy-site.yaml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
--secret-access-key ${{secrets.AWS_DEPLOYMENT_USER_SECRET_ACCESS_KEY}} \
|
||||
--region us-east-1 \
|
||||
&& \
|
||||
echo "::set-env name=SESSION_NAME::${{github.actor}}-${{github.event_name}}-$(echo ${{github.sha}} | cut -c1-8)"
|
||||
echo "SESSION_NAME=${{github.actor}}-${{github.event_name}}-$(echo ${{github.sha}} | cut -c1-8)" >> $GITHUB_ENV
|
||||
working-directory: aws
|
||||
-
|
||||
name: "Infrastructure: Deploy IAM stack"
|
||||
|
||||
2
.github/workflows/quality-checks.yaml
vendored
2
.github/workflows/quality-checks.yaml
vendored
@@ -1,6 +1,6 @@
|
||||
name: Quality checks
|
||||
|
||||
on: push
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
|
||||
1
.github/workflows/security-checks.yaml
vendored
1
.github/workflows/security-checks.yaml
vendored
@@ -2,6 +2,7 @@ name: Security checks
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0'
|
||||
|
||||
|
||||
7
.github/workflows/test.yaml
vendored
7
.github/workflows/test.yaml
vendored
@@ -1,10 +1,13 @@
|
||||
name: Test
|
||||
|
||||
on: push
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
run-tests:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos, ubuntu, windows]
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
node_modules
|
||||
/dist
|
||||
dist/
|
||||
.vs
|
||||
.vscode
|
||||
#Electron-builder output
|
||||
|
||||
75
CHANGELOG.md
75
CHANGELOG.md
@@ -1,5 +1,80 @@
|
||||
# Changelog
|
||||
|
||||
## 0.8.0 (2020-11-01)
|
||||
|
||||
* add support for different recommendation levels: strict and standard | [commit](https://github.com/undergroundwires/privacy.sexy/commit/14be3017c55ed5e0d9bdecb63fcc4e1131e79ab0)
|
||||
* Add GroupMe and Spotify removal option (#34) | [commit](https://github.com/undergroundwires/privacy.sexy/commit/3785c623f837b182d82fa383dfe7709722a67248)
|
||||
* switch places of download and copy buttons | [commit](https://github.com/undergroundwires/privacy.sexy/commit/50fb29038ae19b17ec006093db02cf1e568d53c3)
|
||||
* change "download" button to "save" on desktop | [commit](https://github.com/undergroundwires/privacy.sexy/commit/07fc555324d8bf4fa3594a9701daaa124a873153)
|
||||
* show icons on cards during indeterminate and fully selected states | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1072505219edc47d82a91f148d1f310f32869fea)
|
||||
* add scripts to increase cryptography, enable camera notifications and remove todo app (#36) | [commit](https://github.com/undergroundwires/privacy.sexy/commit/4c68408f1ec339dc8d39c7ab044f825a7f7185cb)
|
||||
* update recommendations to be safer and consistent | [commit](https://github.com/undergroundwires/privacy.sexy/commit/d0019c2c9b1eea620e2e8e02b586903ce62b80e3)
|
||||
* rework disabling metadata retrieval | [commit](https://github.com/undergroundwires/privacy.sexy/commit/ac70b063b8a15bc528256185792939685be6b36f)
|
||||
* add all dist folders in gitignore because of files auto-generated by vscode | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1a9db31c7778c3269a71c0bd9665827efda70a02)
|
||||
* add support for shared functions #41 | [commit](https://github.com/undergroundwires/privacy.sexy/commit/8ce06facbd54184402a4b1af3c7303e64db85b8a)
|
||||
* hide scrollbars on code area when not overflowing | [commit](https://github.com/undergroundwires/privacy.sexy/commit/fd28eaad061c75ea1aa7e0f0d60ea37a7e52f8c4)
|
||||
* update screenshot | [commit](https://github.com/undergroundwires/privacy.sexy/commit/cfedcd724cad7708b30c7390a7bca3b6313b6726)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.6...0.8.0)
|
||||
|
||||
## 0.7.6 (2020-10-18)
|
||||
|
||||
* add docs for default0 pointing to github discussion (#30) | [commit](https://github.com/undergroundwires/privacy.sexy/commit/a3fc3782efd346b4c99d2a0b40df2eb0229f5b36)
|
||||
* add robots.txt to explicitly allow indexing | [commit](https://github.com/undergroundwires/privacy.sexy/commit/4c2f74949b0758d33049bdfa4f0124a28958f8ea)
|
||||
* add more reversibility | [commit](https://github.com/undergroundwires/privacy.sexy/commit/19a092dd31fb3588277f1ab3120b409d98506752)
|
||||
* refactor to read more from package.json | [commit](https://github.com/undergroundwires/privacy.sexy/commit/784a67afff681bc19147d03c947de0e165d97e87)
|
||||
* simplify "why" section | [commit](https://github.com/undergroundwires/privacy.sexy/commit/77c3d2bbb8d13db86bb82ed0b5cbeaacfdea3db9)
|
||||
* update dependencies to latest | [commit](https://github.com/undergroundwires/privacy.sexy/commit/11e06131655398db08faeeacff62062e46e0dddd)
|
||||
* run tests on all operating systems: macos, ubuntu, windows | [commit](https://github.com/undergroundwires/privacy.sexy/commit/d9d7f62d81d4d8f95104d33211e82641884d711f)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.5...0.7.6)
|
||||
|
||||
## 0.7.5 (2020-09-14)
|
||||
|
||||
* fix reverting (reinstalling) capabilities not working | [commit](https://github.com/undergroundwires/privacy.sexy/commit/939d838e3535bb1c9b00c8ea9dacb735ae41d700)
|
||||
* fix tests and checks are not running on PRs | [commit](https://github.com/undergroundwires/privacy.sexy/commit/82d509129b4e4a5df4b84786a0d6842a7d26e888)
|
||||
* fix the recycling bin option (#32) | [commit](https://github.com/undergroundwires/privacy.sexy/commit/15db3118012a172a2191a2afad57084a65b34642)
|
||||
* fix rendering issue in older edge/IE | [commit](https://github.com/undergroundwires/privacy.sexy/commit/6efed72bf25c2ddf0901caab7f22966ca13cd47a)
|
||||
* fix pasting in search bar after page load showing no results | [commit](https://github.com/undergroundwires/privacy.sexy/commit/d1694341578288eeaf8b80caf9296a38d76789f0)
|
||||
* fix typo | [commit](https://github.com/undergroundwires/privacy.sexy/commit/7dd15ed06433e0e6583ab0fa46a683ce6554bbea)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.4...0.7.5)
|
||||
|
||||
## 0.7.4 (2020-09-12)
|
||||
|
||||
* fix checked checkbox has blue border | [commit](https://github.com/undergroundwires/privacy.sexy/commit/4ae385b7fcea9014a68442714b7d99e2ee7df7d0)
|
||||
* fix spectre protection getting single lined #31 | [commit](https://github.com/undergroundwires/privacy.sexy/commit/22b23a9ece446c7f9abd4ede293051eb616ad50a)
|
||||
* fix missing reg value in denying app access to account | [commit](https://github.com/undergroundwires/privacy.sexy/commit/3c13a9e837e06e097450b31d7eb0c0e6bf20cefb)
|
||||
* fix wrong path in clear all firefox user profile settings | [commit](https://github.com/undergroundwires/privacy.sexy/commit/ee66196d9a60f27d17ae7f62d02b4f119a47e6e0)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.3...0.7.4)
|
||||
|
||||
## 0.7.3 (2020-09-12)
|
||||
|
||||
* fix vscode settings file override and add more configs | [commit](https://github.com/undergroundwires/privacy.sexy/commit/a0d61728ead04b4455437f85820121a848db9e00)
|
||||
* fix nvidia tweak error message, categorize and add reversibility | [commit](https://github.com/undergroundwires/privacy.sexy/commit/99a2035fdb0766a4dfc2753133eab0d7666516cd)
|
||||
* improve CPU specific tweaks by conditional platform checks and reversibility | [commit](https://github.com/undergroundwires/privacy.sexy/commit/8df5faf4ef05a49da63973bd0fbb5c5d07d5bd93)
|
||||
* fix wrong path to the main telemetry file | [commit](https://github.com/undergroundwires/privacy.sexy/commit/de4ac978bdda79573b36d355697b8a028d2c0beb)
|
||||
* fix naming of firefox cleanup to mention profiles | [commit](https://github.com/undergroundwires/privacy.sexy/commit/3ab48b1cf5f7f934f07e468ef2318ccee07f530c)
|
||||
* add reversibility and more scripts to denying app access with better structure | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1d465ee3189d0e5a827453b3f0eb4361efe23770)
|
||||
* fix comment lines are being detected as duplicate in validation | [commit](https://github.com/undergroundwires/privacy.sexy/commit/b6ccb5927a20412976a54fd2215eb645092f98a8)
|
||||
* add more detailed error message | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1f11c39773c12eccfb3efb898b58c2f6f37ab9ca)
|
||||
* fix typo in a test | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1f19b2528a69383e63e579d2885f01cd804abf6c)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.2...0.7.3)
|
||||
|
||||
## 0.7.2 (2020-09-06)
|
||||
|
||||
* update onesync documentation and do not recommend it as it breaks other apps | [commit](https://github.com/undergroundwires/privacy.sexy/commit/f36d8bfc7848bb65ac0c641e318a689bf3816ccf)
|
||||
* add reversibility for biometric disabling and do not recommend it | [commit](https://github.com/undergroundwires/privacy.sexy/commit/db74531cd4139615c6d595959217d3651f099019)
|
||||
* fix bad highlighting of selected nodes when using keyboard navigation | [commit](https://github.com/undergroundwires/privacy.sexy/commit/255133af4dfae40171406648a3e2920f16d71cb3)
|
||||
* add reversibility to removing bloatware | [commit](https://github.com/undergroundwires/privacy.sexy/commit/c7b2a703128470a05f12c9c6e8002444def37ef8)
|
||||
* fix indeterminate state being lost | [commit](https://github.com/undergroundwires/privacy.sexy/commit/1f266c33535f72b69c65985bf2eff27cd2c5a104)
|
||||
* fix wording in default text in text area | [commit](https://github.com/undergroundwires/privacy.sexy/commit/ca63a0979ef55d07d09d9443e5cea9aa888870a5)
|
||||
* add best practice suggestion to come back | [commit](https://github.com/undergroundwires/privacy.sexy/commit/f4885b6f1c82752f2143934e336d6d1b1af03015)
|
||||
|
||||
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.7.1...0.7.2)
|
||||
|
||||
## 0.7.1 (2020-09-04)
|
||||
|
||||
* fix some browsers (including firefox) downloading the script as a text file | [commit](https://github.com/undergroundwires/privacy.sexy/commit/8c17929151f9c4fa5f48564492bbf400ced95eea)
|
||||
|
||||
@@ -25,12 +25,6 @@
|
||||
|
||||
## Guidelines
|
||||
|
||||
### Extend scripts
|
||||
|
||||
- Create a [pull request](#Pull-Request-Process) for [application.yaml](./src/application/application.yaml)
|
||||
- 🙏 For any new script, try to add `revertCode` that'll revert the changes caused by the script.
|
||||
- See [typings](./src/application/application.yaml.d.ts) for documentation as code.
|
||||
|
||||
### Handle the state in presentation layer
|
||||
|
||||
- There are two types of components:
|
||||
|
||||
22
README.md
22
README.md
@@ -15,26 +15,26 @@
|
||||
## Get started
|
||||
|
||||
- Online version: [https://privacy.sexy](https://privacy.sexy)
|
||||
- or download latest desktop version for [Windows](https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.1/privacy.sexy-Setup-0.7.1.exe), [Linux](https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.1/privacy.sexy-0.7.1.AppImage), [macOS](https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.1/privacy.sexy-0.7.1.dmg)
|
||||
- or download latest desktop version for [Windows](https://github.com/undergroundwires/privacy.sexy/releases/download/0.8.0/privacy.sexy-Setup-0.8.0.exe), [Linux](https://github.com/undergroundwires/privacy.sexy/releases/download/0.8.0/privacy.sexy-0.8.0.AppImage), [macOS](https://github.com/undergroundwires/privacy.sexy/releases/download/0.8.0/privacy.sexy-0.8.0.dmg)
|
||||
- 💡 Come back regularly to apply latest version for stronger privacy and security.
|
||||
|
||||
[](https://privacy.sexy)
|
||||
|
||||
## Why
|
||||
|
||||
- You don't need to run any compiled software that has access to your system, just run the generated scripts.
|
||||
- Have full visibility into what the tweaks do as you enable them.
|
||||
- Ability to revert applied scripts
|
||||
- Rich tweak pool to harden security & privacy of the OS and other software on it
|
||||
- Free (both free as in beer and free as in speech)
|
||||
- No need to run any compiled software that has access to your system, just run the generated scripts
|
||||
- Have full visibility into what the tweaks do as you enable them
|
||||
- Ability to revert (undo) applied scripts
|
||||
- Everything is transparent: both application and its infrastructure are open-source and automated
|
||||
- Easily extendable
|
||||
- Everything is open-sourced including both application and infrastructure
|
||||
- Fully automated CI/CD pipeline using GitHub actions
|
||||
- to AWS for provisioning serverless infrastructure
|
||||
- for building and sharing the desktop applications
|
||||
|
||||
## Extend scripts
|
||||
|
||||
- Fork it & add more scripts in [application.yaml](src/application/application.yaml) and send a pull request 👌
|
||||
- 📖 More: [extend scripts | CONTRIBUTING.md](./CONTRIBUTING.md#extend-scripts)
|
||||
- 📖 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.
|
||||
|
||||
## Commands
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
- Development: `npm run serve` to compile & hot-reload for development.
|
||||
- Production: `npm run build` to prepare files for distribution.
|
||||
- Or run using Docker:
|
||||
1. Build: `docker build -t undergroundwires/privacy.sexy:0.7.1 .`
|
||||
2. Run: `docker run -it -p 8080:80 --rm --name privacy.sexy-0.7.1 undergroundwires/privacy.sexy:0.7.1`
|
||||
1. Build: `docker build -t undergroundwires/privacy.sexy:0.8.0 .`
|
||||
2. Run: `docker run -it -p 8080:80 --rm --name privacy.sexy-0.8.0 undergroundwires/privacy.sexy:0.8.0`
|
||||
|
||||
## Architecture
|
||||
|
||||
|
||||
139
docs/application-file.md
Normal file
139
docs/application-file.md
Normal file
@@ -0,0 +1,139 @@
|
||||
# Application file
|
||||
|
||||
- privacy.sexy is a data-driven application where it reads the necessary OS-specific logic from [`application.yaml`](./../src/application/application.yaml)
|
||||
- 💡 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)
|
||||
|
||||
## Objects
|
||||
|
||||
### `Application`
|
||||
|
||||
- Application file simply defines different categories and their scripts in a tree structure.
|
||||
- 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.
|
||||
|
||||
#### `Application` syntax
|
||||
|
||||
- `actions: [` ***[`Category`](#Category)*** `, ... ]` **(required)**
|
||||
- Each [category](#category) is rendered as different cards in card presentation.
|
||||
- ❗ Application must consist of at least one category.
|
||||
- `functions: [` ***[`Function`](#Function)*** `, ... ]`
|
||||
- Functions are optionally defined to re-use the same code throughout different scripts.
|
||||
|
||||
### `Category`
|
||||
|
||||
- Category has a parent that has tree-like structure where it can have subcategories or subscripts.
|
||||
- It's a logical grouping of different scripts and other categories.
|
||||
|
||||
#### `Category` syntax
|
||||
|
||||
- `category:` *`string`* (**required**)
|
||||
- Name of the category
|
||||
- ❗ Must be unique throughout the application
|
||||
- `children: [` ***[`Category`](#category)*** `|` [***`Script`***](#Script) `, ... ]` (**required**)
|
||||
- ❗ Category must consist of at least one subcategory or script.
|
||||
- Children can be combination of scripts and subcategories.
|
||||
|
||||
### `Script`
|
||||
|
||||
- Script represents a single tweak.
|
||||
- A script must include either:
|
||||
- A `code` and `revertCode`
|
||||
- Or `call` to call YAML-defined functions
|
||||
- 🙏 For any new script, please add `revertCode` and `docs` values if possible.
|
||||
|
||||
#### `Script` syntax
|
||||
|
||||
- `name`: *`string`* (**required**)
|
||||
- Name of the script
|
||||
- ❗ Must be unique throughout the application
|
||||
- E.g. `Disable targeted ads`
|
||||
- `code`: *`string`* (may be **required**)
|
||||
- Batch file commands that will be executed
|
||||
- 💡 If defined, best practice to also define `revertCode`
|
||||
- ❗ If not defined `call` must be defined, do not define if `call` is defined.
|
||||
- `revertCode`: `string`
|
||||
- Code that'll undo the change done by `code` property.
|
||||
- E.g. let's say `code` sets an environment variable as `setx POWERSHELL_TELEMETRY_OPTOUT 1`
|
||||
- then `revertCode` should be doing `setx POWERSHELL_TELEMETRY_OPTOUT 0`
|
||||
- ❗ Do not define if `call` is defined.
|
||||
- `call`: ***[`FunctionCall`](#FunctionCall)*** | `[` ***[`FunctionCall`](#FunctionCall)*** `, ... ]` (may be **required**)
|
||||
- A shared function or sequence of functions to call (called in order)
|
||||
- ❗ If not defined `code` must be defined
|
||||
- `docs`: *`string`* | `[`*`string`*`, ... ]`
|
||||
- Single documentation URL or list of URLs for those who wants to learn more about the script
|
||||
- E.g. `https://docs.microsoft.com/en-us/windows-server/`
|
||||
- `recommend`: `"standard"` | `"strict"` | `undefined` (default)
|
||||
- If not defined then the script will not be recommended
|
||||
- If defined it can be either
|
||||
- `standard`: Only non-breaking scripts without limiting OS functionality
|
||||
- `strict`: Scripts that can break certain functionality in favor of privacy and security
|
||||
|
||||
### `FunctionCall`
|
||||
|
||||
- Describes a single call to a function by optionally providing values to its parameters.
|
||||
- 👀 See [parameter substitution](#parameter-substitution) for an example usage
|
||||
|
||||
#### `FunctionCall` syntax
|
||||
|
||||
- `function`: *`string`* (**required**)
|
||||
- Name of the function to call.
|
||||
- ❗ Function with same name must defined in `functions` property of [Application](#application)
|
||||
- `parameters`: `[ parameterName:` *`parameterValue`*`, ... ]`
|
||||
- Defines key value dictionary for each parameter and its value
|
||||
- E.g.
|
||||
|
||||
```yaml
|
||||
parameters:
|
||||
userDefinedParameterName: parameterValue
|
||||
# ...
|
||||
appName: Microsoft.WindowsFeedbackHub
|
||||
```
|
||||
|
||||
### `Function`
|
||||
|
||||
- Functions allow re-usable code throughout the defined scripts.
|
||||
- Functions are templates compiled by privacy.sexy and uses special expressions.
|
||||
- Expressions are defined inside mustaches (double brackets, `{{` and `}}`)
|
||||
- 👀 See [parameter substitution](#parameter-substitution) for an example usage
|
||||
|
||||
#### Parameter substitution
|
||||
|
||||
A simple function example
|
||||
|
||||
```yaml
|
||||
function: EchoArgument
|
||||
parameters: [ 'argument' ]
|
||||
code: Hello {{ $argument }} !
|
||||
```
|
||||
|
||||
It would print "Hello world" if it's called in a [script](#script) as following:
|
||||
|
||||
```yaml
|
||||
script: Echo script
|
||||
call:
|
||||
function: EchoArgument
|
||||
parameters:
|
||||
argument: World
|
||||
```
|
||||
|
||||
#### `Function` syntax
|
||||
|
||||
- `name`: *`string`* (**required**)
|
||||
- Name of the function that scripts will use.
|
||||
- Convention is to use camelCase, and be verbs.
|
||||
- E.g. `uninstallStoreApp`
|
||||
- ❗ 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 names must be defined to be used in expressions such as [parameter substitution](#parameter-substitution)
|
||||
- ❗ Parameter names must be unique
|
||||
`code`: *`string`* (**required**)
|
||||
- Batch file commands that will be executed
|
||||
- 💡 If defined, best practice to also define `revertCode`
|
||||
- `revertCode`: *`string`*
|
||||
- Code that'll undo the change done by `code` property.
|
||||
- E.g. let's say `code` sets an environment variable as `setx POWERSHELL_TELEMETRY_OPTOUT 1`
|
||||
- then `revertCode` should be doing `setx POWERSHELL_TELEMETRY_OPTOUT 0`
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 52 KiB |
1453
package-lock.json
generated
1453
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@@ -1,9 +1,14 @@
|
||||
{
|
||||
"name": "privacy.sexy",
|
||||
"version": "0.7.1",
|
||||
"version": "0.8.0",
|
||||
"author": "undergroundwires",
|
||||
"description": "Enforce privacy & security best-practices on Windows, because privacy is sexy 🍑🍆",
|
||||
"homepage": "https://privacy.sexy",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/undergroundwires/privacy.sexy.git"
|
||||
},
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
@@ -21,44 +26,44 @@
|
||||
},
|
||||
"main": "background.js",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.30",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.14.0",
|
||||
"@fortawesome/free-regular-svg-icons": "^5.14.0",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.14.0",
|
||||
"@fortawesome/vue-fontawesome": "^0.1.10",
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.15.1",
|
||||
"@fortawesome/free-regular-svg-icons": "^5.15.1",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
||||
"@fortawesome/vue-fontawesome": "^2.0.0",
|
||||
"ace-builds": "^1.4.12",
|
||||
"file-saver": "^2.0.2",
|
||||
"inversify": "^5.0.1",
|
||||
"liquor-tree": "^0.2.70",
|
||||
"v-tooltip": "2.0.2",
|
||||
"vue": "^2.6.12",
|
||||
"vue-class-component": "^7.2.5",
|
||||
"vue-class-component": "^7.2.6",
|
||||
"vue-js-modal": "^2.0.0-rc.6",
|
||||
"vue-property-decorator": "^9.0.0"
|
||||
"vue-property-decorator": "^9.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ace": "0.0.43",
|
||||
"@types/chai": "^4.2.12",
|
||||
"@types/ace": "0.0.44",
|
||||
"@types/chai": "^4.2.14",
|
||||
"@types/file-saver": "^2.0.1",
|
||||
"@types/mocha": "^8.0.3",
|
||||
"@vue/cli-plugin-typescript": "^4.5.4",
|
||||
"@vue/cli-plugin-unit-mocha": "^4.5.4",
|
||||
"@vue/cli-service": "^4.5.4",
|
||||
"@vue/test-utils": "1.0.4",
|
||||
"@vue/cli-plugin-typescript": "^4.5.7",
|
||||
"@vue/cli-plugin-unit-mocha": "^4.5.7",
|
||||
"@vue/cli-service": "^4.5.7",
|
||||
"@vue/test-utils": "1.1.0",
|
||||
"chai": "^4.2.0",
|
||||
"electron": "^10.1.0",
|
||||
"electron": "^10.1.3",
|
||||
"electron-devtools-installer": "^3.1.1",
|
||||
"electron-log": "^4.2.4",
|
||||
"electron-updater": "^4.3.4",
|
||||
"electron-updater": "^4.3.5",
|
||||
"js-yaml-loader": "^1.2.2",
|
||||
"markdownlint-cli": "^0.23.2",
|
||||
"remark-cli": "^8.0.1",
|
||||
"markdownlint-cli": "^0.24.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-lint-no-dead-urls": "^1.1.0",
|
||||
"remark-preset-lint-consistent": "^3.0.1",
|
||||
"remark-preset-lint-consistent": "^4.0.0",
|
||||
"remark-validate-links": "^10.0.2",
|
||||
"sass": "^1.26.10",
|
||||
"sass-loader": "^10.0.1",
|
||||
"typescript": "^4.0.2",
|
||||
"sass": "^1.27.0",
|
||||
"sass-loader": "^10.0.3",
|
||||
"typescript": "^4.0.3",
|
||||
"vue-cli-plugin-electron-builder": "^2.0.0-rc.4",
|
||||
"vue-template-compiler": "^2.6.12",
|
||||
"yaml-lint": "^1.2.4"
|
||||
|
||||
2
public/robots.txt
Normal file
2
public/robots.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OperatingSystem } from '../OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { DetectorBuilder } from './DetectorBuilder';
|
||||
import { IBrowserOsDetector } from './IBrowserOsDetector';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IBrowserOsDetector } from './IBrowserOsDetector';
|
||||
import { OperatingSystem } from '../OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export class DetectorBuilder {
|
||||
private readonly existingPartsInUserAgent = new Array<string>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OperatingSystem } from '../OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export interface IBrowserOsDetector {
|
||||
detect(userAgent: string): OperatingSystem;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BrowserOsDetector } from './BrowserOs/BrowserOsDetector';
|
||||
import { IBrowserOsDetector } from './BrowserOs/IBrowserOsDetector';
|
||||
import { IEnvironment } from './IEnvironment';
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
interface IEnvironmentVariables {
|
||||
readonly window: Window & typeof globalThis;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export interface IEnvironment {
|
||||
isDesktop: boolean;
|
||||
|
||||
@@ -1,24 +1,37 @@
|
||||
import { Category } from '@/domain/Category';
|
||||
import { Application } from '@/domain/Application';
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { ApplicationYaml } from 'js-yaml-loader!./../application.yaml';
|
||||
import { parseCategory } from './CategoryParser';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { ScriptCompiler } from './Compiler/ScriptCompiler';
|
||||
|
||||
export function parseApplication(content: ApplicationYaml): IApplication {
|
||||
|
||||
export function parseApplication(content: ApplicationYaml, env: NodeJS.ProcessEnv = process.env): IApplication {
|
||||
validate(content);
|
||||
const compiler = new ScriptCompiler(content.functions);
|
||||
const categories = new Array<Category>();
|
||||
for (const action of content.actions) {
|
||||
const category = parseCategory(action);
|
||||
const category = parseCategory(action, compiler);
|
||||
categories.push(category);
|
||||
}
|
||||
const info = readAppInformation(env);
|
||||
const app = new Application(
|
||||
content.name,
|
||||
content.repositoryUrl,
|
||||
process.env.VUE_APP_VERSION,
|
||||
info,
|
||||
categories);
|
||||
return app;
|
||||
}
|
||||
|
||||
function readAppInformation(environment: NodeJS.ProcessEnv): IProjectInformation {
|
||||
return new ProjectInformation(
|
||||
environment.VUE_APP_NAME,
|
||||
environment.VUE_APP_VERSION,
|
||||
environment.VUE_APP_REPOSITORY_URL,
|
||||
environment.VUE_APP_HOMEPAGE_URL,
|
||||
);
|
||||
}
|
||||
|
||||
function validate(content: ApplicationYaml): void {
|
||||
if (!content) {
|
||||
throw new Error('application is null or undefined');
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Script } from '@/domain/Script';
|
||||
import { Category } from '@/domain/Category';
|
||||
import { parseDocUrls } from './DocumentationParser';
|
||||
import { parseScript } from './ScriptParser';
|
||||
import { IScriptCompiler } from './Compiler/IScriptCompiler';
|
||||
|
||||
let categoryIdCounter: number = 0;
|
||||
|
||||
@@ -11,14 +12,17 @@ interface ICategoryChildren {
|
||||
subScripts: Script[];
|
||||
}
|
||||
|
||||
export function parseCategory(category: YamlCategory): Category {
|
||||
export function parseCategory(category: YamlCategory, compiler: IScriptCompiler): Category {
|
||||
if (!compiler) {
|
||||
throw new Error('undefined compiler');
|
||||
}
|
||||
ensureValid(category);
|
||||
const children: ICategoryChildren = {
|
||||
subCategories: new Array<Category>(),
|
||||
subScripts: new Array<Script>(),
|
||||
};
|
||||
for (const categoryOrScript of category.children) {
|
||||
parseCategoryChild(categoryOrScript, children, category);
|
||||
parseCategoryChild(categoryOrScript, children, category, compiler);
|
||||
}
|
||||
return new Category(
|
||||
/*id*/ categoryIdCounter++,
|
||||
@@ -42,22 +46,26 @@ function ensureValid(category: YamlCategory) {
|
||||
}
|
||||
|
||||
function parseCategoryChild(
|
||||
categoryOrScript: any, children: ICategoryChildren, parent: YamlCategory) {
|
||||
categoryOrScript: any,
|
||||
children: ICategoryChildren,
|
||||
parent: YamlCategory,
|
||||
compiler: IScriptCompiler) {
|
||||
if (isCategory(categoryOrScript)) {
|
||||
const subCategory = parseCategory(categoryOrScript as YamlCategory);
|
||||
const subCategory = parseCategory(categoryOrScript as YamlCategory, compiler);
|
||||
children.subCategories.push(subCategory);
|
||||
} else if (isScript(categoryOrScript)) {
|
||||
const yamlScript = categoryOrScript as YamlScript;
|
||||
const script = parseScript(yamlScript);
|
||||
const script = parseScript(yamlScript, compiler);
|
||||
children.subScripts.push(script);
|
||||
} else {
|
||||
throw new Error(`Child element is neither a category or a script.
|
||||
Parent: ${parent.category}, element: ${categoryOrScript}`);
|
||||
Parent: ${parent.category}, element: ${JSON.stringify(categoryOrScript)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function isScript(categoryOrScript: any): boolean {
|
||||
return categoryOrScript.code && categoryOrScript.code.length > 0;
|
||||
return (categoryOrScript.code && categoryOrScript.code.length > 0)
|
||||
|| categoryOrScript.call;
|
||||
}
|
||||
|
||||
function isCategory(categoryOrScript: any): boolean {
|
||||
|
||||
7
src/application/Parser/Compiler/IScriptCompiler.ts
Normal file
7
src/application/Parser/Compiler/IScriptCompiler.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
|
||||
export interface IScriptCompiler {
|
||||
canCompile(script: YamlScript): boolean;
|
||||
compile(script: YamlScript): IScriptCode;
|
||||
}
|
||||
200
src/application/Parser/Compiler/ScriptCompiler.ts
Normal file
200
src/application/Parser/Compiler/ScriptCompiler.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { YamlScript, YamlFunction, FunctionCall, ScriptFunctionCall, FunctionCallParameters } from 'js-yaml-loader!./application.yaml';
|
||||
import { IScriptCompiler } from './IScriptCompiler';
|
||||
|
||||
interface ICompiledCode {
|
||||
readonly code: string;
|
||||
readonly revertCode: string;
|
||||
}
|
||||
|
||||
export class ScriptCompiler implements IScriptCompiler {
|
||||
constructor(private readonly functions: readonly YamlFunction[]) {
|
||||
ensureValidFunctions(functions);
|
||||
}
|
||||
public canCompile(script: YamlScript): boolean {
|
||||
if (!script.call) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public compile(script: YamlScript): IScriptCode {
|
||||
this.ensureCompilable(script.call);
|
||||
const compiledCodes = new Array<ICompiledCode>();
|
||||
const calls = getCallSequence(script.call);
|
||||
calls.forEach((currentCall, currentCallIndex) => {
|
||||
ensureValidCall(currentCall, script.name);
|
||||
const commonFunction = this.getFunctionByName(currentCall.function);
|
||||
let functionCode = compileCode(commonFunction, currentCall.parameters);
|
||||
if (currentCallIndex !== calls.length - 1) {
|
||||
functionCode = appendLine(functionCode);
|
||||
}
|
||||
compiledCodes.push(functionCode);
|
||||
});
|
||||
const scriptCode = merge(compiledCodes);
|
||||
return new ScriptCode(script.name, scriptCode.code, scriptCode.revertCode);
|
||||
}
|
||||
|
||||
private getFunctionByName(name: string): YamlFunction {
|
||||
const func = this.functions.find((f) => f.name === name);
|
||||
if (!func) {
|
||||
throw new Error(`called function is not defined "${name}"`);
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
||||
private ensureCompilable(call: ScriptFunctionCall) {
|
||||
if (!this.functions || this.functions.length === 0) {
|
||||
throw new Error('cannot compile without shared functions');
|
||||
}
|
||||
if (typeof call !== 'object') {
|
||||
throw new Error('called function(s) must be an object');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getDuplicates(texts: readonly string[]): string[] {
|
||||
return texts.filter((item, index) => texts.indexOf(item) !== index);
|
||||
}
|
||||
|
||||
function printList(list: readonly string[]): string {
|
||||
return `"${list.join('","')}"`;
|
||||
}
|
||||
|
||||
function ensureNoDuplicatesInFunctionNames(functions: readonly YamlFunction[]) {
|
||||
const duplicateFunctionNames = getDuplicates(functions
|
||||
.map((func) => func.name.toLowerCase()));
|
||||
if (duplicateFunctionNames.length) {
|
||||
throw new Error(`duplicate function name: ${printList(duplicateFunctionNames)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureNoDuplicatesInParameterNames(functions: readonly YamlFunction[]) {
|
||||
const functionsWithParameters = functions
|
||||
.filter((func) => func.parameters && func.parameters.length > 0);
|
||||
for (const func of functionsWithParameters) {
|
||||
const duplicateParameterNames = getDuplicates(func.parameters);
|
||||
if (duplicateParameterNames.length) {
|
||||
throw new Error(`"${func.name}": duplicate parameter name: ${printList(duplicateParameterNames)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ensureNoDuplicateCode(functions: readonly YamlFunction[]) {
|
||||
const duplicateCodes = getDuplicates(functions.map((func) => func.code));
|
||||
if (duplicateCodes.length > 0) {
|
||||
throw new Error(`duplicate "code" in functions: ${printList(duplicateCodes)}`);
|
||||
}
|
||||
const duplicateRevertCodes = getDuplicates(functions
|
||||
.filter((func) => func.revertCode)
|
||||
.map((func) => func.revertCode));
|
||||
if (duplicateRevertCodes.length > 0) {
|
||||
throw new Error(`duplicate "revertCode" in functions: ${printList(duplicateRevertCodes)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureValidFunctions(functions: readonly YamlFunction[]) {
|
||||
if (!functions) {
|
||||
return;
|
||||
}
|
||||
ensureNoDuplicatesInFunctionNames(functions);
|
||||
ensureNoDuplicatesInParameterNames(functions);
|
||||
ensureNoDuplicateCode(functions);
|
||||
}
|
||||
|
||||
function appendLine(code: ICompiledCode): ICompiledCode {
|
||||
const appendLineIfNotEmpty = (str: string) => str ? `${str}\n` : str;
|
||||
return {
|
||||
code: appendLineIfNotEmpty(code.code),
|
||||
revertCode: appendLineIfNotEmpty(code.revertCode),
|
||||
};
|
||||
}
|
||||
|
||||
function merge(codes: readonly ICompiledCode[]): ICompiledCode {
|
||||
return {
|
||||
code: codes.map((code) => code.code).join(''),
|
||||
revertCode: codes.map((code) => code.revertCode).join(''),
|
||||
};
|
||||
}
|
||||
|
||||
function compileCode(func: YamlFunction, parameters: FunctionCallParameters): ICompiledCode {
|
||||
return {
|
||||
code: compileExpressions(func.code, parameters),
|
||||
revertCode: compileExpressions(func.revertCode, parameters),
|
||||
};
|
||||
}
|
||||
|
||||
function compileExpressions(code: string, parameters: FunctionCallParameters): string {
|
||||
let intermediateCode = compileToIL(code);
|
||||
intermediateCode = substituteParameters(intermediateCode, parameters);
|
||||
ensureNoExpressionLeft(intermediateCode);
|
||||
return intermediateCode;
|
||||
}
|
||||
|
||||
function substituteParameters(intermediateCode: string, parameters: FunctionCallParameters): string {
|
||||
const parameterNames = getUniqueParameterNamesFromIL(intermediateCode);
|
||||
if (parameterNames.length && !parameters) {
|
||||
throw new Error(`no parameters defined, expected: ${printList(parameterNames)}`);
|
||||
}
|
||||
for (const parameterName of parameterNames) {
|
||||
const parameterValue = parameters[parameterName];
|
||||
intermediateCode = substituteParameter(intermediateCode, parameterName, parameterValue);
|
||||
}
|
||||
return intermediateCode;
|
||||
}
|
||||
|
||||
function ensureValidCall(call: FunctionCall, scriptName: string) {
|
||||
if (!call) {
|
||||
throw new Error(`undefined function call in script "${scriptName}"`);
|
||||
}
|
||||
if (!call.function) {
|
||||
throw new Error(`empty function name called in script "${scriptName}"`);
|
||||
}
|
||||
}
|
||||
|
||||
function getCallSequence(call: ScriptFunctionCall): FunctionCall[] {
|
||||
if (call instanceof Array) {
|
||||
return call as FunctionCall[];
|
||||
}
|
||||
return [ call as FunctionCall ];
|
||||
}
|
||||
|
||||
function getDistinctValues(values: readonly string[]): string[] {
|
||||
return values.filter((value, index, self) => {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
}
|
||||
|
||||
// Trim each expression and put them inside "{{exp|}}" e.g. "{{ $hello }}" becomes "{{exp|$hello}}"
|
||||
function compileToIL(code: string) {
|
||||
return code.replace(/\{\{([\s]*[^;\s\{]+[\s]*)\}\}/g, (_, match) => {
|
||||
return `\{\{exp|${match.trim()}\}\}`;
|
||||
});
|
||||
}
|
||||
|
||||
// Parses all distinct usages of {{exp|$parameterName}}
|
||||
function getUniqueParameterNamesFromIL(ilCode: string) {
|
||||
const allSubstitutions = ilCode.matchAll(/\{\{exp\|\$([^;\s\{]+[\s]*)\}\}/g);
|
||||
const allParameters = Array.from(allSubstitutions, (match) => match[1]);
|
||||
const uniqueParameterNames = getDistinctValues(allParameters);
|
||||
return uniqueParameterNames;
|
||||
}
|
||||
|
||||
// substitutes {{exp|$parameterName}} to value of the parameter
|
||||
function substituteParameter(ilCode: string, parameterName: string, parameterValue: string) {
|
||||
if (!parameterValue) {
|
||||
throw Error(`parameter value is not provided for "${parameterName}" in function call`);
|
||||
}
|
||||
const pattern = `{{exp|$${parameterName}}}`;
|
||||
return ilCode.split(pattern).join(parameterValue); // as .replaceAll() is not yet supported by TS
|
||||
}
|
||||
|
||||
// finds all "{{exp|..}} left"
|
||||
function ensureNoExpressionLeft(ilCode: string) {
|
||||
const allSubstitutions = ilCode.matchAll(/\{\{exp\|(.*?)\}\}/g);
|
||||
const allMatches = Array.from(allSubstitutions, (match) => match[1]);
|
||||
const uniqueExpressions = getDistinctValues(allMatches);
|
||||
if (uniqueExpressions.length > 0) {
|
||||
throw new Error(`unknown expression: ${printList(uniqueExpressions)}`);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,61 @@
|
||||
import { Script } from '@/domain/Script';
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import { parseDocUrls } from './DocumentationParser';
|
||||
import { RecommendationLevelNames, RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { IScriptCompiler } from './Compiler/IScriptCompiler';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
|
||||
export function parseScript(yamlScript: YamlScript): Script {
|
||||
if (!yamlScript) {
|
||||
throw new Error('script is null or undefined');
|
||||
export function parseScript(yamlScript: YamlScript, compiler: IScriptCompiler): Script {
|
||||
validateScript(yamlScript);
|
||||
if (!compiler) {
|
||||
throw new Error('undefined compiler');
|
||||
}
|
||||
const script = new Script(
|
||||
/* name */ yamlScript.name,
|
||||
/* code */ yamlScript.code,
|
||||
/* revertCode */ yamlScript.revertCode,
|
||||
/* code */ parseCode(yamlScript, compiler),
|
||||
/* docs */ parseDocUrls(yamlScript),
|
||||
/* isRecommended */ yamlScript.recommend);
|
||||
/* level */ getLevel(yamlScript.recommend));
|
||||
return script;
|
||||
}
|
||||
|
||||
function getLevel(level: string): RecommendationLevel | undefined {
|
||||
if (!level) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof level !== 'string') {
|
||||
throw new Error(`level must be a string but it was ${typeof level}`);
|
||||
}
|
||||
const typedLevel = RecommendationLevelNames
|
||||
.find((l) => l.toLowerCase() === level.toLowerCase());
|
||||
if (!typedLevel) {
|
||||
throw new Error(`unknown level: \"${level}\"`);
|
||||
}
|
||||
return RecommendationLevel[typedLevel as keyof typeof RecommendationLevel];
|
||||
}
|
||||
|
||||
function parseCode(yamlScript: YamlScript, compiler: IScriptCompiler): IScriptCode {
|
||||
if (compiler.canCompile(yamlScript)) {
|
||||
return compiler.compile(yamlScript);
|
||||
}
|
||||
return new ScriptCode(yamlScript.name, yamlScript.code, yamlScript.revertCode);
|
||||
}
|
||||
|
||||
function ensureNotBothCallAndCode(yamlScript: YamlScript) {
|
||||
if (yamlScript.code && yamlScript.call) {
|
||||
throw new Error('cannot define both "call" and "code"');
|
||||
}
|
||||
if (yamlScript.revertCode && yamlScript.call) {
|
||||
throw new Error('cannot define "revertCode" if "call" is defined');
|
||||
}
|
||||
}
|
||||
|
||||
function validateScript(yamlScript: YamlScript) {
|
||||
if (!yamlScript) {
|
||||
throw new Error('undefined script');
|
||||
}
|
||||
if (!yamlScript.code && !yamlScript.call) {
|
||||
throw new Error('must define either "call" or "code"');
|
||||
}
|
||||
ensureNotBothCallAndCode(yamlScript);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export class ApplicationState implements IApplicationState {
|
||||
/** Initially selected scripts */
|
||||
public readonly defaultScripts: Script[]) {
|
||||
this.selection = new UserSelection(app, defaultScripts.map((script) => new SelectedScript(script, false)));
|
||||
this.code = new ApplicationCode(this.selection, app.version);
|
||||
this.code = new ApplicationCode(this.selection, app.info.version);
|
||||
this.filter = new UserFilter(app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,6 @@ function appendSelection(
|
||||
|
||||
function appendCode(selection: SelectedScript, builder: CodeBuilder) {
|
||||
const name = selection.revert ? `${selection.script.name} (revert)` : selection.script.name;
|
||||
const scriptCode = selection.revert ? selection.script.revertCode : selection.script.code;
|
||||
const scriptCode = selection.revert ? selection.script.code.revert : selection.script.code.execute;
|
||||
builder.appendFunction(name, scriptCode);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { IFilterResult } from './IFilterResult';
|
||||
import { ISignal } from '@/infrastructure/Events/Signal';
|
||||
|
||||
export interface IUserFilter {
|
||||
readonly currentFilter: IFilterResult | undefined;
|
||||
readonly filtered: ISignal<IFilterResult>;
|
||||
readonly filterRemoved: ISignal<void>;
|
||||
setFilter(filter: string): void;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Signal } from '@/infrastructure/Events/Signal';
|
||||
export class UserFilter implements IUserFilter {
|
||||
public readonly filtered = new Signal<IFilterResult>();
|
||||
public readonly filterRemoved = new Signal<void>();
|
||||
public currentFilter: IFilterResult | undefined;
|
||||
|
||||
constructor(private application: IApplication) {
|
||||
|
||||
@@ -22,17 +23,17 @@ export class UserFilter implements IUserFilter {
|
||||
(script) => isScriptAMatch(script, filterLowercase));
|
||||
const filteredCategories = this.application.getAllCategories().filter(
|
||||
(category) => category.name.toLowerCase().includes(filterLowercase));
|
||||
|
||||
const matches = new FilterResult(
|
||||
filteredScripts,
|
||||
filteredCategories,
|
||||
filter,
|
||||
);
|
||||
|
||||
this.currentFilter = matches;
|
||||
this.filtered.notify(matches);
|
||||
}
|
||||
|
||||
public removeFilter(): void {
|
||||
this.currentFilter = undefined;
|
||||
this.filterRemoved.notify();
|
||||
}
|
||||
}
|
||||
@@ -41,11 +42,11 @@ function isScriptAMatch(script: IScript, filterLowercase: string) {
|
||||
if (script.name.toLowerCase().includes(filterLowercase)) {
|
||||
return true;
|
||||
}
|
||||
if (script.code.toLowerCase().includes(filterLowercase)) {
|
||||
if (script.code.execute.toLowerCase().includes(filterLowercase)) {
|
||||
return true;
|
||||
}
|
||||
if (script.revertCode) {
|
||||
return script.revertCode.toLowerCase().includes(filterLowercase);
|
||||
if (script.code.revert) {
|
||||
return script.code.revert.toLowerCase().includes(filterLowercase);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { SelectedScript } from './SelectedScript';
|
||||
import { ISignal } from '@/infrastructure/Events/Signal';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
|
||||
export interface IUserSelection {
|
||||
readonly changed: ISignal<ReadonlyArray<SelectedScript>>;
|
||||
readonly selectedScripts: ReadonlyArray<SelectedScript>;
|
||||
readonly totalSelected: number;
|
||||
areAllSelected(category: ICategory): boolean;
|
||||
isAnySelected(category: ICategory): boolean;
|
||||
removeAllInCategory(categoryId: number): void;
|
||||
addOrUpdateAllInCategory(categoryId: number, revert: boolean): void;
|
||||
addSelectedScript(scriptId: string, revert: boolean): void;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SelectedScript } from './SelectedScript';
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { IApplication, ICategory } from '@/domain/IApplication';
|
||||
import { IUserSelection } from './IUserSelection';
|
||||
import { InMemoryRepository } from '@/infrastructure/Repository/InMemoryRepository';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
@@ -21,6 +21,24 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
}
|
||||
|
||||
public areAllSelected(category: ICategory): boolean {
|
||||
if (this.selectedScripts.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const scripts = category.getAllScriptsRecursively();
|
||||
if (this.selectedScripts.length < scripts.length) {
|
||||
return false;
|
||||
}
|
||||
return scripts.every((script) => this.selectedScripts.some((selected) => selected.id === script.id));
|
||||
}
|
||||
|
||||
public isAnySelected(category: ICategory): boolean {
|
||||
if (this.selectedScripts.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return this.selectedScripts.some((s) => category.includes(s.script));
|
||||
}
|
||||
|
||||
public removeAllInCategory(categoryId: number): void {
|
||||
const category = this.app.findCategory(categoryId);
|
||||
const scriptsToRemove = category.getAllScriptsRecursively()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
48
src/application/application.yaml.d.ts
vendored
48
src/application/application.yaml.d.ts
vendored
@@ -1,16 +1,7 @@
|
||||
declare module 'js-yaml-loader!*' {
|
||||
export type CategoryOrScript = YamlCategory | YamlScript;
|
||||
export type DocumentationUrls = ReadonlyArray<string> | string;
|
||||
|
||||
export interface YamlDocumentable {
|
||||
docs?: DocumentationUrls;
|
||||
}
|
||||
|
||||
export interface YamlScript extends YamlDocumentable {
|
||||
name: string;
|
||||
code: string;
|
||||
revertCode: string;
|
||||
recommend: boolean;
|
||||
export interface ApplicationYaml {
|
||||
actions: ReadonlyArray<YamlCategory>;
|
||||
functions: ReadonlyArray<YamlFunction> | undefined;
|
||||
}
|
||||
|
||||
export interface YamlCategory extends YamlDocumentable {
|
||||
@@ -18,10 +9,37 @@ declare module 'js-yaml-loader!*' {
|
||||
category: string;
|
||||
}
|
||||
|
||||
export interface ApplicationYaml {
|
||||
export type CategoryOrScript = YamlCategory | YamlScript;
|
||||
export type DocumentationUrls = ReadonlyArray<string> | string;
|
||||
|
||||
export interface YamlDocumentable {
|
||||
docs?: DocumentationUrls;
|
||||
}
|
||||
|
||||
export interface YamlFunction {
|
||||
name: string;
|
||||
repositoryUrl: string;
|
||||
actions: ReadonlyArray<YamlCategory>;
|
||||
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;
|
||||
}
|
||||
|
||||
const content: ApplicationYaml;
|
||||
|
||||
@@ -2,45 +2,51 @@ import { IEntity } from '../infrastructure/Entity/IEntity';
|
||||
import { ICategory } from './ICategory';
|
||||
import { IScript } from './IScript';
|
||||
import { IApplication } from './IApplication';
|
||||
import { IProjectInformation } from './IProjectInformation';
|
||||
import { RecommendationLevel, RecommendationLevelNames, RecommendationLevels } from './RecommendationLevel';
|
||||
|
||||
export class Application implements IApplication {
|
||||
public get totalScripts(): number { return this.flattened.allScripts.length; }
|
||||
public get totalCategories(): number { return this.flattened.allCategories.length; }
|
||||
public get totalScripts(): number { return this.queryable.allScripts.length; }
|
||||
public get totalCategories(): number { return this.queryable.allCategories.length; }
|
||||
|
||||
private readonly flattened: IFlattenedApplication;
|
||||
private readonly queryable: IQueryableApplication;
|
||||
|
||||
constructor(
|
||||
public readonly name: string,
|
||||
public readonly repositoryUrl: string,
|
||||
public readonly version: string,
|
||||
public readonly info: IProjectInformation,
|
||||
public readonly actions: ReadonlyArray<ICategory>) {
|
||||
if (!name) { throw Error('Application has no name'); }
|
||||
if (!repositoryUrl) { throw Error('Application has no repository url'); }
|
||||
if (!version) { throw Error('Version cannot be empty'); }
|
||||
this.flattened = flatten(actions);
|
||||
ensureValid(this.flattened);
|
||||
ensureNoDuplicates(this.flattened.allCategories);
|
||||
ensureNoDuplicates(this.flattened.allScripts);
|
||||
if (!info) {
|
||||
throw new Error('info is undefined');
|
||||
}
|
||||
this.queryable = makeQueryable(actions);
|
||||
ensureValid(this.queryable);
|
||||
ensureNoDuplicates(this.queryable.allCategories);
|
||||
ensureNoDuplicates(this.queryable.allScripts);
|
||||
}
|
||||
|
||||
public findCategory(categoryId: number): ICategory | undefined {
|
||||
return this.flattened.allCategories.find((category) => category.id === categoryId);
|
||||
return this.queryable.allCategories.find((category) => category.id === categoryId);
|
||||
}
|
||||
|
||||
public getRecommendedScripts(): readonly IScript[] {
|
||||
return this.flattened.allScripts.filter((script) => script.isRecommended);
|
||||
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
|
||||
if (isNaN(level)) {
|
||||
throw new Error('undefined level');
|
||||
}
|
||||
if (!(level in RecommendationLevel)) {
|
||||
throw new Error(`invalid level: ${level}`);
|
||||
}
|
||||
return this.queryable.scriptsByLevel.get(level);
|
||||
}
|
||||
|
||||
public findScript(scriptId: string): IScript | undefined {
|
||||
return this.flattened.allScripts.find((script) => script.id === scriptId);
|
||||
return this.queryable.allScripts.find((script) => script.id === scriptId);
|
||||
}
|
||||
|
||||
public getAllScripts(): IScript[] {
|
||||
return this.flattened.allScripts;
|
||||
return this.queryable.allScripts;
|
||||
}
|
||||
|
||||
public getAllCategories(): ICategory[] {
|
||||
return this.flattened.allCategories;
|
||||
return this.queryable.allCategories;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,55 +68,85 @@ function ensureNoDuplicates<TKey>(entities: ReadonlyArray<IEntity<TKey>>) {
|
||||
}
|
||||
}
|
||||
|
||||
interface IFlattenedApplication {
|
||||
interface IQueryableApplication {
|
||||
allCategories: ICategory[];
|
||||
allScripts: IScript[];
|
||||
scriptsByLevel: Map<RecommendationLevel, readonly IScript[]>;
|
||||
}
|
||||
|
||||
function ensureValid(application: IFlattenedApplication) {
|
||||
if (!application.allCategories || application.allCategories.length === 0) {
|
||||
function ensureValid(application: IQueryableApplication) {
|
||||
ensureValidCategories(application.allCategories);
|
||||
ensureValidScripts(application.allScripts);
|
||||
}
|
||||
|
||||
function ensureValidCategories(allCategories: readonly ICategory[]) {
|
||||
if (!allCategories || allCategories.length === 0) {
|
||||
throw new Error('Application must consist of at least one category');
|
||||
}
|
||||
if (!application.allScripts || application.allScripts.length === 0) {
|
||||
}
|
||||
|
||||
function ensureValidScripts(allScripts: readonly IScript[]) {
|
||||
if (!allScripts || allScripts.length === 0) {
|
||||
throw new Error('Application must consist of at least one script');
|
||||
}
|
||||
if (application.allScripts.filter((script) => script.isRecommended).length === 0) {
|
||||
throw new Error('Application must consist of at least one recommended script');
|
||||
for (const level of RecommendationLevels) {
|
||||
if (allScripts.every((script) => script.level !== level)) {
|
||||
throw new Error(`none of the scripts are recommended as ${RecommendationLevel[level]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function flattenApplication(categories: ReadonlyArray<ICategory>): [ICategory[], IScript[]] {
|
||||
const allCategories = new Array<ICategory>();
|
||||
const allScripts = new Array<IScript>();
|
||||
flattenCategories(categories, allCategories, allScripts);
|
||||
return [
|
||||
allCategories,
|
||||
allScripts,
|
||||
];
|
||||
}
|
||||
|
||||
function flattenCategories(
|
||||
categories: ReadonlyArray<ICategory>,
|
||||
flattened: IFlattenedApplication): IFlattenedApplication {
|
||||
allCategories: ICategory[],
|
||||
allScripts: IScript[]): IQueryableApplication {
|
||||
if (!categories || categories.length === 0) {
|
||||
return flattened;
|
||||
return;
|
||||
}
|
||||
for (const category of categories) {
|
||||
flattened.allCategories.push(category);
|
||||
flattened = flattenScripts(category.scripts, flattened);
|
||||
flattened = flattenCategories(category.subCategories, flattened);
|
||||
allCategories.push(category);
|
||||
flattenScripts(category.scripts, allScripts);
|
||||
flattenCategories(category.subCategories, allCategories, allScripts);
|
||||
}
|
||||
return flattened;
|
||||
}
|
||||
|
||||
function flattenScripts(
|
||||
scripts: ReadonlyArray<IScript>,
|
||||
flattened: IFlattenedApplication): IFlattenedApplication {
|
||||
allScripts: IScript[]): IScript[] {
|
||||
if (!scripts) {
|
||||
return flattened;
|
||||
return;
|
||||
}
|
||||
for (const script of scripts) {
|
||||
flattened.allScripts.push(script);
|
||||
allScripts.push(script);
|
||||
}
|
||||
return flattened;
|
||||
}
|
||||
|
||||
function flatten(
|
||||
categories: ReadonlyArray<ICategory>): IFlattenedApplication {
|
||||
let flattened: IFlattenedApplication = {
|
||||
allCategories: new Array<ICategory>(),
|
||||
allScripts: new Array<IScript>(),
|
||||
function makeQueryable(
|
||||
actions: ReadonlyArray<ICategory>): IQueryableApplication {
|
||||
const flattened = flattenApplication(actions);
|
||||
return {
|
||||
allCategories: flattened[0],
|
||||
allScripts: flattened[1],
|
||||
scriptsByLevel: groupByLevel(flattened[1]),
|
||||
};
|
||||
flattened = flattenCategories(categories, flattened);
|
||||
return flattened;
|
||||
}
|
||||
|
||||
function groupByLevel(allScripts: readonly IScript[]): Map<RecommendationLevel, readonly IScript[]> {
|
||||
const map = new Map<RecommendationLevel, readonly IScript[]>();
|
||||
for (const levelName of RecommendationLevelNames) {
|
||||
const level = RecommendationLevel[levelName];
|
||||
const scripts = allScripts.filter((script) => script.level !== undefined && script.level <= level);
|
||||
map.set(level, scripts);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ export class Category extends BaseEntity<number> implements ICategory {
|
||||
validateCategory(this);
|
||||
}
|
||||
|
||||
public includes(script: IScript): boolean {
|
||||
return this.getAllScriptsRecursively().some((childScript) => childScript.id === script.id);
|
||||
}
|
||||
|
||||
public getAllScriptsRecursively(): readonly IScript[] {
|
||||
return this.allSubScripts || (this.allSubScripts = parseScriptsRecursively(this));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { IProjectInformation } from './IProjectInformation';
|
||||
import { RecommendationLevel } from './RecommendationLevel';
|
||||
|
||||
export interface IApplication {
|
||||
readonly name: string;
|
||||
readonly repositoryUrl: string;
|
||||
readonly version: string;
|
||||
readonly info: IProjectInformation;
|
||||
readonly totalScripts: number;
|
||||
readonly totalCategories: number;
|
||||
readonly actions: ReadonlyArray<ICategory>;
|
||||
|
||||
getRecommendedScripts(): ReadonlyArray<IScript>;
|
||||
getScriptsByLevel(level: RecommendationLevel): ReadonlyArray<IScript>;
|
||||
findCategory(categoryId: number): ICategory | undefined;
|
||||
findScript(scriptId: string): IScript | undefined;
|
||||
getAllScripts(): ReadonlyArray<IScript>;
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface ICategory extends IEntity<number>, IDocumentable {
|
||||
readonly name: string;
|
||||
readonly subCategories?: ReadonlyArray<ICategory>;
|
||||
readonly scripts?: ReadonlyArray<IScript>;
|
||||
includes(script: IScript): boolean;
|
||||
getAllScriptsRecursively(): ReadonlyArray<IScript>;
|
||||
}
|
||||
|
||||
|
||||
11
src/domain/IProjectInformation.ts
Normal file
11
src/domain/IProjectInformation.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
export interface IProjectInformation {
|
||||
readonly name: string;
|
||||
readonly version: string;
|
||||
readonly repositoryUrl: string;
|
||||
readonly homepage: string;
|
||||
readonly feedbackUrl: string;
|
||||
readonly releaseUrl: string;
|
||||
readonly repositoryWebUrl: string;
|
||||
getDownloadUrl(os: OperatingSystem): string;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import { IEntity } from '../infrastructure/Entity/IEntity';
|
||||
import { IDocumentable } from './IDocumentable';
|
||||
import { RecommendationLevel } from './RecommendationLevel';
|
||||
import { IScriptCode } from './IScriptCode';
|
||||
|
||||
export interface IScript extends IEntity<string>, IDocumentable {
|
||||
readonly name: string;
|
||||
readonly isRecommended: boolean;
|
||||
readonly level?: RecommendationLevel;
|
||||
readonly documentationUrls: ReadonlyArray<string>;
|
||||
readonly code: string;
|
||||
readonly revertCode: string;
|
||||
readonly code: IScriptCode;
|
||||
canRevert(): boolean;
|
||||
}
|
||||
|
||||
4
src/domain/IScriptCode.ts
Normal file
4
src/domain/IScriptCode.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface IScriptCode {
|
||||
readonly execute: string;
|
||||
readonly revert: string;
|
||||
}
|
||||
55
src/domain/ProjectInformation.ts
Normal file
55
src/domain/ProjectInformation.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { IProjectInformation } from './IProjectInformation';
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
|
||||
export class ProjectInformation implements IProjectInformation {
|
||||
public readonly repositoryWebUrl: string;
|
||||
constructor(
|
||||
public readonly name: string,
|
||||
public readonly version: string,
|
||||
public readonly repositoryUrl: string,
|
||||
public readonly homepage: string,
|
||||
) {
|
||||
if (!name) {
|
||||
throw new Error('name is undefined');
|
||||
}
|
||||
if (!version || +version <= 0) {
|
||||
throw new Error('version should be higher than zero');
|
||||
}
|
||||
if (!repositoryUrl) {
|
||||
throw new Error('repositoryUrl is undefined');
|
||||
}
|
||||
if (!homepage) {
|
||||
throw new Error('homepage is undefined');
|
||||
}
|
||||
this.repositoryWebUrl = getWebUrl(this.repositoryUrl);
|
||||
}
|
||||
public getDownloadUrl(os: OperatingSystem): string {
|
||||
return `${this.repositoryWebUrl}/releases/download/${this.version}/${getFileName(os, this.version)}`;
|
||||
}
|
||||
public get feedbackUrl(): string {
|
||||
return `${this.repositoryWebUrl}/issues`;
|
||||
}
|
||||
public get releaseUrl(): string {
|
||||
return `${this.repositoryWebUrl}/releases/tag/${this.version}`;
|
||||
}
|
||||
}
|
||||
|
||||
function getWebUrl(gitUrl: string) {
|
||||
if (gitUrl.endsWith('.git')) {
|
||||
return gitUrl.substring(0, gitUrl.length - 4);
|
||||
}
|
||||
return gitUrl;
|
||||
}
|
||||
|
||||
function getFileName(os: OperatingSystem, version: string): string {
|
||||
switch (os) {
|
||||
case OperatingSystem.Linux:
|
||||
return `privacy.sexy-${version}.AppImage`;
|
||||
case OperatingSystem.macOS:
|
||||
return `privacy.sexy-${version}.dmg`;
|
||||
case OperatingSystem.Windows:
|
||||
return `privacy.sexy-Setup-${version}.exe`;
|
||||
default:
|
||||
throw new Error(`Unsupported os: ${OperatingSystem[os]}`);
|
||||
}
|
||||
}
|
||||
11
src/domain/RecommendationLevel.ts
Normal file
11
src/domain/RecommendationLevel.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export enum RecommendationLevel {
|
||||
Standard = 0,
|
||||
Strict = 1,
|
||||
}
|
||||
|
||||
export const RecommendationLevelNames = Object
|
||||
.values(RecommendationLevel)
|
||||
.filter((level) => typeof level === 'string') as string[];
|
||||
|
||||
export const RecommendationLevels = RecommendationLevelNames
|
||||
.map((level) => RecommendationLevel[level]) as RecommendationLevel[];
|
||||
@@ -1,57 +1,27 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import { IScript } from './IScript';
|
||||
import { RecommendationLevel } from './RecommendationLevel';
|
||||
import { IScriptCode } from './IScriptCode';
|
||||
|
||||
export class Script extends BaseEntity<string> implements IScript {
|
||||
constructor(
|
||||
public readonly name: string,
|
||||
public readonly code: string,
|
||||
public readonly revertCode: string,
|
||||
public readonly code: IScriptCode,
|
||||
public readonly documentationUrls: ReadonlyArray<string>,
|
||||
public readonly isRecommended: boolean) {
|
||||
public readonly level?: RecommendationLevel) {
|
||||
super(name);
|
||||
validateCode(name, code);
|
||||
if (revertCode) {
|
||||
validateCode(name, revertCode);
|
||||
if (code === revertCode) {
|
||||
throw new Error(`${name}: Code itself and its reverting code cannot be the same`);
|
||||
}
|
||||
if (!code) {
|
||||
throw new Error(`undefined code (script: ${name})`);
|
||||
}
|
||||
validateLevel(level);
|
||||
}
|
||||
public canRevert(): boolean {
|
||||
return Boolean(this.revertCode);
|
||||
return Boolean(this.code.revert);
|
||||
}
|
||||
}
|
||||
|
||||
function validateCode(name: string, code: string): void {
|
||||
if (!code || code.length === 0) {
|
||||
throw new Error(`Code of ${name} is empty or null`);
|
||||
}
|
||||
ensureCodeHasUniqueLines(name, code);
|
||||
ensureNoEmptyLines(name, code);
|
||||
}
|
||||
|
||||
function ensureNoEmptyLines(name: string, code: string): void {
|
||||
if (code.split('\n').some((line) => line.trim().length === 0)) {
|
||||
throw Error(`Script has empty lines "${name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
function mayBeUniqueLine(codeLine: string): boolean {
|
||||
const trimmed = codeLine.trim();
|
||||
if (trimmed === ')' || trimmed === '(') { // "(" and ")" are used often in batch code
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function ensureCodeHasUniqueLines(name: string, code: string): void {
|
||||
const lines = code.split('\n')
|
||||
.filter((line) => mayBeUniqueLine(line));
|
||||
if (lines.length === 0) {
|
||||
return;
|
||||
}
|
||||
const duplicateLines = lines.filter((e, i, a) => a.indexOf(e) !== i);
|
||||
if (duplicateLines.length !== 0) {
|
||||
throw Error(`Duplicates detected in script "${name}":\n ${duplicateLines.join('\n')}`);
|
||||
function validateLevel(level?: RecommendationLevel) {
|
||||
if (level !== undefined && !(level in RecommendationLevel)) {
|
||||
throw new Error(`invalid level: ${level}`);
|
||||
}
|
||||
}
|
||||
|
||||
57
src/domain/ScriptCode.ts
Normal file
57
src/domain/ScriptCode.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { IScriptCode } from './IScriptCode';
|
||||
|
||||
export class ScriptCode implements IScriptCode {
|
||||
constructor(
|
||||
scriptName: string,
|
||||
public readonly execute: string,
|
||||
public readonly revert: string) {
|
||||
if (!scriptName) {
|
||||
throw new Error('script name is undefined');
|
||||
}
|
||||
validateCode(scriptName, execute);
|
||||
if (revert) {
|
||||
scriptName = `${scriptName} (revert)`;
|
||||
validateCode(scriptName, revert);
|
||||
if (execute === revert) {
|
||||
throw new Error(`${scriptName}: Code itself and its reverting code cannot be the same`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validateCode(name: string, code: string): void {
|
||||
if (!code || code.length === 0) {
|
||||
throw new Error(`code of ${name} is empty or undefined`);
|
||||
}
|
||||
ensureCodeHasUniqueLines(name, code);
|
||||
ensureNoEmptyLines(name, code);
|
||||
}
|
||||
|
||||
function ensureNoEmptyLines(name: string, code: string): void {
|
||||
if (code.split('\n').some((line) => line.trim().length === 0)) {
|
||||
throw Error(`Script has empty lines "${name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureCodeHasUniqueLines(name: string, code: string): void {
|
||||
const lines = code.split('\n')
|
||||
.filter((line) => mayBeUniqueLine(line));
|
||||
if (lines.length === 0) {
|
||||
return;
|
||||
}
|
||||
const duplicateLines = lines.filter((e, i, a) => a.indexOf(e) !== i);
|
||||
if (duplicateLines.length !== 0) {
|
||||
throw Error(`Duplicates detected in script "${name}":\n ${duplicateLines.join('\n')}`);
|
||||
}
|
||||
}
|
||||
|
||||
function mayBeUniqueLine(codeLine: string): boolean {
|
||||
const trimmed = codeLine.trim();
|
||||
if (trimmed === ')' || trimmed === '(') { // "(" and ")" are used often in batch code
|
||||
return false;
|
||||
}
|
||||
if (codeLine.startsWith(':: ') || codeLine.startsWith('REM ')) { // Is comment?
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import Vue from 'vue';
|
||||
import App from './App.vue';
|
||||
import { ApplicationBootstrapper } from './presentation/Bootstrapping/ApplicationBootstrapper';
|
||||
import 'core-js/fn/array/flat-map'; // Here until Vue 3 & CLI v4 https://github.com/vuejs/vue-cli/issues/3834
|
||||
|
||||
new ApplicationBootstrapper()
|
||||
.bootstrap(Vue);
|
||||
|
||||
@@ -6,7 +6,8 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
/** REGULAR ICONS (PREFIX: far) */
|
||||
import { faFolderOpen, faFolder, faSmile } from '@fortawesome/free-regular-svg-icons';
|
||||
/** SOLID ICONS (PREFIX: fas (default)) */
|
||||
import { faTimes, faFileDownload, faCopy, faSearch, faInfoCircle, faUserSecret, faDesktop, faTag, faGlobe } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faTimes, faFileDownload, faCopy, faSearch, faInfoCircle, faUserSecret, faDesktop,
|
||||
faTag, faGlobe, faSave, faBatteryFull, faBatteryHalf } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
|
||||
export class IconBootstrapper implements IVueBootstrapper {
|
||||
@@ -21,9 +22,10 @@ export class IconBootstrapper implements IVueBootstrapper {
|
||||
faFolderOpen,
|
||||
faFolder,
|
||||
faTimes,
|
||||
faFileDownload,
|
||||
faFileDownload, faSave,
|
||||
faCopy,
|
||||
faSearch,
|
||||
faBatteryFull, faBatteryHalf,
|
||||
faInfoCircle);
|
||||
vue.component('font-awesome-icon', FontAwesomeIcon);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,17 @@
|
||||
}"
|
||||
ref="cardElement">
|
||||
<div class="card__inner">
|
||||
<span v-if="cardTitle && cardTitle.length > 0">{{cardTitle}}</span>
|
||||
<span v-if="cardTitle && cardTitle.length > 0">
|
||||
<span>{{cardTitle}}</span>
|
||||
</span>
|
||||
<span v-else>Oh no 😢</span>
|
||||
<!-- Expand icon -->
|
||||
<font-awesome-icon :icon="['far', isExpanded ? 'folder-open' : 'folder']" class="card__inner__expand-icon" />
|
||||
<!-- Indeterminate and full states -->
|
||||
<div class="card__inner__state-icons">
|
||||
<font-awesome-icon v-if="isAnyChildSelected && !areAllChildrenSelected" :icon="['fa', 'battery-half']" />
|
||||
<font-awesome-icon v-if="areAllChildrenSelected" :icon="['fa', 'battery-full']" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card__expander" v-on:click.stop>
|
||||
<div class="card__expander__content">
|
||||
@@ -36,17 +44,21 @@ import { StatefulVue } from '@/presentation/StatefulVue';
|
||||
export default class CardListItem extends StatefulVue {
|
||||
@Prop() public categoryId!: number;
|
||||
@Prop() public activeCategoryId!: number;
|
||||
public cardTitle?: string = '';
|
||||
public isExpanded: boolean = false;
|
||||
public cardTitle = '';
|
||||
public isExpanded = false;
|
||||
public isAnyChildSelected = false;
|
||||
public areAllChildrenSelected = false;
|
||||
|
||||
@Emit('selected')
|
||||
@Emit('selected')
|
||||
public onSelected(isExpanded: boolean) {
|
||||
this.isExpanded = isExpanded;
|
||||
}
|
||||
|
||||
@Watch('activeCategoryId')
|
||||
public async onActiveCategoryChanged(value: |number) {
|
||||
this.isExpanded = value === this.categoryId;
|
||||
}
|
||||
|
||||
@Watch('isExpanded')
|
||||
public async onExpansionChangedAsync(newValue: number, oldValue: number) {
|
||||
if (!oldValue && newValue) {
|
||||
@@ -57,20 +69,23 @@ export default class CardListItem extends StatefulVue {
|
||||
}
|
||||
|
||||
public async mounted() {
|
||||
this.cardTitle = this.categoryId ? await this.getCardTitleAsync(this.categoryId) : undefined;
|
||||
const state = await this.getCurrentStateAsync();
|
||||
state.selection.changed.on(() => {
|
||||
this.updateStateAsync(this.categoryId);
|
||||
});
|
||||
this.updateStateAsync(this.categoryId);
|
||||
}
|
||||
|
||||
@Watch('categoryId')
|
||||
public async onCategoryIdChanged(value: |number) {
|
||||
this.cardTitle = value ? await this.getCardTitleAsync(value) : undefined;
|
||||
}
|
||||
|
||||
private async getCardTitleAsync(categoryId: number): Promise<string | undefined> {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
const category = state.app.findCategory(this.categoryId);
|
||||
return category ? category.name : undefined;
|
||||
public async updateStateAsync(value: |number) {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
const category = !value ? undefined : state.app.findCategory(this.categoryId);
|
||||
this.cardTitle = category ? category.name : undefined;
|
||||
this.isAnyChildSelected = category ? state.selection.isAnySelected(category) : false;
|
||||
this.areAllChildrenSelected = category ? state.selection.areAllSelected(category) : false;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -93,7 +108,7 @@ $expanded-margin-top: 30px;
|
||||
@media screen and (max-width: $small-screen-width) { width: 90%; }
|
||||
|
||||
&__inner {
|
||||
padding: $card-padding;
|
||||
padding: $card-padding $card-padding 0 $card-padding;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
background-color: $gray;
|
||||
@@ -115,13 +130,21 @@ $expanded-margin-top: 30px;
|
||||
&:after {
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
&__state-icons {
|
||||
height: $card-padding;
|
||||
margin-right: -$card-padding;
|
||||
padding-right: 10px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
&__expand-icon {
|
||||
width: 100%;
|
||||
margin-top: .25em;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
|
||||
&__expander {
|
||||
transition: all 0.2s ease-in-out;
|
||||
position: relative;
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
state.filter.filtered.on(this.handleFiltered);
|
||||
// Update initial state
|
||||
await this.initializeNodesAsync(this.categoryId);
|
||||
await this.initializeFilter(state.filter.currentFilter);
|
||||
}
|
||||
|
||||
public async toggleNodeSelectionAsync(event: INodeSelectedEvent) {
|
||||
@@ -84,6 +85,14 @@
|
||||
(category: ICategory) => node.id === getCategoryNodeId(category));
|
||||
}
|
||||
|
||||
private initializeFilter(currentFilter: IFilterResult | undefined) {
|
||||
if (!currentFilter) {
|
||||
this.handleFilterRemoved();
|
||||
} else {
|
||||
this.handleFiltered(currentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private handleSelectionChanged(selectedScripts: ReadonlyArray<SelectedScript>): void {
|
||||
this.selectedNodeIds = selectedScripts
|
||||
.map((node) => node.id);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
Node,
|
||||
},
|
||||
})
|
||||
export default class SelectableTree extends Vue {
|
||||
export default class SelectableTree extends Vue { // Keep it stateless to make it easier to switch out
|
||||
@Prop() public filterPredicate?: FilterPredicate;
|
||||
@Prop() public filterText?: string;
|
||||
@Prop() public selectedNodeIds?: ReadonlyArray<string>;
|
||||
|
||||
@@ -5,23 +5,37 @@
|
||||
<div class="part">
|
||||
<SelectableOption
|
||||
label="None"
|
||||
:enabled="isNoneSelected"
|
||||
@click="selectNoneAsync()">
|
||||
</SelectableOption>
|
||||
:enabled="this.currentSelection == SelectionState.None"
|
||||
@click="selectAsync(SelectionState.None)"
|
||||
v-tooltip="'Deselect all selected scripts. Good start to dive deeper into tweaks and select only what you want.'"
|
||||
/>
|
||||
</div>
|
||||
<div class="part"> | </div>
|
||||
<div class="part">
|
||||
<SelectableOption
|
||||
label="Recommended"
|
||||
:enabled="isRecommendedSelected"
|
||||
@click="selectRecommendedAsync()" />
|
||||
label="Standard"
|
||||
:enabled="this.currentSelection == SelectionState.Standard"
|
||||
@click="selectAsync(SelectionState.Standard)"
|
||||
v-tooltip="'🛡️ Balanced for privacy and functionality. OS and applications will function normally.'"
|
||||
/>
|
||||
</div>
|
||||
<div class="part"> | </div>
|
||||
<div class="part">
|
||||
<SelectableOption
|
||||
label="Strict"
|
||||
:enabled="this.currentSelection == SelectionState.Strict"
|
||||
@click="selectAsync(SelectionState.Strict)"
|
||||
v-tooltip="'🚫 Stronger privacy, disables risky functions that may leak your data. Double check selected tweaks!'"
|
||||
/>
|
||||
</div>
|
||||
<div class="part"> | </div>
|
||||
<div class="part">
|
||||
<SelectableOption
|
||||
label="All"
|
||||
:enabled="isAllSelected"
|
||||
@click="selectAllAsync()" />
|
||||
label="All"
|
||||
:enabled="this.currentSelection == SelectionState.All"
|
||||
@click="selectAsync(SelectionState.All)"
|
||||
v-tooltip="'🔒 Strongest privacy. Disables any functionality that may leak your data. ⚠️ Not recommended for inexperienced users'"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,17 +47,24 @@ import { StatefulVue } from '@/presentation/StatefulVue';
|
||||
import SelectableOption from './SelectableOption.vue';
|
||||
import { IApplicationState } from '@/application/State/IApplicationState';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { SelectedScript } from '../../../application/State/Selection/SelectedScript';
|
||||
import { SelectedScript } from '@/application/State/Selection/SelectedScript';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
|
||||
enum SelectionState {
|
||||
Standard,
|
||||
Strict,
|
||||
All,
|
||||
None,
|
||||
Custom,
|
||||
}
|
||||
@Component({
|
||||
components: {
|
||||
SelectableOption,
|
||||
},
|
||||
})
|
||||
export default class TheSelector extends StatefulVue {
|
||||
public isAllSelected = false;
|
||||
public isNoneSelected = false;
|
||||
public isRecommendedSelected = false;
|
||||
public SelectionState = SelectionState;
|
||||
public currentSelection = SelectionState.None;
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
@@ -52,43 +73,73 @@ export default class TheSelector extends StatefulVue {
|
||||
this.updateSelections(state);
|
||||
});
|
||||
}
|
||||
|
||||
public async selectAllAsync(): Promise<void> {
|
||||
if (this.isAllSelected) {
|
||||
public async selectAsync(type: SelectionState): Promise<void> {
|
||||
if (this.currentSelection === type) {
|
||||
return;
|
||||
}
|
||||
const state = await this.getCurrentStateAsync();
|
||||
state.selection.selectAll();
|
||||
}
|
||||
|
||||
public async selectRecommendedAsync(): Promise<void> {
|
||||
if (this.isRecommendedSelected) {
|
||||
return;
|
||||
}
|
||||
const state = await this.getCurrentStateAsync();
|
||||
state.selection.selectOnly(state.app.getRecommendedScripts());
|
||||
}
|
||||
|
||||
public async selectNoneAsync(): Promise<void> {
|
||||
if (this.isNoneSelected) {
|
||||
return;
|
||||
}
|
||||
const state = await this.getCurrentStateAsync();
|
||||
state.selection.deselectAll();
|
||||
selectType(state, type);
|
||||
}
|
||||
|
||||
private updateSelections(state: IApplicationState) {
|
||||
this.isNoneSelected = state.selection.totalSelected === 0;
|
||||
this.isAllSelected = state.selection.totalSelected === state.app.totalScripts;
|
||||
this.isRecommendedSelected = this.areAllRecommended(state.app.getRecommendedScripts(),
|
||||
state.selection.selectedScripts);
|
||||
this.currentSelection = getCurrentSelectionState(state);
|
||||
}
|
||||
}
|
||||
|
||||
private areAllRecommended(scripts: ReadonlyArray<IScript>, other: ReadonlyArray<SelectedScript>): boolean {
|
||||
other = other.filter((selected) => !(selected).revert);
|
||||
return (scripts.length === other.length) &&
|
||||
scripts.every((script) => other.some((selected) => selected.id === script.id));
|
||||
interface ITypeSelector {
|
||||
isSelected: (state: IApplicationState) => boolean;
|
||||
select: (state: IApplicationState) => void;
|
||||
}
|
||||
|
||||
const selectors = new Map<SelectionState, ITypeSelector>([
|
||||
[SelectionState.None, {
|
||||
select: (state) => state.selection.deselectAll(),
|
||||
isSelected: (state) => state.selection.totalSelected === 0,
|
||||
}],
|
||||
[SelectionState.Standard, {
|
||||
select: (state) => state.selection.selectOnly(state.app.getScriptsByLevel(RecommendationLevel.Standard)),
|
||||
isSelected: (state) => hasAllSelectedLevelOf(RecommendationLevel.Standard, state),
|
||||
}],
|
||||
[SelectionState.Strict, {
|
||||
select: (state) => state.selection.selectOnly(state.app.getScriptsByLevel(RecommendationLevel.Strict)),
|
||||
isSelected: (state) => hasAllSelectedLevelOf(RecommendationLevel.Strict, state),
|
||||
}],
|
||||
[SelectionState.All, {
|
||||
select: (state) => state.selection.selectAll(),
|
||||
isSelected: (state) => state.selection.totalSelected === state.app.totalScripts,
|
||||
}],
|
||||
]);
|
||||
|
||||
function selectType(state: IApplicationState, type: SelectionState) {
|
||||
const selector = selectors.get(type);
|
||||
selector.select(state);
|
||||
}
|
||||
|
||||
function getCurrentSelectionState(state: IApplicationState): SelectionState {
|
||||
for (const [type, selector] of Array.from(selectors.entries())) {
|
||||
if (selector.isSelected(state)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return SelectionState.Custom;
|
||||
}
|
||||
|
||||
function hasAllSelectedLevelOf(level: RecommendationLevel, state: IApplicationState) {
|
||||
const scripts = state.app.getScriptsByLevel(level);
|
||||
const selectedScripts = state.selection.selectedScripts;
|
||||
return areAllSelected(scripts, selectedScripts);
|
||||
}
|
||||
|
||||
function areAllSelected(
|
||||
expectedScripts: ReadonlyArray<IScript>,
|
||||
selection: ReadonlyArray<SelectedScript>): boolean {
|
||||
selection = selection.filter((selected) => !selected.revert);
|
||||
if (expectedScripts.length < selection.length) {
|
||||
return false;
|
||||
}
|
||||
const selectedScriptIds = selection.map((script) => script.id).sort();
|
||||
const expectedScriptIds = expectedScripts.map((script) => script.id).sort();
|
||||
return selectedScriptIds.every((id, index) => id === expectedScriptIds[index]);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -72,10 +72,9 @@
|
||||
public isSearching = false;
|
||||
public searchHasMatches = false;
|
||||
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
this.repositoryUrl = state.app.repositoryUrl;
|
||||
this.repositoryUrl = state.app.info.repositoryWebUrl;
|
||||
state.filter.filterRemoved.on(() => {
|
||||
this.isSearching = false;
|
||||
});
|
||||
|
||||
@@ -17,15 +17,15 @@ const NothingChosenCode =
|
||||
.appendLine()
|
||||
.appendCommentLine('-- 🤔 How to use')
|
||||
.appendCommentLine(' 📙 Start by exploring different categories and choosing different tweaks.')
|
||||
.appendCommentLine(' 📙 You can select "Recommended" on the top to select "safer" tweaks. Always double check!')
|
||||
.appendCommentLine(' 📙 On top left, you can apply predefined selections for privacy level you\'d like.')
|
||||
.appendCommentLine(' 📙 After you choose any tweak, you can download or copy to execute your script.')
|
||||
.appendCommentLine(' 📙 Come back regularly to apply latest version for stronger privacy and security.')
|
||||
.appendLine()
|
||||
.appendCommentLine('-- 🧐 Why privacy.sexy')
|
||||
.appendCommentLine(' ✔️ Rich tweak pool to harden security & privacy of the OS and other softwares on it.')
|
||||
.appendCommentLine(' ✔️ You don\'t need to run any compiled software on your system, just run the generated scripts.')
|
||||
.appendCommentLine(' ✔️ Rich tweak pool to harden security & privacy of the OS and other software on it.')
|
||||
.appendCommentLine(' ✔️ No need to run any compiled software on your system, just run the generated scripts.')
|
||||
.appendCommentLine(' ✔️ Have full visibility into what the tweaks do as you enable them.')
|
||||
.appendCommentLine(' ✔️ Free software, 100% transparency: both application & infrastructure code are open-sourced.')
|
||||
.appendCommentLine(' ✔️ Open-source and free (both free as in beer and free as in speech).')
|
||||
.toString();
|
||||
|
||||
@Component
|
||||
@@ -113,6 +113,7 @@ function initializeEditor(theme: string, editorId: string): ace.Ace.Editor {
|
||||
width: 100%;
|
||||
max-height: 1000px;
|
||||
min-height: 200px;
|
||||
overflow: auto;
|
||||
&__highlight {
|
||||
background-color:$accent;
|
||||
opacity: 0.2; // having procent fails in production (minified) build
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
<template>
|
||||
<div class="container" v-if="hasCode">
|
||||
</IconButton>
|
||||
<IconButton
|
||||
:text="this.isDesktop ? 'Save' : 'Download'"
|
||||
v-on:click="saveCodeAsync"
|
||||
icon-prefix="fas"
|
||||
:icon-name="this.isDesktop ? 'save' : 'file-download'">
|
||||
</IconButton>
|
||||
<IconButton
|
||||
text="Copy"
|
||||
v-on:click="copyCodeAsync"
|
||||
icon-prefix="fas" icon-name="copy">
|
||||
</IconButton>
|
||||
<IconButton
|
||||
text="Download"
|
||||
v-on:click="saveCodeAsync"
|
||||
icon-prefix="fas" icon-name="file-download">
|
||||
</IconButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component } from 'vue-property-decorator';
|
||||
import { StatefulVue } from './StatefulVue';
|
||||
import { SaveFileDialog, FileType } from './../infrastructure/SaveFileDialog';
|
||||
import { Clipboard } from './../infrastructure/Clipboard';
|
||||
import { SaveFileDialog, FileType } from '@/infrastructure/SaveFileDialog';
|
||||
import { Clipboard } from '@/infrastructure/Clipboard';
|
||||
import IconButton from './IconButton.vue';
|
||||
import { Environment } from '@/application/Environment/Environment';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -27,9 +30,11 @@ import IconButton from './IconButton.vue';
|
||||
})
|
||||
export default class TheCodeButtons extends StatefulVue {
|
||||
public hasCode = false;
|
||||
public isDesktop = false;
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
this.isDesktop = Environment.CurrentEnvironment.isDesktop;
|
||||
this.hasCode = state.code.current && state.code.current.length > 0;
|
||||
state.code.changed.on((code) => {
|
||||
this.hasCode = code && code.code.length > 0;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import { Environment } from '@/application/Environment/Environment';
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import DownloadUrlListItem from './DownloadUrlListItem.vue';
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { Component, Prop, Watch } from 'vue-property-decorator';
|
||||
import { StatefulVue } from '@/presentation/StatefulVue';
|
||||
import { Environment } from '@/application/Environment/Environment';
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
@Component
|
||||
export default class DownloadUrlListItem extends StatefulVue {
|
||||
@@ -39,7 +39,7 @@ export default class DownloadUrlListItem extends StatefulVue {
|
||||
|
||||
private async getDownloadUrlAsync(os: OperatingSystem): Promise<string> {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
return `${state.app.repositoryUrl}/releases/download/${state.app.version}/${getFileName(os, state.app.version)}`;
|
||||
return state.app.info.getDownloadUrl(os);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,18 +62,6 @@ function getOperatingSystemName(os: OperatingSystem): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getFileName(os: OperatingSystem, version: string): string {
|
||||
switch (os) {
|
||||
case OperatingSystem.Linux:
|
||||
return `privacy.sexy-${version}.AppImage`;
|
||||
case OperatingSystem.macOS:
|
||||
return `privacy.sexy-${version}.dmg`;
|
||||
case OperatingSystem.Windows:
|
||||
return `privacy.sexy-Setup-${version}.exe`;
|
||||
default:
|
||||
throw new Error(`Unsupported os: ${OperatingSystem[os]}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -48,8 +48,8 @@ export default class TheFooter extends StatefulVue {
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
this.repositoryUrl = state.app.repositoryUrl;
|
||||
this.feedbackUrl = `${state.app.repositoryUrl}/issues`;
|
||||
this.repositoryUrl = state.app.info.repositoryWebUrl;
|
||||
this.feedbackUrl = state.app.info.feedbackUrl;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="footer__section">
|
||||
<span v-if="isDesktop" class="footer__section__item">
|
||||
<font-awesome-icon class="icon" :icon="['fas', 'globe']" />
|
||||
<span>Online version at <a href="https://privacy.sexy" target="_blank">https://privacy.sexy</a></span>
|
||||
<span>Online version at <a :href="homepageUrl" target="_blank">{{ homepageUrl }}</a></span>
|
||||
</span>
|
||||
<span v-else class="footer__section__item">
|
||||
<DownloadUrlList />
|
||||
@@ -66,6 +66,7 @@ export default class TheFooter extends StatefulVue {
|
||||
public repositoryUrl: string = '';
|
||||
public releaseUrl: string = '';
|
||||
public feedbackUrl: string = '';
|
||||
public homepageUrl: string = '';
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -74,12 +75,15 @@ export default class TheFooter extends StatefulVue {
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
this.version = state.app.version;
|
||||
this.repositoryUrl = state.app.repositoryUrl;
|
||||
this.releaseUrl = `${state.app.repositoryUrl}/releases/tag/${state.app.version}`;
|
||||
this.feedbackUrl = `${state.app.repositoryUrl}/issues`;
|
||||
const info = state.app.info;
|
||||
this.version = info.version;
|
||||
this.homepageUrl = info.homepage;
|
||||
this.repositoryUrl = info.repositoryWebUrl;
|
||||
this.releaseUrl = info.releaseUrl;
|
||||
this.feedbackUrl = info.feedbackUrl;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class TheHeader extends StatefulVue {
|
||||
|
||||
public async mounted() {
|
||||
const state = await this.getCurrentStateAsync();
|
||||
this.title = state.app.name;
|
||||
this.title = state.app.info.name;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
&-checkbox {
|
||||
&.checked {
|
||||
background: $accent !important;
|
||||
border-color: $accent !important;
|
||||
}
|
||||
&.indeterminate {
|
||||
border-color: $gray !important;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { BrowserOsDetector } from '@/application/Environment/BrowserOs/BrowserOsDetector';
|
||||
import { BrowserOsTestCases } from './BrowserOsTestCases';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
interface IBrowserOsTestCase {
|
||||
userAgent: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
interface IDesktopTestCase {
|
||||
processPlatform: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IBrowserOsDetector } from '@/application/Environment/BrowserOs/IBrowserOsDetector';
|
||||
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { DesktopOsTestCases } from './DesktopOsTestCases';
|
||||
import { Environment } from '@/application/Environment/Environment';
|
||||
import { expect } from 'chai';
|
||||
|
||||
@@ -4,86 +4,95 @@ import { parseApplication } from '@/application/Parser/ApplicationParser';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
|
||||
declare var process;
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
|
||||
describe('ApplicationParser', () => {
|
||||
describe('parseApplication', () => {
|
||||
it('can parse current application file', () => {
|
||||
expect(() => parseApplication(applicationFile)).to.not.throw();
|
||||
// act
|
||||
const act = () => parseApplication(applicationFile);
|
||||
// assert
|
||||
expect(act).to.not.throw();
|
||||
});
|
||||
it('throws when undefined', () => {
|
||||
expect(() => parseApplication(undefined)).to.throw('application is null or undefined');
|
||||
// arrange
|
||||
const expectedError = 'application is null or undefined';
|
||||
// act
|
||||
const act = () => parseApplication(undefined);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when undefined actions', () => {
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'test',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: undefined,
|
||||
};
|
||||
expect(() => parseApplication(sut)).to.throw('application does not define any action');
|
||||
// arrange
|
||||
const sut: ApplicationYaml = { actions: undefined, functions: undefined };
|
||||
const expectedError = 'application does not define any action';
|
||||
// act
|
||||
const act = () => parseApplication(sut);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when has no actions', () => {
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'test',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [],
|
||||
};
|
||||
expect(() => parseApplication(sut)).to.throw('application does not define any action');
|
||||
});
|
||||
it('returns expected name', () => {
|
||||
// arrange
|
||||
const expected = 'test-app-name';
|
||||
const sut: ApplicationYaml = {
|
||||
name: expected,
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
const sut: ApplicationYaml = { actions: [], functions: undefined };
|
||||
const expectedError = 'application does not define any action';
|
||||
// act
|
||||
const actual = parseApplication(sut).name;
|
||||
const act = () => parseApplication(sut);
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('returns expected repository url', () => {
|
||||
// arrange
|
||||
const expected = 'https://privacy.sexy';
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: expected,
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
});
|
||||
it('returns expected repository version', () => {
|
||||
// arrange
|
||||
const expected = '1.0.0';
|
||||
process = {
|
||||
env: {
|
||||
VUE_APP_VERSION: expected,
|
||||
},
|
||||
};
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).version;
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
describe('information', () => {
|
||||
it('returns expected repository version', () => {
|
||||
// arrange
|
||||
const expected = 'expected-version';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_VERSION = expected;
|
||||
const sut: ApplicationYaml = { actions: [ getTestCategory() ], functions: undefined };
|
||||
// act
|
||||
const actual = parseApplication(sut, env).info.version;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
it('returns expected repository url', () => {
|
||||
// arrange
|
||||
const expected = 'https://expected-repository.url';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_REPOSITORY_URL = expected;
|
||||
const sut: ApplicationYaml = { actions: [ getTestCategory() ], functions: undefined };
|
||||
// act
|
||||
const actual = parseApplication(sut, env).info.repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
it('returns expected name', () => {
|
||||
// arrange
|
||||
const expected = 'expected-app-name';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_NAME = expected;
|
||||
const sut: ApplicationYaml = { actions: [ getTestCategory() ], functions: undefined };
|
||||
// act
|
||||
const actual = parseApplication(sut, env).info.name;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
it('returns expected homepage url', () => {
|
||||
// arrange
|
||||
const expected = 'https://expected.sexy';
|
||||
const env = getProcessEnvironmentStub();
|
||||
env.VUE_APP_HOMEPAGE_URL = expected;
|
||||
const sut: ApplicationYaml = { actions: [ getTestCategory() ], functions: undefined };
|
||||
// act
|
||||
const actual = parseApplication(sut, env).info.homepage;
|
||||
// assert
|
||||
expect(actual).to.be.equal(expected);
|
||||
});
|
||||
});
|
||||
it('parses actions', () => {
|
||||
// arrange
|
||||
const actions = [ getTestCategory('test1'), getTestCategory('test2') ];
|
||||
const expected = [ parseCategory(actions[0]), parseCategory(actions[1]) ];
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions,
|
||||
};
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
|
||||
const sut: ApplicationYaml = { actions, functions: undefined };
|
||||
// act
|
||||
const actual = parseApplication(sut).actions;
|
||||
// assert
|
||||
@@ -98,18 +107,31 @@ describe('ApplicationParser', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function getTestCategory(scriptName = 'testScript'): YamlCategory {
|
||||
function getTestCategory(scriptPrefix = 'testScript'): YamlCategory {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [ getTestScript(scriptName) ],
|
||||
children: [
|
||||
getTestScript(`${scriptPrefix}-standard`, RecommendationLevel.Standard),
|
||||
getTestScript(`${scriptPrefix}-strict`, RecommendationLevel.Strict),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function getTestScript(scriptName: string): YamlScript {
|
||||
function getTestScript(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): YamlScript {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: true,
|
||||
recommend: RecommendationLevel[level].toLowerCase(),
|
||||
call: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function getProcessEnvironmentStub(): NodeJS.ProcessEnv {
|
||||
return {
|
||||
VUE_APP_VERSION: 'stub-version',
|
||||
VUE_APP_NAME: 'stub-name',
|
||||
VUE_APP_REPOSITORY_URL: 'stub-repository-url',
|
||||
VUE_APP_HOMEPAGE_URL: 'stub-homepage-url',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,87 +4,150 @@ import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
import { YamlCategory, CategoryOrScript, YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
||||
|
||||
describe('CategoryParser', () => {
|
||||
describe('parseCategory', () => {
|
||||
|
||||
it('throws when undefined', () => {
|
||||
expect(() => parseCategory(undefined)).to.throw('category is null or undefined');
|
||||
describe('invalid category', () => {
|
||||
it('throws when undefined', () => {
|
||||
// arrange
|
||||
const expectedMessage = 'category is null or undefined';
|
||||
const category = undefined;
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const act = () => parseCategory(category, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedMessage);
|
||||
});
|
||||
it('throws when children are empty', () => {
|
||||
// arrange
|
||||
const expectedMessage = 'category has no children';
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: [],
|
||||
};
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const act = () => parseCategory(category, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedMessage);
|
||||
});
|
||||
it('throws when children are undefined', () => {
|
||||
// arrange
|
||||
const expectedMessage = 'category has no children';
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: undefined,
|
||||
};
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const act = () => parseCategory(category, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedMessage);
|
||||
});
|
||||
it('throws when name is empty or undefined', () => {
|
||||
// arrange
|
||||
const expectedMessage = 'category has no name';
|
||||
const invalidNames = ['', undefined];
|
||||
invalidNames.forEach((invalidName) => {
|
||||
const category: YamlCategory = {
|
||||
category: invalidName,
|
||||
children: getTestChildren(),
|
||||
};
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const act = () => parseCategory(category, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when children is empty', () => {
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: [],
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no children');
|
||||
it('throws when compiler is undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined compiler';
|
||||
const compiler = undefined;
|
||||
const category = getValidCategory();
|
||||
// act
|
||||
const act = () => parseCategory(category, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
|
||||
it('throws when children is undefined', () => {
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: undefined,
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no children');
|
||||
});
|
||||
|
||||
it('throws when name is empty', () => {
|
||||
const category: YamlCategory = {
|
||||
category: '',
|
||||
children: getTestChildren(),
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no name');
|
||||
});
|
||||
|
||||
it('throws when name is undefined', () => {
|
||||
const category: YamlCategory = {
|
||||
category: undefined,
|
||||
children: getTestChildren(),
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no name');
|
||||
});
|
||||
|
||||
it('returns expected docs', () => {
|
||||
// arrange
|
||||
const url = 'https://privacy.sexy';
|
||||
const expected = parseDocUrls({ docs: url });
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: getTestChildren(),
|
||||
docs: url,
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category).documentationUrls;
|
||||
const actual = parseCategory(category, compiler).documentationUrls;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it('returns expected scripts', () => {
|
||||
// arrange
|
||||
const script = getTestScript();
|
||||
const expected = [ parseScript(script) ];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category).scripts;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
describe('parses expected subscript', () => {
|
||||
it('single script with code', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = [ parseScript(script, compiler) ];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category, compiler).scripts;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('single script with function call', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(script);
|
||||
const expected = [ parseScript(script, compiler) ];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category, compiler).scripts;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('multiple scripts with function call and code', () => {
|
||||
// arrange
|
||||
const callableScript = YamlScriptStub.createWithCall();
|
||||
const scripts = [ callableScript, YamlScriptStub.createWithCode() ];
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(callableScript);
|
||||
const expected = scripts.map((script) => parseScript(script, compiler));
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: scripts,
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category, compiler).scripts;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns expected subcategories', () => {
|
||||
// arrange
|
||||
const expected: YamlCategory[] = [ {
|
||||
category: 'test category',
|
||||
children: [ getTestScript() ],
|
||||
children: [ YamlScriptStub.createWithCode() ],
|
||||
}];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: expected,
|
||||
};
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const actual = parseCategory(category).subCategories;
|
||||
const actual = parseCategory(category, compiler).subCategories;
|
||||
// assert
|
||||
expect(actual).to.have.lengthOf(1);
|
||||
expect(actual[0].name).to.equal(expected[0].category);
|
||||
@@ -93,17 +156,16 @@ describe('CategoryParser', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
|
||||
return [
|
||||
getTestScript(),
|
||||
];
|
||||
}
|
||||
|
||||
function getTestScript(): YamlScript {
|
||||
function getValidCategory(): YamlCategory {
|
||||
return {
|
||||
name: 'script name',
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: true,
|
||||
category: 'category name',
|
||||
children: getTestChildren(),
|
||||
docs: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
|
||||
return [
|
||||
YamlScriptStub.createWithCode(),
|
||||
];
|
||||
}
|
||||
|
||||
363
tests/unit/application/Parser/Compiler/ScriptCompiler.spec.ts
Normal file
363
tests/unit/application/Parser/Compiler/ScriptCompiler.spec.ts
Normal file
@@ -0,0 +1,363 @@
|
||||
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 { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||
|
||||
describe('ScriptCompiler', () => {
|
||||
describe('ctor', () => {
|
||||
it('throws when functions have same names', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate function name: "same-func-name"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
name: 'same-func-name',
|
||||
code: 'non-empty-code',
|
||||
}, {
|
||||
name: 'same-func-name',
|
||||
code: 'non-empty-code-2',
|
||||
}];
|
||||
// act
|
||||
const act = () => new ScriptCompiler(functions);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when function parameters have same names', () => {
|
||||
// arrange
|
||||
const func: YamlFunction = {
|
||||
name: 'function-name',
|
||||
code: 'non-empty-code',
|
||||
parameters: [ 'duplicate', 'duplicate' ],
|
||||
};
|
||||
const expectedError = `"${func.name}": duplicate parameter name: "duplicate"`;
|
||||
// act
|
||||
const act = () => new ScriptCompiler([func]);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
describe('throws when when function have duplicate code', () => {
|
||||
it('code', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate "code" in functions: "duplicate-code"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
name: 'func-1',
|
||||
code: 'duplicate-code',
|
||||
}, {
|
||||
name: 'func-2',
|
||||
code: 'duplicate-code',
|
||||
}];
|
||||
// act
|
||||
const act = () => new ScriptCompiler(functions);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('revertCode', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate "revertCode" in functions: "duplicate-revert-code"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
name: 'func-1',
|
||||
code: 'code-1',
|
||||
revertCode: 'duplicate-revert-code',
|
||||
}, {
|
||||
name: 'func-2',
|
||||
code: 'code-2',
|
||||
revertCode: 'duplicate-revert-code',
|
||||
}];
|
||||
// act
|
||||
const act = () => new ScriptCompiler(functions);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('canCompile', () => {
|
||||
it('returns true if "call" is defined', () => {
|
||||
// arrange
|
||||
const sut = new ScriptCompiler([]);
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
// act
|
||||
const actual = sut.canCompile(script);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
it('returns false if "call" is undefined', () => {
|
||||
// arrange
|
||||
const sut = new ScriptCompiler([]);
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
// act
|
||||
const actual = sut.canCompile(script);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
});
|
||||
describe('compile', () => {
|
||||
describe('invalid state', () => {
|
||||
it('throws if functions are empty', () => {
|
||||
// arrange
|
||||
const expectedError = 'cannot compile without shared functions';
|
||||
const functions = [];
|
||||
const sut = new ScriptCompiler(functions);
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws if call is not an object', () => {
|
||||
// arrange
|
||||
const expectedError = 'called function(s) must be an object';
|
||||
const invalidValues = [undefined, 'string', 33];
|
||||
const sut = new ScriptCompiler(createFunctions());
|
||||
invalidValues.forEach((invalidValue) => {
|
||||
const script = YamlScriptStub.createWithoutCallOrCodes() // because call ctor overwrites "undefined"
|
||||
.withCall(invalidValue as any);
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('invalid function reference', () => {
|
||||
it('throws if function does not exist', () => {
|
||||
// arrange
|
||||
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);
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws if function is undefined', () => {
|
||||
// arrange
|
||||
const existingFunctionName = 'existing-func';
|
||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||
const call: ScriptFunctionCall = [
|
||||
{ function: existingFunctionName },
|
||||
undefined,
|
||||
];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const expectedError = `undefined function call in script "${script.name}"`;
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws if function name is not given', () => {
|
||||
// arrange
|
||||
const existingFunctionName = 'existing-func';
|
||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||
const call: FunctionCall[] = [
|
||||
{ function: existingFunctionName },
|
||||
{ function: undefined }];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const expectedError = `empty function name called in script "${script.name}"`;
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('builds code as expected', () => {
|
||||
it('builds single call as expected', () => {
|
||||
// arrange
|
||||
const functionName = 'testSharedFunction';
|
||||
const expected: IScriptCode = {
|
||||
execute: 'expected-code',
|
||||
revert: 'expected-revert-code',
|
||||
};
|
||||
const func: YamlFunction = {
|
||||
name: functionName,
|
||||
parameters: [],
|
||||
code: expected.execute,
|
||||
revertCode: expected.revert,
|
||||
};
|
||||
const sut = new ScriptCompiler([func]);
|
||||
const call: FunctionCall = { function: functionName };
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
// act
|
||||
const actual = sut.compile(script);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('builds call sequence as expected', () => {
|
||||
// arrange
|
||||
const firstFunction: YamlFunction = {
|
||||
name: 'first-function-name',
|
||||
parameters: [],
|
||||
code: 'first-function-code',
|
||||
revertCode: 'first-function-revert-code',
|
||||
};
|
||||
const secondFunction: YamlFunction = {
|
||||
name: 'second-function-name',
|
||||
parameters: [],
|
||||
code: 'second-function-code',
|
||||
revertCode: 'second-function-revert-code',
|
||||
};
|
||||
const expected: IScriptCode = {
|
||||
execute: 'first-function-code\nsecond-function-code',
|
||||
revert: 'first-function-revert-code\nsecond-function-revert-code',
|
||||
};
|
||||
const sut = new ScriptCompiler([firstFunction, secondFunction]);
|
||||
const call: FunctionCall[] = [
|
||||
{ function: firstFunction.name },
|
||||
{ function: secondFunction.name },
|
||||
];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
// act
|
||||
const actual = sut.compile(script);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
describe('parameter substitution', () => {
|
||||
describe('substitutes by ignoring whitespaces inside mustaches', () => {
|
||||
// arrange
|
||||
const mustacheVariations = [
|
||||
'Hello {{ $test }}!',
|
||||
'Hello {{$test }}!',
|
||||
'Hello {{ $test}}!',
|
||||
'Hello {{$test}}!'];
|
||||
mustacheVariations.forEach((variation) => {
|
||||
it(variation, () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: variation,
|
||||
parameters: {
|
||||
test: 'world',
|
||||
},
|
||||
});
|
||||
const expected = env.expect('Hello world!');
|
||||
// act
|
||||
const actual = env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('substitutes as expected', () => {
|
||||
it('with different parameters', () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: 'He{{ $firstParameter }} {{ $secondParameter }}!',
|
||||
parameters: {
|
||||
firstParameter: 'llo',
|
||||
secondParameter: 'world',
|
||||
},
|
||||
});
|
||||
const expected = env.expect('Hello world!');
|
||||
// act
|
||||
const actual = env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('with same parameter repeated', () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: '{{ $parameter }} {{ $parameter }}!',
|
||||
parameters: {
|
||||
parameter: 'Hodor',
|
||||
},
|
||||
});
|
||||
const expected = env.expect('Hodor Hodor!');
|
||||
// act
|
||||
const actual = env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
it('throws when parameters is undefined', () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: '{{ $parameter }} {{ $parameter }}!',
|
||||
});
|
||||
const expectedError = 'no parameters defined, expected: "parameter"';
|
||||
// act
|
||||
const act = () => env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when parameter value is not provided', () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: '{{ $parameter }} {{ $parameter }}!',
|
||||
parameters: {
|
||||
parameter: undefined,
|
||||
},
|
||||
});
|
||||
const expectedError = 'parameter value is not provided for "parameter" in function call';
|
||||
// act
|
||||
const act = () => env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws on unknown expressions', () => {
|
||||
// arrange
|
||||
const env = new TestEnvironment({
|
||||
code: '{{ each }}',
|
||||
parameters: {
|
||||
parameter: undefined,
|
||||
},
|
||||
});
|
||||
const expectedError = 'unknown expression: "each"';
|
||||
// act
|
||||
const act = () => env.sut.compile(env.script);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
interface ITestCase {
|
||||
code: string;
|
||||
parameters?: FunctionCallParameters;
|
||||
}
|
||||
|
||||
class TestEnvironment {
|
||||
public readonly sut: IScriptCompiler;
|
||||
public readonly script: YamlScript;
|
||||
constructor(testCase: ITestCase) {
|
||||
const functionName = 'testFunction';
|
||||
const func: YamlFunction = {
|
||||
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 = {
|
||||
function: functionName,
|
||||
parameters: testCase.parameters,
|
||||
};
|
||||
this.script = YamlScriptStub.createWithCall(call);
|
||||
}
|
||||
public expect(code: string): IScriptCode {
|
||||
return {
|
||||
execute: this.getCode(code, 'execute'),
|
||||
revert: this.getCode(code, 'revert'),
|
||||
};
|
||||
}
|
||||
private getCode(text: string, type: 'execute' | 'revert'): string {
|
||||
return `${text} (${type})`;
|
||||
}
|
||||
}
|
||||
|
||||
function createFunctions(...names: string[]): YamlFunction[] {
|
||||
if (!names || names.length === 0) {
|
||||
names = ['test-function'];
|
||||
}
|
||||
return names.map((functionName) => {
|
||||
const func: YamlFunction = {
|
||||
name: functionName,
|
||||
parameters: [],
|
||||
code: `REM test-code (${functionName})`,
|
||||
revertCode: `REM test-revert-code (${functionName})`,
|
||||
};
|
||||
return func;
|
||||
});
|
||||
}
|
||||
@@ -1,28 +1,198 @@
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
import { RecommendationLevelNames, RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
||||
|
||||
describe('ScriptParser', () => {
|
||||
describe('parseScript', () => {
|
||||
it('parseScript parses as expected', () => {
|
||||
it('parses name as expected', () => {
|
||||
// arrange
|
||||
const expected: YamlScript = {
|
||||
name: 'expected name',
|
||||
code: 'expected code',
|
||||
revertCode: 'expected revert code',
|
||||
docs: ['hello.com'],
|
||||
recommend: true,
|
||||
};
|
||||
const expected = 'test-expected-name';
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
.withName(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const actual = parseScript(expected);
|
||||
const actual = parseScript(script, compiler);
|
||||
// assert
|
||||
expect(actual.name).to.equal(expected.name);
|
||||
expect(actual.code).to.equal(expected.code);
|
||||
expect(actual.revertCode).to.equal(expected.revertCode);
|
||||
expect(actual.documentationUrls).to.deep.equal(parseDocUrls(expected));
|
||||
expect(actual.isRecommended).to.equal(expected.recommend);
|
||||
expect(actual.name).to.equal(expected);
|
||||
});
|
||||
it('parses docs as expected', () => {
|
||||
// arrange
|
||||
const docs = [ 'https://expected-doc1.com', 'https://expected-doc2.com' ];
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
.withDocs(docs);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = parseDocUrls(script);
|
||||
// act
|
||||
const actual = parseScript(script, compiler);
|
||||
// assert
|
||||
expect(actual.documentationUrls).to.deep.equal(expected);
|
||||
});
|
||||
describe('invalid script', () => {
|
||||
it('throws when script is undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined script';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = undefined;
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when both function call and code are defined', () => {
|
||||
// arrange
|
||||
const expectedError = 'cannot define both "call" and "code"';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub
|
||||
.createWithCall()
|
||||
.withCode('code');
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when both function call and revertCode are defined', () => {
|
||||
// arrange
|
||||
const expectedError = 'cannot define "revertCode" if "call" is defined';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub
|
||||
.createWithCall()
|
||||
.withRevertCode('revert-code');
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when neither call or revertCode are defined', () => {
|
||||
// arrange
|
||||
const expectedError = 'must define either "call" or "code"';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub.createWithoutCallOrCodes();
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('level', () => {
|
||||
it('accepts undefined level', () => {
|
||||
const undefinedLevels: string[] = [ '', undefined ];
|
||||
undefinedLevels.forEach((undefinedLevel) => {
|
||||
// arrange
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
script.recommend = undefinedLevel;
|
||||
// act
|
||||
const actual = parseScript(script, compiler);
|
||||
// assert
|
||||
expect(actual.level).to.equal(undefined);
|
||||
});
|
||||
});
|
||||
it('throws on unknown level', () => {
|
||||
// arrange
|
||||
const unknownLevel = 'boi';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
script.recommend = unknownLevel;
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(`unknown level: "${unknownLevel}"`);
|
||||
});
|
||||
it('throws on non-string type', () => {
|
||||
const nonStringTypes: any[] = [ 5, true ];
|
||||
nonStringTypes.forEach((nonStringType) => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub();
|
||||
script.recommend = nonStringType;
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw(`level must be a string but it was ${typeof nonStringType}`);
|
||||
});
|
||||
});
|
||||
describe('parses level as expected', () => {
|
||||
for (const levelText of RecommendationLevelNames) {
|
||||
it(levelText, () => {
|
||||
// arrange
|
||||
const expectedLevel = RecommendationLevel[levelText];
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub();
|
||||
script.recommend = levelText;
|
||||
// act
|
||||
const actual = parseScript(script, compiler);
|
||||
// assert
|
||||
expect(actual.level).to.equal(expectedLevel);
|
||||
});
|
||||
}
|
||||
});
|
||||
it('parses level case insensitive', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = RecommendationLevel.Standard;
|
||||
script.recommend = RecommendationLevel[expected].toUpperCase();
|
||||
// act
|
||||
const actual = parseScript(script, compiler);
|
||||
// assert
|
||||
expect(actual.level).to.equal(expected);
|
||||
});
|
||||
});
|
||||
describe('code', () => {
|
||||
it('parses code as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-code';
|
||||
const script = YamlScriptStub
|
||||
.createWithCode()
|
||||
.withCode(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const parsed = parseScript(script, compiler);
|
||||
// assert
|
||||
const actual = parsed.code.execute;
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('parses revertCode as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-revert-code';
|
||||
const script = YamlScriptStub
|
||||
.createWithCode()
|
||||
.withRevertCode(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
const parsed = parseScript(script, compiler);
|
||||
// assert
|
||||
const actual = parsed.code.revert;
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
describe('compiler', () => {
|
||||
it('throws when compiler is not defined', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = undefined;
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
expect(act).to.throw('undefined compiler');
|
||||
});
|
||||
it('gets code from compiler', () => {
|
||||
// arrange
|
||||
const expected = new ScriptCode('test-script', 'code', 'revert-code');
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(script, expected);
|
||||
// act
|
||||
const parsed = parseScript(script, compiler);
|
||||
// assert
|
||||
const actual = parsed.code;
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,129 +7,158 @@ import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('UserFilter', () => {
|
||||
it('signals when removing filter', () => {
|
||||
// arrange
|
||||
let isCalled = false;
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
sut.filterRemoved.on(() => isCalled = true);
|
||||
// act
|
||||
sut.removeFilter();
|
||||
// assert
|
||||
expect(isCalled).to.be.equal(true);
|
||||
});
|
||||
it('signals when no matches', () => {
|
||||
// arrange
|
||||
let actual: IFilterResult;
|
||||
const nonMatchingFilter = 'non matching filter';
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(nonMatchingFilter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(false);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(0);
|
||||
expect(actual.query).to.equal(nonMatchingFilter);
|
||||
});
|
||||
describe('signals when script matches', () => {
|
||||
it('code matches', () => {
|
||||
describe('removeFilter', () => {
|
||||
it('signals when removing filter', () => {
|
||||
// arrange
|
||||
const code = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withCode(code);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
let isCalled = false;
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
sut.filterRemoved.on(() => isCalled = true);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
sut.removeFilter();
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(isCalled).to.be.equal(true);
|
||||
});
|
||||
it('revertCode matches', () => {
|
||||
it('sets currentFilter to undefined', () => {
|
||||
// arrange
|
||||
const revertCode = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withRevertCode(revertCode);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
sut.setFilter('non-important');
|
||||
sut.removeFilter();
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
});
|
||||
it('name matches', () => {
|
||||
// arrange
|
||||
const name = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withName(name);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.be.equal(undefined);
|
||||
});
|
||||
});
|
||||
it('signals when category matches', () => {
|
||||
// arrange
|
||||
const categoryName = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const category = new CategoryStub(55).withName(categoryName);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(1);
|
||||
expect(actual.categoryMatches[0]).to.deep.equal(category);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(0);
|
||||
expect(actual.query).to.equal(filter);
|
||||
});
|
||||
it('signals when category and script matches', () => {
|
||||
// arrange
|
||||
const matchingText = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('script')
|
||||
.withName(matchingText);
|
||||
const category = new CategoryStub(55)
|
||||
.withName(matchingText)
|
||||
.withScript(script);
|
||||
const app = new ApplicationStub()
|
||||
.withAction(category);
|
||||
const sut = new UserFilter(app);
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(1);
|
||||
expect(actual.categoryMatches[0]).to.deep.equal(category);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
describe('setFilter', () => {
|
||||
it('signals when no matches', () => {
|
||||
// arrange
|
||||
let actual: IFilterResult;
|
||||
const nonMatchingFilter = 'non matching filter';
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(nonMatchingFilter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(false);
|
||||
expect(actual.query).to.equal(nonMatchingFilter);
|
||||
});
|
||||
it('sets currentFilter as expected when no matches', () => {
|
||||
// arrange
|
||||
const nonMatchingFilter = 'non matching filter';
|
||||
const sut = new UserFilter(new ApplicationStub());
|
||||
// act
|
||||
sut.setFilter(nonMatchingFilter);
|
||||
// assert
|
||||
const actual = sut.currentFilter;
|
||||
expect(actual.hasAnyMatches()).be.equal(false);
|
||||
expect(actual.query).to.equal(nonMatchingFilter);
|
||||
});
|
||||
describe('signals when matches', () => {
|
||||
describe('signals when script matches', () => {
|
||||
it('code matches', () => {
|
||||
// arrange
|
||||
const code = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withCode(code);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.deep.equal(actual);
|
||||
});
|
||||
it('revertCode matches', () => {
|
||||
// arrange
|
||||
const revertCode = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withRevertCode(revertCode);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.deep.equal(actual);
|
||||
});
|
||||
it('name matches', () => {
|
||||
// arrange
|
||||
const name = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('id').withName(name);
|
||||
const category = new CategoryStub(33).withScript(script);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(0);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.deep.equal(actual);
|
||||
});
|
||||
});
|
||||
it('signals when category matches', () => {
|
||||
// arrange
|
||||
const categoryName = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const category = new CategoryStub(55).withName(categoryName);
|
||||
const sut = new UserFilter(new ApplicationStub()
|
||||
.withAction(category));
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(1);
|
||||
expect(actual.categoryMatches[0]).to.deep.equal(category);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(0);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.deep.equal(actual);
|
||||
});
|
||||
it('signals when category and script matches', () => {
|
||||
// arrange
|
||||
const matchingText = 'HELLO world';
|
||||
const filter = 'Hello WoRLD';
|
||||
let actual: IFilterResult;
|
||||
const script = new ScriptStub('script')
|
||||
.withName(matchingText);
|
||||
const category = new CategoryStub(55)
|
||||
.withName(matchingText)
|
||||
.withScript(script);
|
||||
const app = new ApplicationStub()
|
||||
.withAction(category);
|
||||
const sut = new UserFilter(app);
|
||||
sut.filtered.on((filterResult) => actual = filterResult);
|
||||
// act
|
||||
sut.setFilter(filter);
|
||||
// assert
|
||||
expect(actual.hasAnyMatches()).be.equal(true);
|
||||
expect(actual.categoryMatches).to.have.lengthOf(1);
|
||||
expect(actual.categoryMatches[0]).to.deep.equal(category);
|
||||
expect(actual.scriptMatches).to.have.lengthOf(1);
|
||||
expect(actual.scriptMatches[0]).to.deep.equal(script);
|
||||
expect(actual.query).to.equal(filter);
|
||||
expect(sut.currentFilter).to.deep.equal(actual);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,4 +292,92 @@ describe('UserSelection', () => {
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
describe('category state', () => {
|
||||
describe('when no scripts are selected', () => {
|
||||
// arrange
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2');
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app, [ ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
it('isAnySelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.isAnySelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
});
|
||||
describe('when no subscript exists in selected scripts', () => {
|
||||
// arrange
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2');
|
||||
const selectedScript = new ScriptStub('selected');
|
||||
const app = new ApplicationStub()
|
||||
.withAction(category)
|
||||
.withAction(new CategoryStub(22).withScript(selectedScript));
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
it('isAnySelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.isAnySelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
});
|
||||
describe('when one of the scripts are selected', () => {
|
||||
// arrange
|
||||
const selectedScript = new ScriptStub('selected');
|
||||
const category = new CategoryStub(1)
|
||||
.withScriptIds('non-selected-script-1', 'non-selected-script-2')
|
||||
.withCategory(new CategoryStub(12).withScript(selectedScript));
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app, [ new SelectedScript(selectedScript, false) ]);
|
||||
it('areAllSelected returns false', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
it('isAnySelected returns true', () => {
|
||||
// act
|
||||
const actual = sut.isAnySelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
describe('when all scripts are selected', () => {
|
||||
// arrange
|
||||
const firstSelectedScript = new ScriptStub('selected1');
|
||||
const secondSelectedScript = new ScriptStub('selected2');
|
||||
const category = new CategoryStub(1)
|
||||
.withScript(firstSelectedScript)
|
||||
.withCategory(new CategoryStub(12).withScript(secondSelectedScript));
|
||||
const app = new ApplicationStub().withAction(category);
|
||||
const sut = new UserSelection(app,
|
||||
[ firstSelectedScript, secondSelectedScript ].map((s) => new SelectedScript(s, false)));
|
||||
it('areAllSelected returns true', () => {
|
||||
// act
|
||||
const actual = sut.areAllSelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
it('isAnySelected returns true', () => {
|
||||
// act
|
||||
const actual = sut.isAnySelected(category);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,86 +1,178 @@
|
||||
import { ScriptStub } from './../stubs/ScriptStub';
|
||||
import { CategoryStub } from './../stubs/CategoryStub';
|
||||
import { Application } from './../../../src/domain/Application';
|
||||
import { Application } from '@/domain/Application';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { RecommendationLevel, RecommendationLevels } from '@/domain/RecommendationLevel';
|
||||
|
||||
describe('Application', () => {
|
||||
it('getRecommendedScripts returns as expected', () => {
|
||||
// arrange
|
||||
const expected = [
|
||||
new ScriptStub('S3').withIsRecommended(true),
|
||||
new ScriptStub('S4').withIsRecommended(true),
|
||||
];
|
||||
const sut = new Application('name', 'repo', '0.1.0', [
|
||||
new CategoryStub(3).withScripts(expected[0], new ScriptStub('S1').withIsRecommended(false)),
|
||||
new CategoryStub(2).withScripts(expected[1], new ScriptStub('S2').withIsRecommended(false)),
|
||||
]);
|
||||
|
||||
// act
|
||||
const actual = sut.getRecommendedScripts();
|
||||
|
||||
// assert
|
||||
expect(expected[0]).to.deep.equal(actual[0]);
|
||||
expect(expected[1]).to.deep.equal(actual[1]);
|
||||
describe('getScriptsByLevel', () => {
|
||||
it('filters out scripts without levels', () => {
|
||||
// arrange
|
||||
const scriptsWithLevels = RecommendationLevels.map((level, index) =>
|
||||
new ScriptStub(`Script${index}`).withLevel(level),
|
||||
);
|
||||
const toIgnore = new ScriptStub('script-to-ignore').withLevel(undefined);
|
||||
for (const currentLevel of RecommendationLevels) {
|
||||
const category = new CategoryStub(0)
|
||||
.withScripts(...scriptsWithLevels)
|
||||
.withScript(toIgnore);
|
||||
const sut = new Application(createInformation(), [category]);
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(currentLevel);
|
||||
// assert
|
||||
expect(actual).to.not.include(toIgnore);
|
||||
}
|
||||
});
|
||||
it(`${RecommendationLevel[RecommendationLevel.Standard]} filters ${RecommendationLevel[RecommendationLevel.Strict]}`, () => {
|
||||
// arrange
|
||||
const level = RecommendationLevel.Standard;
|
||||
const expected = [
|
||||
new ScriptStub('S1').withLevel(level),
|
||||
new ScriptStub('S2').withLevel(level),
|
||||
];
|
||||
const sut = new Application(createInformation(), [
|
||||
new CategoryStub(3).withScripts(...expected,
|
||||
new ScriptStub('S3').withLevel(RecommendationLevel.Strict)),
|
||||
]);
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(level);
|
||||
// assert
|
||||
expect(expected).to.deep.equal(actual);
|
||||
});
|
||||
it(`${RecommendationLevel[RecommendationLevel.Strict]} includes ${RecommendationLevel[RecommendationLevel.Standard]}`, () => {
|
||||
// arrange
|
||||
const level = RecommendationLevel.Strict;
|
||||
const expected = [
|
||||
new ScriptStub('S1').withLevel(RecommendationLevel.Standard),
|
||||
new ScriptStub('S2').withLevel(RecommendationLevel.Strict),
|
||||
];
|
||||
const sut = new Application(createInformation(), [
|
||||
new CategoryStub(3).withScripts(...expected),
|
||||
]);
|
||||
// act
|
||||
const actual = sut.getScriptsByLevel(level);
|
||||
// assert
|
||||
expect(expected).to.deep.equal(actual);
|
||||
});
|
||||
it('throws when level is undefined', () => {
|
||||
// arrange
|
||||
const sut = new Application(createInformation(), [ getCategoryForValidApplication() ]);
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(undefined);
|
||||
// assert
|
||||
expect(act).to.throw('undefined level');
|
||||
});
|
||||
it('throws when level is out of range', () => {
|
||||
// arrange
|
||||
const invalidValue = 66;
|
||||
const sut = new Application(createInformation(), [
|
||||
getCategoryForValidApplication(),
|
||||
]);
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(invalidValue);
|
||||
// assert
|
||||
expect(act).to.throw(`invalid level: ${invalidValue}`);
|
||||
});
|
||||
});
|
||||
it('cannot construct without categories', () => {
|
||||
// arrange
|
||||
const categories = [];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one category');
|
||||
describe('ctor', () => {
|
||||
it('cannot construct without categories', () => {
|
||||
// arrange
|
||||
const categories = [];
|
||||
// act
|
||||
function construct() { return new Application(createInformation(), categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one category');
|
||||
});
|
||||
it('cannot construct without scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3),
|
||||
new CategoryStub(2),
|
||||
];
|
||||
// act
|
||||
function construct() { return new Application(createInformation(), categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one script');
|
||||
});
|
||||
describe('cannot construct without any recommended scripts', () => {
|
||||
for (const missingLevel of RecommendationLevels) {
|
||||
// arrange
|
||||
const expectedError = `none of the scripts are recommended as ${RecommendationLevel[missingLevel]}`;
|
||||
const otherLevels = RecommendationLevels.filter((level) => level !== missingLevel);
|
||||
const categories = otherLevels.map((level, index) =>
|
||||
new CategoryStub(index).withScript(new ScriptStub(`Script${index}`).withLevel(level)),
|
||||
);
|
||||
// act
|
||||
const construct = () => new Application(createInformation(), categories);
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
}
|
||||
});
|
||||
it('cannot construct without information', () => {
|
||||
// arrange
|
||||
const categories = [ new CategoryStub(1).withScripts(
|
||||
new ScriptStub('S1').withLevel(RecommendationLevel.Standard))];
|
||||
const information = undefined;
|
||||
// act
|
||||
function construct() { return new Application(information, categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('info is undefined');
|
||||
});
|
||||
});
|
||||
it('cannot construct without scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3),
|
||||
new CategoryStub(2),
|
||||
];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one script');
|
||||
describe('totalScripts', () => {
|
||||
it('returns total of initial scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(1).withScripts(
|
||||
new ScriptStub('S1').withLevel(RecommendationLevel.Standard)),
|
||||
new CategoryStub(2).withScripts(
|
||||
new ScriptStub('S2'),
|
||||
new ScriptStub('S3').withLevel(RecommendationLevel.Strict)),
|
||||
new CategoryStub(3).withCategories(
|
||||
new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const sut = new Application(createInformation(), categories);
|
||||
// assert
|
||||
expect(sut.totalScripts).to.equal(4);
|
||||
});
|
||||
});
|
||||
it('cannot construct without any recommended scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3).withScripts(new ScriptStub('S1').withIsRecommended(false)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2').withIsRecommended(false)),
|
||||
];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one recommended script');
|
||||
describe('totalCategories', () => {
|
||||
it('returns total of initial categories', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(1).withScripts(new ScriptStub('S1').withLevel(RecommendationLevel.Strict)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2'), new ScriptStub('S3')),
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const sut = new Application(createInformation(), categories);
|
||||
// assert
|
||||
expect(sut.totalCategories).to.equal(4);
|
||||
});
|
||||
});
|
||||
it('totalScripts counts right', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(1).withScripts(new ScriptStub('S1').withIsRecommended(true)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2'), new ScriptStub('S3')),
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const application = new Application('name', 'repo', '0.1.0', categories);
|
||||
// assert
|
||||
expect(application.totalScripts).to.equal(4);
|
||||
});
|
||||
it('totalCategories counts right', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(1).withScripts(new ScriptStub('S1').withIsRecommended(true)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2'), new ScriptStub('S3')),
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const application = new Application('name', 'repo', '0.1.0', categories);
|
||||
// assert
|
||||
expect(application.totalCategories).to.equal(4);
|
||||
describe('info', () => {
|
||||
it('returns initial information', () => {
|
||||
// arrange
|
||||
const expected = createInformation();
|
||||
// act
|
||||
const sut = new Application(
|
||||
expected, [ getCategoryForValidApplication() ]);
|
||||
// assert
|
||||
expect(sut.info).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getCategoryForValidApplication() {
|
||||
return new CategoryStub(1).withScripts(
|
||||
new ScriptStub('S1').withLevel(RecommendationLevel.Standard),
|
||||
new ScriptStub('S2').withLevel(RecommendationLevel.Strict));
|
||||
}
|
||||
|
||||
function createInformation(): IProjectInformation {
|
||||
return new ProjectInformation('name', 'repo', '0.1.0', 'homepage');
|
||||
}
|
||||
|
||||
@@ -86,4 +86,41 @@ describe('Category', () => {
|
||||
expect(actualIds).to.have.deep.members(expectedScriptIds);
|
||||
});
|
||||
});
|
||||
describe('includes', () => {
|
||||
it('return false when does not include', () => {
|
||||
// assert
|
||||
const script = new ScriptStub('3');
|
||||
const sut = new Category(0, 'category', [], [new CategoryStub(33).withScriptIds('1', '2')], []);
|
||||
// act
|
||||
const actual = sut.includes(script);
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
it('return true when includes as subscript', () => {
|
||||
// assert
|
||||
const script = new ScriptStub('3');
|
||||
const sut = new Category(0, 'category', [], [
|
||||
new CategoryStub(33).withScript(script).withScriptIds('non-related'),
|
||||
], []);
|
||||
// act
|
||||
const actual = sut.includes(script);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
it('return true when includes as nested category script', () => {
|
||||
// assert
|
||||
const script = new ScriptStub('3');
|
||||
const sut = new Category(11, 'category', [],
|
||||
[
|
||||
new CategoryStub(22)
|
||||
.withScriptIds('non-relatedd')
|
||||
.withCategory(new CategoryStub(33).withScript(script)),
|
||||
],
|
||||
[]);
|
||||
// act
|
||||
const actual = sut.includes(script);
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
128
tests/unit/domain/ProjectInformation.spec.ts
Normal file
128
tests/unit/domain/ProjectInformation.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
describe('ProjectInformation', () => {
|
||||
it('sets name as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-name';
|
||||
const sut = new ProjectInformation(expected, 'version', 'repositoryUrl', 'homepage');
|
||||
// act
|
||||
const actual = sut.name;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets version as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-version';
|
||||
const sut = new ProjectInformation('name', expected, 'repositoryUrl', 'homepage');
|
||||
// act
|
||||
const actual = sut.version;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets repositoryUrl as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-repository-url';
|
||||
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
|
||||
// act
|
||||
const actual = sut.repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
describe('sets repositoryWebUrl as expected', () => {
|
||||
it('sets repositoryUrl when it does not end with .git', () => {
|
||||
// arrange
|
||||
const expected = 'expected-repository-url';
|
||||
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
|
||||
// act
|
||||
const actual = sut.repositoryWebUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('removes ".git" from the end when it ends with ".git"', () => {
|
||||
// arrange
|
||||
const expected = 'expected-repository-url';
|
||||
const sut = new ProjectInformation('name', 'version', `${expected}.git`, 'homepage');
|
||||
// act
|
||||
const actual = sut.repositoryWebUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
it('sets homepage as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-homepage';
|
||||
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', expected);
|
||||
// act
|
||||
const actual = sut.homepage;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets feedbackUrl to github issues page', () => {
|
||||
// arrange
|
||||
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
|
||||
const expected = 'https://github.com/undergroundwires/privacy.sexy/issues';
|
||||
const sut = new ProjectInformation('name', 'version', repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.feedbackUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets releaseUrl to github releases page', () => {
|
||||
// arrange
|
||||
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
|
||||
const version = '0.7.2';
|
||||
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/tag/0.7.2';
|
||||
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.releaseUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
describe('getDownloadUrl', () => {
|
||||
it('gets expected url for macOS', () => {
|
||||
// arrange
|
||||
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-0.7.2.dmg';
|
||||
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
|
||||
const version = '0.7.2';
|
||||
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.macOS);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('gets expected url for Linux', () => {
|
||||
// arrange
|
||||
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-0.7.2.AppImage';
|
||||
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
|
||||
const version = '0.7.2';
|
||||
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.Linux);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('gets expected url for Windows', () => {
|
||||
// arrange
|
||||
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-Setup-0.7.2.exe';
|
||||
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
|
||||
const version = '0.7.2';
|
||||
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.Windows);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('throws when OS is unknown', () => {
|
||||
// arrange
|
||||
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', 'homepage');
|
||||
const os = OperatingSystem.Unknown;
|
||||
// act
|
||||
const act = () => sut.getDownloadUrl(os);
|
||||
// assert
|
||||
expect(act).to.throw(`Unsupported os: ${OperatingSystem[os]}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
17
tests/unit/domain/RecommendationLevel.ts
Normal file
17
tests/unit/domain/RecommendationLevel.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { RecommendationLevelNames, RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
|
||||
describe('RecommendationLevel', () => {
|
||||
describe('RecommendationLevelNames', () => {
|
||||
// arrange
|
||||
const expected = [
|
||||
RecommendationLevel[RecommendationLevel.Strict],
|
||||
RecommendationLevel[RecommendationLevel.Standard],
|
||||
];
|
||||
// act
|
||||
const actual = RecommendationLevelNames;
|
||||
// assert
|
||||
expect(actual).to.have.deep.members(expected);
|
||||
});
|
||||
});
|
||||
@@ -1,46 +1,149 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { Script } from '@/domain/Script';
|
||||
import { RecommendationLevel, RecommendationLevels } from '@/domain/RecommendationLevel';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
|
||||
describe('Script', () => {
|
||||
describe('ctor', () => {
|
||||
describe('code', () => {
|
||||
it('cannot construct with duplicate lines', () => {
|
||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
||||
expect(() => createWithCode(code)).to.throw();
|
||||
describe('scriptCode', () => {
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const name = 'test-script';
|
||||
const expected = new ScriptCode(name, 'expected-execute', 'expected-revert');
|
||||
const sut = new ScriptBuilder()
|
||||
.withCode(expected)
|
||||
.build();
|
||||
// act
|
||||
const actual = sut.code;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('cannot construct with empty lines', () => {
|
||||
const code = 'duplicate\n\n\ntest\nduplicate';
|
||||
expect(() => createWithCode(code)).to.throw();
|
||||
});
|
||||
});
|
||||
describe('revertCode', () => {
|
||||
it('cannot construct with duplicate lines', () => {
|
||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
||||
expect(() => createWithCode('REM', code)).to.throw();
|
||||
});
|
||||
it('cannot construct with empty lines', () => {
|
||||
const code = 'duplicate\n\n\ntest\nduplicate';
|
||||
expect(() => createWithCode('REM', code)).to.throw();
|
||||
});
|
||||
it('cannot construct with when same as code', () => {
|
||||
const code = 'REM';
|
||||
expect(() => createWithCode(code, code)).to.throw();
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const name = 'script-name';
|
||||
const expectedError = `undefined code (script: ${name})`;
|
||||
const code: IScriptCode = undefined;
|
||||
// act
|
||||
const construct = () => new ScriptBuilder()
|
||||
.withName(name)
|
||||
.withCode(code)
|
||||
.build();
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('canRevert', () => {
|
||||
it('returns false without revert code', () => {
|
||||
const sut = createWithCode('code');
|
||||
expect(sut.canRevert()).to.equal(false);
|
||||
// arrange
|
||||
const sut = new ScriptBuilder()
|
||||
.withCodes('code')
|
||||
.build();
|
||||
// act
|
||||
const actual = sut.canRevert();
|
||||
// assert
|
||||
expect(actual).to.equal(false);
|
||||
});
|
||||
it('returns true with revert code', () => {
|
||||
const sut = createWithCode('code', 'non empty revert code');
|
||||
expect(sut.canRevert()).to.equal(true);
|
||||
// arrange
|
||||
const sut = new ScriptBuilder()
|
||||
.withCodes('code', 'non empty revert code')
|
||||
.build();
|
||||
// act
|
||||
const actual = sut.canRevert();
|
||||
// assert
|
||||
expect(actual).to.equal(true);
|
||||
});
|
||||
});
|
||||
describe('level', () => {
|
||||
it('cannot construct with invalid wrong value', () => {
|
||||
// arrange
|
||||
const invalidValue: RecommendationLevel = 55;
|
||||
const expectedError = 'invalid level';
|
||||
// act
|
||||
const construct = () => new ScriptBuilder()
|
||||
.withRecommendationLevel(invalidValue)
|
||||
.build();
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
it('sets undefined as expected', () => {
|
||||
// arrange
|
||||
const expected = undefined;
|
||||
// act
|
||||
const sut = new ScriptBuilder()
|
||||
.withRecommendationLevel(expected)
|
||||
.build();
|
||||
// assert
|
||||
expect(sut.level).to.equal(expected);
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
for (const expected of RecommendationLevels) {
|
||||
// act
|
||||
const sut = new ScriptBuilder()
|
||||
.withRecommendationLevel(expected)
|
||||
.build();
|
||||
// assert
|
||||
const actual = sut.level;
|
||||
expect(actual).to.equal(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
describe('documentationUrls', () => {
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const expected = [ 'doc1', 'doc2 '];
|
||||
// act
|
||||
const sut = new ScriptBuilder()
|
||||
.withDocumentationUrls(expected)
|
||||
.build();
|
||||
const actual = sut.documentationUrls;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createWithCode(code: string, revertCode?: string): Script {
|
||||
return new Script('name', code, revertCode, [], false);
|
||||
class ScriptBuilder {
|
||||
private name = 'test-script';
|
||||
private code: IScriptCode = new ScriptCode(this.name, 'code', 'revert-code');
|
||||
private level = RecommendationLevel.Standard;
|
||||
private documentationUrls: readonly string[] = undefined;
|
||||
|
||||
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
||||
this.code = new ScriptCode(this.name, code, revertCode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCode(code: IScriptCode): ScriptBuilder {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withName(name: string): ScriptBuilder {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRecommendationLevel(level: RecommendationLevel): ScriptBuilder {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withDocumentationUrls(urls: readonly string[]): ScriptBuilder {
|
||||
this.documentationUrls = urls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public build(): Script {
|
||||
return new Script(
|
||||
this.name,
|
||||
this.code,
|
||||
this.documentationUrls,
|
||||
this.level,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
93
tests/unit/domain/ScriptCode.spec.ts
Normal file
93
tests/unit/domain/ScriptCode.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
|
||||
describe('ScriptCode', () => {
|
||||
describe('scriptName', () => {
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'name is undefined';
|
||||
const name = undefined;
|
||||
// act
|
||||
const act = () => new ScriptCode(name, 'non-empty-code', '');
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('code', () => {
|
||||
it('cannot construct with duplicate lines', () => {
|
||||
// arrange
|
||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
||||
// act
|
||||
const act = () => createSut(code);
|
||||
// assert
|
||||
expect(act).to.throw();
|
||||
});
|
||||
it('cannot construct with empty lines', () => {
|
||||
// arrange
|
||||
const code = 'line1\n\n\nline2';
|
||||
// act
|
||||
const act = () => createSut(code);
|
||||
// assert
|
||||
expect(act).to.throw();
|
||||
});
|
||||
it('cannot construct with empty or undefined values', () => {
|
||||
// arrange
|
||||
const name = 'test-code';
|
||||
const errorMessage = `code of ${name} is empty or undefined`;
|
||||
const invalidValues = [ '', undefined ];
|
||||
invalidValues.forEach((invalidValue) => {
|
||||
// act
|
||||
const act = () => new ScriptCode(name, invalidValue, '');
|
||||
// assert
|
||||
expect(act).to.throw(errorMessage);
|
||||
});
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-revert';
|
||||
// act
|
||||
const sut = createSut(expected);
|
||||
// assert
|
||||
expect(sut.execute).to.equal(expected);
|
||||
});
|
||||
});
|
||||
describe('revert', () => {
|
||||
it('cannot construct with duplicate lines', () => {
|
||||
// arrange
|
||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
||||
// act
|
||||
const act = () => createSut('REM', code);
|
||||
// assert
|
||||
expect(act).to.throw();
|
||||
});
|
||||
it('cannot construct with empty lines', () => {
|
||||
// arrange
|
||||
const code = 'line1\n\n\nline2';
|
||||
// act
|
||||
const act = () => createSut('REM', code);
|
||||
// assert
|
||||
expect(act).to.throw();
|
||||
});
|
||||
it('cannot construct with when same as code', () => {
|
||||
// arrange
|
||||
const code = 'REM';
|
||||
// act
|
||||
const act = () => createSut(code, code);
|
||||
// assert
|
||||
expect(act).to.throw();
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-revert';
|
||||
// act
|
||||
const sut = createSut('abc', expected);
|
||||
// assert
|
||||
expect(sut.revert).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createSut(code: string, revert = ''): ScriptCode {
|
||||
return new ScriptCode('test-code', code, revert);
|
||||
}
|
||||
@@ -3,11 +3,11 @@ import { expect } from 'chai';
|
||||
import { getScriptNodeId, getScriptId, getCategoryNodeId, getCategoryId } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { CategoryStub } from '../../../stubs/CategoryStub';
|
||||
import { ScriptStub } from '../../../stubs/ScriptStub';
|
||||
import { parseSingleCategory, parseAllCategories } from '../../../../../src/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { parseSingleCategory, parseAllCategories } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { ApplicationStub } from '../../../stubs/ApplicationStub';
|
||||
import { INode, NodeType } from '../../../../../src/presentation/Scripts/ScriptsTree/SelectableTree/Node/INode';
|
||||
import { IScript } from '../../../../../src/domain/IScript';
|
||||
import { ICategory } from '../../../../../src/domain/ICategory';
|
||||
import { INode, NodeType } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/INode';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
|
||||
describe('ScriptNodeParser', () => {
|
||||
it('can convert script id and back', () => {
|
||||
@@ -80,7 +80,7 @@ describe('ScriptNodeParser', () => {
|
||||
|
||||
function isReversible(category: ICategory): boolean {
|
||||
if (category.scripts) {
|
||||
return category.scripts.every((s) => s.revertCode);
|
||||
return category.scripts.every((s) => s.canRevert());
|
||||
}
|
||||
return category.subCategories.every((c) => isReversible(c));
|
||||
}
|
||||
@@ -100,8 +100,8 @@ function expectSameCategory(node: INode, category: ICategory): void {
|
||||
}
|
||||
function getErrorMessage(field: string) {
|
||||
return `Unexpected node field: ${field}.\n` +
|
||||
`\nActual node:\n${JSON.stringify(node, null, 2)}` +
|
||||
`\nExpected category:\n${JSON.stringify(category, null, 2)}`;
|
||||
`\nActual node:\n${print(node)}` +
|
||||
`\nExpected category:\n${print(category)}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +110,15 @@ function expectSameScript(node: INode, script: IScript): void {
|
||||
expect(node.id).to.equal(getScriptNodeId(script), getErrorMessage('id'));
|
||||
expect(node.documentationUrls).to.equal(script.documentationUrls, getErrorMessage('documentationUrls'));
|
||||
expect(node.text).to.equal(script.name, getErrorMessage('name'));
|
||||
expect(node.isReversible).to.equal(!!script.revertCode, getErrorMessage('revertCode'));
|
||||
expect(node.isReversible).to.equal(script.canRevert(), getErrorMessage('canRevert'));
|
||||
expect(node.children).to.equal(undefined);
|
||||
function getErrorMessage(field: string) {
|
||||
return `Unexpected node field: ${field}.` +
|
||||
`\nActual node:\n${JSON.stringify(node, null, 2)}\n` +
|
||||
`\nExpected script:\n${JSON.stringify(script, null, 2)}`;
|
||||
`\nActual node:\n${print(node)}\n` +
|
||||
`\nExpected script:\n${print(script)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function print(object: any) {
|
||||
return JSON.stringify(object, null, 2);
|
||||
}
|
||||
|
||||
@@ -4,199 +4,200 @@ import { ILiquorTreeNode } from 'liquor-tree';
|
||||
import { NodeType } from '@/presentation/Scripts/ScriptsTree/SelectableTree/Node/INode';
|
||||
import { getNewState } from '@/presentation/Scripts/ScriptsTree/SelectableTree/LiquorTree/NodeWrapper/NodeStateUpdater';
|
||||
|
||||
describe('getNewState', () => {
|
||||
describe('checked', () => {
|
||||
describe('script node', () => {
|
||||
it('true when selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', node.id, 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(true);
|
||||
describe('NodeStateUpdater', () => {
|
||||
describe('getNewState', () => {
|
||||
describe('checked', () => {
|
||||
describe('script node', () => {
|
||||
it('true when selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', node.id, 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(true);
|
||||
});
|
||||
it('false when unselected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
});
|
||||
});
|
||||
it('false when unselected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
describe('category node', () => {
|
||||
it('true when every child selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(true);
|
||||
});
|
||||
it('false when none of the children is selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'none', 'of', 'them', 'are', 'selected' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
});
|
||||
it('false when some of the children is selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{
|
||||
id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'c', 'unrelated' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('category node', () => {
|
||||
it('true when every child selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(true);
|
||||
describe('indeterminate', () => {
|
||||
describe('script node', () => {
|
||||
it('false when selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', node.id, 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
it('false when not selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
});
|
||||
it('false when none of the children is selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'none', 'of', 'them', 'are', 'selected' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
});
|
||||
it('false when some of the children is selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{
|
||||
id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'c', 'unrelated' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.checked).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('indeterminate', () => {
|
||||
describe('script node', () => {
|
||||
it('false when selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', node.id, 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
it('false when not selected', () => {
|
||||
// arrange
|
||||
const node = getScriptNode();
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
});
|
||||
describe('category node', () => {
|
||||
it('false when all children are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
it('true when all some are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(true);
|
||||
});
|
||||
it('false when no children are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'none', 'of', 'them', 'are', 'selected' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
describe('category node', () => {
|
||||
it('false when all children are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a', 'b', 'c' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
it('true when all some are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'a' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(true);
|
||||
});
|
||||
it('false when no children are selected', () => {
|
||||
// arrange
|
||||
const node = {
|
||||
id: '1',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [
|
||||
{ id: '2',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('a'), getScriptNode('b') ],
|
||||
},
|
||||
{ id: '3',
|
||||
data: { type: NodeType.Category, documentationUrls: [], isReversible: false },
|
||||
children: [ getScriptNode('c') ],
|
||||
},
|
||||
],
|
||||
};
|
||||
const selectedScriptNodeIds = [ 'none', 'of', 'them', 'are', 'selected' ];
|
||||
// act
|
||||
const state = getNewState(node, selectedScriptNodeIds);
|
||||
// assert
|
||||
expect(state.indeterminate).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
function getScriptNode(scriptNodeId: string = 'script'): ILiquorTreeNode {
|
||||
return {
|
||||
id: scriptNodeId,
|
||||
data: {
|
||||
type: NodeType.Script,
|
||||
documentationUrls: [],
|
||||
isReversible: false,
|
||||
},
|
||||
children: [],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function getScriptNode(scriptNodeId: string = 'script'): ILiquorTreeNode {
|
||||
return {
|
||||
id: scriptNodeId,
|
||||
data: {
|
||||
type: NodeType.Script,
|
||||
documentationUrls: [],
|
||||
isReversible: false,
|
||||
},
|
||||
children: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ScriptReverter } from '@/presentation/Scripts/ScriptsTree/SelectableTre
|
||||
import { SelectedScriptStub } from '../../../../../../stubs/SelectedScriptStub';
|
||||
import { getScriptNodeId } from '@/presentation/Scripts/ScriptsTree/ScriptNodeParser';
|
||||
import { ScriptStub } from '../../../../../../stubs/ScriptStub';
|
||||
import { UserSelection } from '../../../../../../../../src/application/State/Selection/UserSelection';
|
||||
import { UserSelection } from '@/application/State/Selection/UserSelection';
|
||||
import { SelectedScript } from '@/application/State/Selection/SelectedScript';
|
||||
import { ApplicationStub } from '../../../../../../stubs/ApplicationStub';
|
||||
import { CategoryStub } from '../../../../../../stubs/CategoryStub';
|
||||
@@ -68,7 +68,7 @@ describe('ScriptReverter', () => {
|
||||
selection: [ new SelectedScript(script, true)], revert: true, expectRevert: true,
|
||||
},
|
||||
{
|
||||
name: 'keeps revert state deselected when already selected wtih non revert state',
|
||||
name: 'keeps revert state deselected when already selected with non revert state',
|
||||
selection: [ new SelectedScript(script, false)], revert: false, expectRevert: false,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { IApplication, ICategory, IScript } from '@/domain/IApplication';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
|
||||
export class ApplicationStub implements IApplication {
|
||||
public totalScripts = 0;
|
||||
public totalCategories = 0;
|
||||
public readonly name = 'StubApplication';
|
||||
public readonly repositoryUrl = 'https://privacy.sexy';
|
||||
public readonly version = '0.1.0';
|
||||
public readonly info = new ProjectInformation('StubApplication', '0.1.0', 'https://github.com/undergroundwires/privacy.sexy', 'https://privacy.sexy');
|
||||
public readonly actions = new Array<ICategory>();
|
||||
|
||||
public withAction(category: ICategory): ApplicationStub {
|
||||
@@ -16,8 +15,8 @@ export class ApplicationStub implements IApplication {
|
||||
return this.getAllCategories().find(
|
||||
(category) => category.id === categoryId);
|
||||
}
|
||||
public getRecommendedScripts(): readonly IScript[] {
|
||||
throw new Error('Method not implemented: getRecommendedScripts');
|
||||
public getScriptsByLevel(): readonly IScript[] {
|
||||
throw new Error('Method not implemented: getScriptsByLevel');
|
||||
}
|
||||
public findScript(scriptId: string): IScript {
|
||||
return this.getAllScripts().find((script) => scriptId === script.id);
|
||||
|
||||
@@ -12,6 +12,10 @@ export class CategoryStub extends BaseEntity<number> implements ICategory {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public includes(script: IScript): boolean {
|
||||
return this.getAllScriptsRecursively().some((s) => s.id === script.id);
|
||||
}
|
||||
|
||||
public getAllScriptsRecursively(): readonly IScript[] {
|
||||
return [
|
||||
...this.scripts,
|
||||
|
||||
18
tests/unit/stubs/ScriptCompilerStub.ts
Normal file
18
tests/unit/stubs/ScriptCompilerStub.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
|
||||
export class ScriptCompilerStub implements IScriptCompiler {
|
||||
public compilables = new Map<YamlScript, IScriptCode>();
|
||||
public canCompile(script: YamlScript): boolean {
|
||||
return this.compilables.has(script);
|
||||
}
|
||||
public compile(script: YamlScript): IScriptCode {
|
||||
return this.compilables.get(script);
|
||||
}
|
||||
public withCompileAbility(script: YamlScript, result?: IScriptCode): ScriptCompilerStub {
|
||||
this.compilables.set(script, result ||
|
||||
{ execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` });
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,41 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
|
||||
export class ScriptStub extends BaseEntity<string> implements IScript {
|
||||
public name = `name${this.id}`;
|
||||
public code = `REM code${this.id}`;
|
||||
public revertCode = `REM revertCode${this.id}`;
|
||||
public code = {
|
||||
execute: `REM execute-code (${this.id})`,
|
||||
revert: `REM revert-code (${this.id})`,
|
||||
};
|
||||
public readonly documentationUrls = new Array<string>();
|
||||
public isRecommended = true;
|
||||
public level = RecommendationLevel.Standard;
|
||||
|
||||
constructor(public readonly id: string) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public canRevert(): boolean {
|
||||
return Boolean(this.revertCode);
|
||||
return Boolean(this.code.revert);
|
||||
}
|
||||
|
||||
public withIsRecommended(value: boolean): ScriptStub {
|
||||
this.isRecommended = value;
|
||||
public withLevel(value: RecommendationLevel): ScriptStub {
|
||||
this.level = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCode(value: string): ScriptStub {
|
||||
this.code = value;
|
||||
this.code.execute = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withName(name: string): ScriptStub {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRevertCode(revertCode: string): ScriptStub {
|
||||
this.revertCode = revertCode;
|
||||
this.code.revert = revertCode;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
61
tests/unit/stubs/YamlScriptStub.ts
Normal file
61
tests/unit/stubs/YamlScriptStub.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptFunctionCall, YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
|
||||
export class YamlScriptStub implements YamlScript {
|
||||
public static createWithCode(): YamlScriptStub {
|
||||
return new YamlScriptStub()
|
||||
.withCode('stub-code')
|
||||
.withRevertCode('stub-revert-code');
|
||||
}
|
||||
public static createWithCall(call?: ScriptFunctionCall): YamlScriptStub {
|
||||
let instance = new YamlScriptStub();
|
||||
if (call) {
|
||||
instance = instance.withCall(call);
|
||||
} else {
|
||||
instance = instance.withMockCall();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public static createWithoutCallOrCodes(): YamlScriptStub {
|
||||
return new YamlScriptStub();
|
||||
}
|
||||
|
||||
public name = 'valid-name';
|
||||
public code = undefined;
|
||||
public revertCode = undefined;
|
||||
public call = undefined;
|
||||
public recommend = RecommendationLevel[RecommendationLevel.Standard].toLowerCase();
|
||||
public docs = ['hello.com'];
|
||||
|
||||
private constructor() { }
|
||||
|
||||
public withName(name: string): YamlScriptStub {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withDocs(docs: string[]): YamlScriptStub {
|
||||
this.docs = docs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCode(code: string): YamlScriptStub {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRevertCode(revertCode: string): YamlScriptStub {
|
||||
this.revertCode = revertCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withMockCall(): YamlScriptStub {
|
||||
this.call = { function: 'func', parameters: [] };
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCall(call: ScriptFunctionCall): YamlScriptStub {
|
||||
this.call = call;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
process.env.VUE_APP_VERSION = require('./package.json').version;
|
||||
const packageJson = require('./package.json');
|
||||
|
||||
process.env.VUE_APP_VERSION = packageJson.version;
|
||||
process.env.VUE_APP_NAME = packageJson.name;
|
||||
process.env.VUE_APP_REPOSITORY_URL = packageJson.repository.url;
|
||||
process.env.VUE_APP_HOMEPAGE_URL = packageJson.homepage;
|
||||
|
||||
module.exports = {
|
||||
pluginOptions: {
|
||||
|
||||
Reference in New Issue
Block a user