Skip to content

Commit

Permalink
Add new hats and preprocessing script
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Sep 17, 2021
1 parent 57d4ac1 commit 5cea580
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 32 deletions.
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,33 @@
### Installation

```sh
yarn install
```

### Running tests

```sh
yarn run test
```

### Adding tests

See [test-case-recorder.md](docs/test-case-recorder.md).

### Adding a new programming language

See [docs](docs/adding-a-new-language.md).

### Adding syntactic scope types to an existing language

See [parse-tree-patterns.md](docs/parse-tree-patterns.md).

### Changing SVGs

You'll probably want to run the following to make sure the SVGs have everything they need:

```sh
yarn run compile && node ./out/scripts/preprocessSvgHats.js
```

This script will add dummy width, height and fill attributes as necessary to appease the regex in `Decorations.ts`
24 changes: 1 addition & 23 deletions README.md
Expand Up @@ -57,29 +57,7 @@ See [CHANGELOG.md](CHANGELOG.md).

## Contributing

### Installation

```sh
yarn install
```

### Running tests

```sh
yarn run test
```

### Adding tests

See [test-case-recorder.md](docs/test-case-recorder.md).

### Adding a new programming language

See [docs](docs/adding-a-new-language.md).

### Adding syntactic scope types to an existing language

See [parse-tree-patterns.md](docs/parse-tree-patterns.md).
See [CONTRIBUTING.md](CONTRIBUTING.md).

---

Expand Down
2 changes: 1 addition & 1 deletion images/hats/chevron.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/curve.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/default.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/eye.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/fourPointStar.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/frame.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/hole.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/hats/play.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/hats/threePointStar.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -346,6 +346,7 @@
"@typescript-eslint/parser": "^4.9.0",
"esbuild": "^0.11.12",
"eslint": "^7.15.0",
"fast-xml-parser": "^3.20.0",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"mocha": "^8.1.3",
Expand All @@ -358,4 +359,4 @@
"immutability-helper": "^3.1.1",
"lodash": "^4.17.21"
}
}
}
32 changes: 32 additions & 0 deletions src/scripts/preprocessSvgHats.ts
@@ -0,0 +1,32 @@
import * as parser from "fast-xml-parser";
import { promises as fsp, read, readdirSync } from "fs";
import * as path from "path";

async function main() {
const directory = path.join(__dirname, "../../images/hats");

const dumper = new parser.j2xParser({
ignoreAttributes: false,
supressEmptyNode: true,
});

readdirSync(directory, { withFileTypes: true }).forEach(async (dirent) => {
const filePath = path.join(directory, dirent.name);
const rawSvg = await fsp.readFile(filePath, { encoding: "utf8" });
const svgJson = parser.parse(rawSvg, { ignoreAttributes: false });

svgJson.svg["@_width"] = "0.7em";
svgJson.svg["@_height"] = "0.7em";

if (
rawSvg.match(/fill="[^"]+"/) == null &&
rawSvg.match(/fill:[^;]+;/) == null
) {
svgJson.svg["@_fill"] = "#123456";
}

await fsp.writeFile(filePath, dumper.parse(svgJson));
});
}

main();
12 changes: 12 additions & 0 deletions yarn.lock
Expand Up @@ -686,6 +686,13 @@ fast-levenshtein@^2.0.6:
resolved "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=

fast-xml-parser@^3.20.0:
version "3.20.0"
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.20.0.tgz#b9ce9ddbc44d2cb7e38f846c5929c667bbf0936d"
integrity sha512-cMQwDJYVDjMPU56DviszewgMKuNzuf4NQSBuDf9RgZ6FKm5QEMxW05Za8lvnuL6moxoeZVUWBlL733WmovvV6g==
dependencies:
strnum "^1.0.3"

fastq@^1.6.0:
version "1.10.1"
resolved "https://registry.npmjs.org/fastq/-/fastq-1.10.1.tgz"
Expand Down Expand Up @@ -1425,6 +1432,11 @@ strip-json-comments@3.1.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1.
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

strnum@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.3.tgz#bbc438bcb35fbbfc9c1e82f73097665b6ec6959e"
integrity sha512-GVoRjsqAYZkAH16GDzfTuafuwKxzKdaaCQyLaWf37gOP1e2PPbAKWoME1OmO+c4RCKMfNrrPRDLFCNBFU45N/A==

supports-color@8.1.1:
version "8.1.1"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz"
Expand Down

0 comments on commit 5cea580

Please sign in to comment.