-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: set up README sync so that docs on the site are published to j…
…s.electronforge.io and to npm w Fixes #483
- Loading branch information
1 parent
ab64142
commit 513013e
Showing
4 changed files
with
66 additions
and
2 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 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 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 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,56 @@ | ||
const fetch = require('node-fetch'); | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
const workspaceMappings = { | ||
maker: { | ||
wix: 'wix-msi', | ||
squirrel: 'squirrel.windows', | ||
snap: 'snapcraft', | ||
}, | ||
publisher: {}, | ||
plugin: {}, | ||
}; | ||
|
||
const BASE_DIR = path.resolve(__dirname, '..'); | ||
const DOCS_BASE = 'https://raw.githubusercontent.com/MarshallOfSound/electron-forge-docs/v6'; | ||
|
||
const sanitize = (gb) => { | ||
return gb | ||
.replace('{% code-tabs %}', '') | ||
.replace('{% endcode-tabs %}', '') | ||
.replace(/{% code-tabs-item title=".+?" %}/g, '') | ||
.replace('{% endcode-tabs-item %}', '') | ||
.replace('{% endhint %}', '</b>') | ||
.replace(/{% hint style="(.+?)" %}\n/g, (_, style) => { | ||
const styleMap = { | ||
warning: '⚠️', | ||
info: 'ℹ️', | ||
danger: '🚨', | ||
}; | ||
return `${styleMap[style] || 'ℹ️'} <b>`; | ||
}); | ||
}; | ||
|
||
const sync = async () => { | ||
for (const workspace of Object.keys(workspaceMappings)) { | ||
const workspaceDir = path.resolve(BASE_DIR, 'packages', workspace); | ||
|
||
for (const packageName of await fs.readdir(path.resolve(workspaceDir))) { | ||
const packageKey = workspaceMappings[workspace][packageName] || packageName; | ||
|
||
const r = await fetch(`${DOCS_BASE}/${workspace}s/${packageKey}.md`); | ||
if (r.status !== 200) continue; | ||
|
||
console.info('Writing README for:', `${path.basename(workspaceDir)}/${packageKey}`); | ||
const md = sanitize(await r.text()); | ||
await fs.writeFile(path.resolve(workspaceDir, packageName, 'README.md'), md); | ||
} | ||
} | ||
}; | ||
|
||
if (process.mainModule === module) { | ||
sync().catch(console.error); | ||
} | ||
|
||
module.exports = sync; |