Skip to content

Commit

Permalink
chore: set up README sync so that docs on the site are published to j…
Browse files Browse the repository at this point in the history
…s.electronforge.io and to npm w

Fixes #483
  • Loading branch information
MarshallOfSound committed May 3, 2018
1 parent ab64142 commit 513013e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ packages/.old
docs
doc
.vscode
packages/utils/types/index.d.ts
packages/utils/types/index.d.ts
packages/maker/**/README.md
packages/publisher/**/README.md
packages/plugin/**/README.md
!packages/**/base/README.md
!/README.md
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"docs": "bolt docs:generate && bolt docs:position",
"docs:generate": "bolt ws exec -- node_modules/.bin/typedoc --out doc --excludeExternals --ignoreCompilerErrors --mode file --excludePrivate --excludeProtected --hideGenerator",
"docs:position": "ts-node tools/position-docs.ts",
"docs:deploy": "bolt docs && ts-node tools/copy-now.ts && cd docs && now && now alias",
"docs:deploy": "node tools/sync-readmes.js && bolt docs && ts-node tools/copy-now.ts && cd docs && now && now alias",
"lint": "ts-node tools/link-ts.ts && bolt ws exec -- node_modules/.bin/tslint src/**/*.ts test/**/*.ts",
"test": "bolt ws run test"
},
Expand Down
3 changes: 3 additions & 0 deletions tools/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');
cwd: BASE_DIR,
});

console.info('Fetching README\'s');
await require('./sync-readmes')();

console.info('Publishing all packages');

const dirsToPublish = [];
Expand Down
56 changes: 56 additions & 0 deletions tools/sync-readmes.js
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;

0 comments on commit 513013e

Please sign in to comment.