It allow pipes to be used in nested functions. Before, pipes were added
to a variable before variable content was evaluated/compiled by
another function. This commit ensures that the commits are evaluted in
expected order.
The issue is solved by stopping precompiling functions. It makes code
less complex. It adds to compile time of the script file but nothing
noticable and something optimizable.
The problem was that the call trees we're not executed in expected
order. E.g. let's say we have functionA that outputs something like
"Hello {{ $name| pipe }}", and we have function B calling with "name:
dear {{ $firstName}}", and at last we have a script that's calling
function B with "firstName: undergroundwires". Before, expressions were
evaluated directly, meaning that function A would become:
"Hello Dear {{ $firstName}}", as you see the pipe in function A
is lost here after being applied to function B and not reaching
$firstTime input value. Parsing expressions in the end allows for pipes
etc. to not get lost.
The commit also does necessary name refactorings and folder refactorings
to reflect logical changes. `FunctionCompiler` is renamed to
`SharedFunctionsParser` as precompiling is removed and it just simply
parses now. `/FunctionCall/` is moved to `/Function/Call`.
Finally, it improves documentation and adds more tests.
8.7 KiB
8.7 KiB
Collection files
- privacy.sexy is a data-driven application where it reads the necessary OS-specific logic from yaml files in
application/collections - 💡 Best practices
- If you repeat yourself, try to utilize YAML-defined functions
- Always try to add documentation and a way to revert a tweak in scripts
- 📖 Types in code:
collection.yaml.d.ts
Objects
Collection
- A collection simply defines:
- different categories and their scripts in a tree structure
- OS specific details
- Also allows defining common functions to be used throughout the collection if you'd like different scripts to share same code.
Collection syntax
os:string(required)- Operating system that the Collection is written for.
- 📖 See OperatingSystem.ts enumeration for allowed values.
actions: [Category, ... ](required)- Each category is rendered as different cards in card presentation.
- ❗ A Collection must consist of at least one category.
functions: [Function, ... ]- Functions are optionally defined to re-use the same code throughout different scripts.
scripting:ScriptingDefinition(required)- Defines the scripting language that the code of other action uses.
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 Collection
children: [Category|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 can be of two different types (just like functions):
- Inline script; a script with an inline code
- Must define
codeproperty and optionallyrevertCodebut notcall
- Must define
- Caller script; a script that calls other functions
- Must define
callproperty but notcodeorrevertCode
- Must define
- Inline script; a script with an inline code
- 🙏 For any new script, please add
revertCodeanddocsvalues if possible.
Script syntax
name:string(required)- Name of the script
- ❗ Must be unique throughout the Collection
- 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
callmust be defined, do not define ifcallis defined.
revertCode:string- Code that'll undo the change done by
codeproperty. - E.g. let's say
codesets an environment variable assetx POWERSHELL_TELEMETRY_OPTOUT 1- then
revertCodeshould be doingsetx POWERSHELL_TELEMETRY_OPTOUT 0
- then
- ❗ Do not define if
callis defined.
- Code that'll undo the change done by
call:FunctionCall|[FunctionCall, ... ](may be required)- A shared function or sequence of functions to call (called in order)
- ❗ If not defined
codemust 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 functionalitystrict: 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 for an example usage
FunctionCall syntax
function:string(required)- Name of the function to call.
- ❗ Function with same name must defined in
functionsproperty of Collection
parameters:[ parameterName:parameterValue, ... ]-
Defines key value dictionary for each parameter and its value
-
E.g.
parameters: userDefinedParameterName: parameterValue # ... appName: Microsoft.WindowsFeedbackHub -
💡 Expressions (templating) can be used as parameter value
-
Function
- Functions allow re-usable code throughout the defined scripts.
- Functions are templates compiled by privacy.sexy and uses special expression expressions.
- A function can be of two different types (just like scripts):
- Inline function: a function with an inline code.
- Must define
codeproperty and optionallyrevertCodebut notcall.
- Must define
- Caller function: a function that calls other functions.
- Must define
callproperty but notcodeorrevertCode.
- Must define
- Inline function: a function with an inline code.
- 👀 Read more on Templating for function expressions and example usages.
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:[FunctionParameter, ... ]- List of parameters that function code refers to.
- ❗ Must be defined to be able use in
FunctionCallor expressions (templating)code:string(required ifcallis undefined) - Batch file commands that will be executed
- 💡 Expressions (templating) can be used in its value
- 💡 If defined, best practice to also define
revertCode - ❗ If not defined
callmust be defined
revertCode:string- Code that'll undo the change done by
codeproperty. - E.g. let's say
codesets an environment variable assetx POWERSHELL_TELEMETRY_OPTOUT 1- then
revertCodeshould be doingsetx POWERSHELL_TELEMETRY_OPTOUT 0
- then
- 💡 Expressions (templating) can be used in code
- Code that'll undo the change done by
call:FunctionCall|[FunctionCall, ... ](may be required)- A shared function or sequence of functions to call (called in order)
- The parameter values that are sent can use expressions (templating)
- ❗ If not defined
codemust be defined
FunctionParameter
- Defines a parameter that function requires optionally or mandatory.
- Its arguments are provided by a Script through a FunctionCall.
FunctionParameter syntax
name:string(required)- Name of the parameters that the function has.
- Parameter names must be defined to be used in expressions (templating).
- ❗ Parameter names must be unique and include alphanumeric characters only.
optional:boolean(default:false)- Specifies whether the caller Script must provide any value for the parameter.
- If set to
falsei.e. an argument value is not optional then it expects a non-empty value for the variable;- Otherwise it throws.
- 💡 Set it to
trueif a parameter is used conditionally;- Or else set it to
falsefor verbosity or do not define it as default value isfalseanyway.
- Or else set it to
- 💡 Can be used in conjunction with
withexpression.
ScriptingDefinition
- Defines global properties for scripting that's used throughout its parent Collection.
ScriptingDefinition syntax
language:string(required)- 📖 See ScriptingLanguage.ts enumeration for allowed values.
startCode:string(required)- Code that'll be inserted on top of user created script.
- Global variables such as
$homepage,$version,$datecan be used using parameter substitution code syntax such asWelcome to {{ $homepage }}!
endCode:string(required)- Code that'll be inserted at the end of user created script.
- Global variables such as
$homepage,$version,$datecan be used using parameter substitution code syntax such asWelcome to {{ $homepage }}!