-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ttbe): Toggl Track browser extension
- Loading branch information
Showing
261 changed files
with
697 additions
and
53,375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
.* | ||
!.editorconfig | ||
!.eslintrc.js | ||
!.gitignore | ||
!.npmrc | ||
!.travis.yml | ||
|
||
dist/ | ||
node_modules/ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
f78590c
There was a problem hiding this comment.
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