Skip to content

Commit

Permalink
fix: tweak schema for replacements
Browse files Browse the repository at this point in the history
* fix: tweak schema for replacements

* chore: typo and formatting
  • Loading branch information
mshanemc authored Mar 10, 2023
1 parent 07a4440 commit 39a9937
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 115 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For most other editors, you can use the schemas by adding the `$schema` property
}
```

You can also use these schemas programatially. For example, Salesforce CLI uses these schema to do certain validation.
You can also use these schemas programatically. For example, Salesforce CLI uses these schema to do certain validation.

```javascript
const schemas = require('@salesforce/schemas');
Expand All @@ -33,6 +33,14 @@ const projectJsonSchema = require('@salesforce/schema/sfdx-project-schema.json']

Run the `features-update` and `settings-update` scripts on every major release and open a PR with the new changes against the `main` branch to keep the schema files up to date

## Generating Schema from TS files

the /src folder contains the TS type used to generate the [`replacements`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_string_replace.htm?q=replacements) project property.

You can define (or import and re-export) TS types and then use [this extension](https://marketplace.visualstudio.com/items?itemName=marcoq.vscode-typescript-to-json-schema). It adds a "Generate JSON Schema from type" action to your palette.

The results go into `/compiled`, which can be used to copy-paste into the project.

## Bugs and Feedback

To report issues or feedback with the schemas, open a bug on [GitHub](https://github.com/forcedotcom/schemas/issues).
266 changes: 266 additions & 0 deletions compiled/replacements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Replacements",
"definitions": {
"Replacements": {
"anyOf": [
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithFile": {
"type": "string"
},
"stringToReplace": {
"type": "string"
},
"filename": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["filename", "replaceWithFile", "stringToReplace"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithEnv": {
"type": "string"
},
"stringToReplace": {
"type": "string"
},
"filename": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["filename", "replaceWithEnv", "stringToReplace"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithFile": {
"type": "string"
},
"regexToReplace": {
"type": "string"
},
"filename": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["filename", "regexToReplace", "replaceWithFile"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithEnv": {
"type": "string"
},
"regexToReplace": {
"type": "string"
},
"filename": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["filename", "regexToReplace", "replaceWithEnv"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithFile": {
"type": "string"
},
"stringToReplace": {
"type": "string"
},
"glob": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["glob", "replaceWithFile", "stringToReplace"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithEnv": {
"type": "string"
},
"stringToReplace": {
"type": "string"
},
"glob": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["glob", "replaceWithEnv", "stringToReplace"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithFile": {
"type": "string"
},
"regexToReplace": {
"type": "string"
},
"glob": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["glob", "regexToReplace", "replaceWithFile"]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"replaceWithEnv": {
"type": "string"
},
"regexToReplace": {
"type": "string"
},
"glob": {
"type": "string"
},
"replaceWhenEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"env": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["env", "value"],
"additionalProperties": false
}
}
},
"required": ["glob", "regexToReplace", "replaceWithEnv"]
}
]
}
}
}
7 changes: 6 additions & 1 deletion examples/sfdx-project/replacements.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"stringToReplace": "replaceMe",
"replaceWithEnv": "THE_REPLACEMENT"
},
{
"filename": "force-app/main/default/classes/myClass.cls",
"stringToReplace": "replaceMe",
"replaceWithFile": "~/substitutions.txt"
},
{
"glob": "**/*.cls",
"regexToReplace": "\\d",
Expand All @@ -29,4 +34,4 @@
]
}
]
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
"devDependencies": {
"@commitlint/cli": "^7",
"@commitlint/config-conventional": "^7",
"@salesforce/dev-config": "^3.1.0",
"ajv": "^8.11.0",
"commitizen": "^3.0.5",
"cz-conventional-changelog": "^2.1.0",
"ajv": "^8.11.0",
"husky": "^3.0.2",
"jest": "^24.8.0",
"prettier": "^1.18.2",
Expand All @@ -52,4 +53,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
Loading

0 comments on commit 39a9937

Please sign in to comment.