Skip to content

Commit

Permalink
build: allow building from local electron/electron
Browse files Browse the repository at this point in the history
This PR allows developers to pass a parameter to indicate where in the
file system the `prebuild` script should look for the documentation. It
assumes it is a clone of `electron/electron` so the content should be
under a `/docs` folder. E.g.:

```console
yarn prebuild ../electron
```

In the future there might be a `watch` option enabled by default. This
is the MVP for #4.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix #4
  • Loading branch information
molant committed Apr 26, 2021
1 parent 5b9da1e commit 3d80f47
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 24 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Website
# electronjs.org-new

This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator.
This repository contains the code for the new electronsjs.org website. It is built using
[Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator.

## Installation

Expand All @@ -10,24 +11,43 @@ yarn install

## Local Development

If you want to use the contents from [`electron/electron`](https://github.com/electron/electron)
run the following:

```console
yarn prebuid
yarn start
```

This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
If you want the website to pick your local documentation, run:

## Build
```console
yarn prebuild ../relative/path/to/local/electron/repo
yarn start
```

For example, if you have the following structure:

```
└── projects
├─ electron
├─ electronjs.org-new
├─ ...
```

and assuming your prompt is in `/projects/electronjs.org-new/` you will have to run:

```console
yarn build
yarn prebuild ../electron
yarn start
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.
`yarn start` starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.

## Deployment
## Build

```console
GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
yarn build
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
This command generates static content into the `build` directory and can be served using any static contents hosting service.
38 changes: 27 additions & 11 deletions scripts/pre-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,47 @@
const path = require('path');
const del = require('del');

const { download } = require('./tasks/download-docs');
const { copy, download } = require('./tasks/download-docs');
const { addFrontmatter } = require('./tasks/add-frontmatter');
const { createSidebar } = require('./tasks/create-sidebar');
const { fixContent } = require('./tasks/md-fixers');
const { existsSync, fstat } = require('fs');

const DOCS_FOLDER = 'docs';
const BLOG_FOLDER = 'blog';
// TODO: Figure out the latest release
const VERSION = '12-x-y';

const start = async () => {
/**
*
* @param {string} localElectron
*/
const start = async (localElectron) => {
console.log(`Deleting previous content`);
await del(DOCS_FOLDER);
// TODO: Uncomment once we have the blog up and running
// await del(BLOG_FOLDER);

console.log(`Downloading docs for "v${VERSION}"`);
await download({
target: VERSION,
repository: 'electron',
destination: DOCS_FOLDER,
downloadMatch: 'docs',
});
if (!localElectron) {
console.log(`Downloading docs for "v${VERSION}"`);
await download({
target: VERSION,
repository: 'electron',
destination: DOCS_FOLDER,
downloadMatch: 'docs',
});
} else if (existsSync(localElectron)) {
await copy({
target: localElectron,
destination: DOCS_FOLDER,
downloadMatch: 'docs',
});
} else {
console.error(`Path ${localElectron} does not exist`);
return process.exit(-1);
}

// TODO: Uncomment once we have the blog up and running
// TODO: Uncoment once we have the blog enabled
// console.log(`Downloading posts`);
// await download({
// target: 'master',
Expand All @@ -51,4 +67,4 @@ const start = async () => {
await createSidebar(DOCS_FOLDER, path.join(process.cwd(), 'sidebars.js'));
};

start();
start(process.argv[2]);
24 changes: 20 additions & 4 deletions scripts/tasks/download-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const path = require('path');
const makeDir = require('make-dir');
const tar = require('tar-stream');
const got = require('got');
const globby = require('globby');

const pathRewrites = require('./docs-reorg.json');
const fixedFolders = ['api', 'images', 'fiddles'];

/**
* @typedef DownloadOptions
* @type {object}
* @property {string} repository - The repository in the electron org to download the contents from
* @property {string} [repository] - The repository in the electron org to download the contents from
* @property {string} destination - The destination absolute path.
* @property {string} target - The branch, commit, version. (e.g. `v1.0.0`, `master`)
* @property {string} downloadMatch - The math to use to filter the downloaded contents
Expand Down Expand Up @@ -154,9 +155,24 @@ const download = async (userOptions) => {
* as needed.
* @param {DownloadOptions} userOptions
*/
const copy = async (userOptions) => {
// Load contents
// Save contents
const copy = async ({ target, destination, downloadMatch = '.' }) => {
const filesPaths = await globby(`${downloadMatch}/**/*`, {
cwd: target,
});

const contents = [];

for (const filePath of filesPaths) {
const content = {
filename: filePath.replace(`${downloadMatch}/`, ''),
content: await fs.readFile(path.join(target, filePath)),
slug: path.basename(filePath, '.md'),
};

contents.push(content);
}

await saveContents(contents, destination);
};

module.exports = {
Expand Down

0 comments on commit 3d80f47

Please sign in to comment.