Skip to content

Commit

Permalink
feat(ttbe): Toggl Track browser extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Phenome committed Dec 2, 2021
1 parent 3280cec commit f78590c
Show file tree
Hide file tree
Showing 261 changed files with 697 additions and 53,375 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
74 changes: 0 additions & 74 deletions .eslintrc.js

This file was deleted.

151 changes: 0 additions & 151 deletions .github/CONTRIBUTING.md

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/origins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: origins
on: [push]
jobs:
update-origins:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- run: node .github/workflows/update-origins.js
- uses: EndBug/add-and-commit@v5
with:
add: "src/origins.js"
message: 'Update origins.js'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71 changes: 71 additions & 0 deletions .github/workflows/update-origins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { readFileSync, writeFileSync } = require("fs");
const path = require("path");
const { exec } = require("child_process");

const getFileInfo = (fileContents) => {
const header = (fileContents.match(/^\/\*\*\n(.+?)\*\//s) || [])[1];
if (!header) return null;
const fileInfo = [...header.matchAll(/@(\w+)\s+(.+?)\s*\r?\n/gs)].reduce(
(obj, [_, prop, value]) => ({ ...obj, [prop]: value }),
{}
);
return fileInfo;
};

const getOrigins = () => {
const contents = readFileSync("./src/origins.js").toString().slice(17, -4);
const origins = [
...contents.matchAll(/'?([a-zA-Z0-9.-]+?)'?: {\n(.+?)},?/gs),
].map(([_, urlAlias, props]) => ({ urlAlias, props }));
return origins.reduce((obj, { urlAlias, props }) => {
obj[urlAlias] = [...props.matchAll(/(\w+): '?(.*?)'?,?\n/gs)].reduce(
(_obj, [_, prop, value]) => ({ ..._obj, [prop]: value }),
{}
);
return obj;
}, {});
};

const formatOriginsFile = (origins) =>
`export default {\n${Object.entries(origins)
.sort((a, b) =>
a[1].name.toLowerCase() < b[1].name.toLowerCase() ? -1 : 1
)
.map(
([urlAlias, props]) =>
` '${urlAlias}': {\n${Object.entries(props)
.map(([prop, value]) => ` ${prop}: '${value}'`)
.join(",\n")}\n }`
)
.join(",\n")}\n};\n`;

exec(`git diff --name-only HEAD^ HEAD`, (_, out) => {
const files = out.split(/[\r\n]+/).filter((name) => !!name && name.startsWith('src/content/'));
if (files.length === 0) {
console.log(`::No files to process`);
process.exit(0);
}
const infos = files
.map((file) => ({
...getFileInfo(readFileSync(file).toString()),
file: path.basename(file),
}))
.filter((info) => info !== null);
if (infos.length === 0 || !infos[0].urlAlias) {
console.log(`All files ${files.join(', ')}`)
console.log(
`::error ::File ${files[0]} has a faulty header. Check CONTRIBUTING.md`
);
process.exit(1);
}
const origins = getOrigins();
const newOrigins = infos.reduce(
(_origins, { name, urlAlias, urlRegex, file }) => ({
...origins,
[urlAlias]: { url: urlRegex, name, file },
}),
origins
);

writeFileSync("./src/origins.js", formatOriginsFile(newOrigins));
});
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
.*
!.editorconfig
!.eslintrc.js
!.gitignore
!.npmrc
!.travis.yml

dist/
node_modules/
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

Loading

1 comment on commit f78590c

@salomvary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those wondering what happened here, the extensions got de-opensourced:

https://toggl.com/blog/purposeful-open-source

#2175

Please sign in to comment.