Skip to content

Commit

Permalink
chore: revise make-docs.js so it can update the version shown on the …
Browse files Browse the repository at this point in the history
…coverpage
  • Loading branch information
crucialfelix committed Nov 27, 2019
1 parent 37e3361 commit 2c69e63
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
16 changes: 16 additions & 0 deletions docs/src/_coverpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

<!-- _coverpage.md -->

<!-- ![logo](_media/icon.svg) -->

# supercollider.js <small>{{version}}</small>

> The JavaScript client library for SuperCollider.
[GitHub](https://github.com/crucialfelix/supercolliderjs/)
[Docs](#supercolliderjs)

<!-- background color -->

![color](#202020)

57 changes: 38 additions & 19 deletions tasks/make-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fsp = fs.promises;

const root = path.resolve(path.join(__dirname, ".."));
const packagesRoot = path.join(root, "packages");
const docsRoot = path.join(root, "docs");
// const docsRoot = path.join(root, "docs");
const repository = "https://github.com/crucialfelix/supercolliderjs";

const typedocRoot = "https://crucialfelix.github.io/supercolliderjs";
Expand Down Expand Up @@ -37,44 +37,63 @@ const typedocLink = text => {
return body;
};

async function main() {
async function make(srcPath, destPath, data) {
const tplPath = path.join(root, srcPath);
if (!(await fileExists(tplPath))) {
await fsp.mkdir(path.dirname(tplPath), { recursive: true });
await fsp.writeFile(tplPath, "");
}
const tpl = (await fsp.readFile(tplPath)).toString();
const content = Mustache.render(tpl, data, partials);
await fsp.writeFile(path.join(root, destPath), content);
}

async function main(version) {
const packages = (await fsp.readdir(packagesRoot)).filter(name => name.match(/^[a-z\-]+$/));

const pkg = JSON.parse(await fsp.readFile(path.join(root, "package.json")));

const rootData = {
name: pkg.name,
short: pkg.name.replace("@supercollider/", ""),
description: pkg.description,
version: version || pkg.version,
homepage: pkg.hompage,
repository,
typedocRoot: typedocRoot,
example: () => example,
typedocLink: () => typedocLink,
};

// _coverpage
await make("docs/src/_coverpage.md", "docs/_coverpage.md", rootData);

for (const pkgdir of packages) {
const pkg = JSON.parse(await fsp.readFile(path.join(packagesRoot, pkgdir, "package.json")));

const tplPath = path.join(root, "docs/src/packages", pkgdir, "README.md");
if (!(await fileExists(tplPath))) {
await fsp.mkdir(path.dirname(tplPath), { recursive: true });
await fsp.writeFile(tplPath, "");
}
const tpl = (await fsp.readFile(tplPath)).toString();

const data = {
...rootData,
name: pkg.name,
short: pkg.name.replace("@supercollider/", ""),
description: pkg.description,
version: pkg.version,
homepage: pkg.hompage,
repository,
typedocRoot: typedocRoot,
example: () => example,
typedocLink: () => typedocLink,
};

const content = Mustache.render(tpl, data, partials);
const tplPath = path.join("docs/src/packages", pkgdir, "README.md");

// Write to packages for publishing to npm
await fsp.writeFile(path.join(packagesRoot, pkgdir, "README.md"), content);
await make(tplPath, path.join("packages", pkgdir, "README.md"), data);
// Write it to docs
await fsp.writeFile(path.join(docsRoot, "packages", pkgdir, "README.md"), content);
await make(tplPath, path.join("docs/packages", pkgdir, "README.md"), data);

if (pkgdir === "supercolliderjs") {
// Is also the main page in docs
await fsp.writeFile(path.join(docsRoot, "README.md"), content);
await make(tplPath, path.join("docs", "README.md"), data);
// and main page on github
await fsp.writeFile(path.join(root, "README.md"), content);
await make(tplPath, "README.md", data);
}
}
}

main().catch(console.error);
main(process.argv[2]).catch(console.error);

0 comments on commit 2c69e63

Please sign in to comment.