Skip to content
Permalink
Browse files

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
MarshallOfSound committed May 3, 2018
1 parent ab64142 commit 513013e61cda643c67ac4ab7d6afa36f9b14fa7a
Showing with 66 additions and 2 deletions.
  1. +6 −1 .gitignore
  2. +1 −1 package.json
  3. +3 −0 tools/publish.js
  4. +56 −0 tools/sync-readmes.js
@@ -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
@@ -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"
},
@@ -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 = [];
@@ -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.
You can’t perform that action at this time.