Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary stuff from desktop build #911

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions development/builder.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const fs = require('fs');
const pathUtil = require('path');
const sizeOfImage = require('image-size');
const renderTemplate = require('./render-template');
const renderDocs = require('./render-docs');
const compatibilityAliases = require('./compatibility-aliases');
const parseMetadata = require('./parse-extension-metadata');
const featuredExtensionSlugs = require('../extensions/extensions.json');
Expand Down Expand Up @@ -135,6 +132,8 @@ class HomepageFile extends BuildFile {
}

read () {
const renderTemplate = require('./render-template');

const mostRecentExtensions = Object.entries(this.extensionFiles)
.sort((a, b) => b[1].getLastModified() - a[1].getLastModified())
.slice(0, 5)
Expand Down Expand Up @@ -205,6 +204,7 @@ class JSONMetadataFile extends BuildFile {

class ImageFile extends BuildFile {
validate () {
const sizeOfImage = require('image-size');
const contents = this.read();
const {width, height} = sizeOfImage(contents);
const aspectRatio = width / height;
Expand Down Expand Up @@ -269,6 +269,7 @@ class DocsFile extends BuildFile {
}

read () {
const renderDocs = require('./render-docs');
const markdown = super.read().toString('utf-8');
return renderDocs(markdown, this.extensionSlug);
}
Expand All @@ -279,10 +280,7 @@ class DocsFile extends BuildFile {
}

class Build {
constructor (mode) {
/** @type {Mode} */
this.mode = mode;

constructor () {
this.files = {};
}

Expand All @@ -302,10 +300,6 @@ class Build {
}

for (const [relativePath, file] of Object.entries(this.files)) {
if (this.mode === 'desktop' && relativePath.endsWith('.html')) {
continue;
}

const directoryName = pathUtil.dirname(relativePath);
fs.mkdirSync(pathUtil.join(root, directoryName), {
recursive: true
Expand Down Expand Up @@ -340,6 +334,19 @@ class Builder {
build () {
const build = new Build(this.mode);

/** @type {Record<string, ExtensionFile>} */
const extensionFiles = {};
for (const [filename, absolutePath] of recursiveReadDirectory(this.extensionsRoot)) {
if (!filename.endsWith('.js')) {
continue;
}
const extensionSlug = filename.split('.')[0];
const featured = featuredExtensionSlugs.includes(extensionSlug);
const file = new ExtensionFile(absolutePath, featured);
extensionFiles[extensionSlug] = file;
build.files[`/${filename}`] = file;
}

/** @type {Record<string, ImageFile>} */
const extensionImages = {};
for (const [filename, absolutePath] of recursiveReadDirectory(this.imagesRoot)) {
Expand All @@ -355,41 +362,31 @@ class Builder {
build.files[`/images/${filename}`] = new ImageFileClass(absolutePath);
}

for (const [filename, absolutePath] of recursiveReadDirectory(this.docsRoot)) {
if (!filename.endsWith('.md')) {
continue;
if (this.mode !== 'desktop') {
for (const [filename, absolutePath] of recursiveReadDirectory(this.websiteRoot)) {
build.files[`/${filename}`] = new BuildFile(absolutePath);
}
const extensionSlug = filename.split('.')[0];
build.files[`/${extensionSlug}.html`] = new DocsFile(absolutePath, extensionSlug);
}

const scratchblocksPath = pathUtil.join(__dirname, '../node_modules/scratchblocks/build/scratchblocks.min.js');
build.files['/docs-internal/scratchblocks.js'] = new BuildFile(scratchblocksPath);

/** @type {Record<string, ExtensionFile>} */
const extensionFiles = {};
for (const [filename, absolutePath] of recursiveReadDirectory(this.extensionsRoot)) {
if (!filename.endsWith('.js')) {
continue;
for (const [filename, absolutePath] of recursiveReadDirectory(this.docsRoot)) {
if (!filename.endsWith('.md')) {
continue;
}
const extensionSlug = filename.split('.')[0];
build.files[`/${extensionSlug}.html`] = new DocsFile(absolutePath, extensionSlug);
}
const extensionSlug = filename.split('.')[0];
const featured = featuredExtensionSlugs.includes(extensionSlug);
const file = new ExtensionFile(absolutePath, featured);
extensionFiles[extensionSlug] = file;
build.files[`/${filename}`] = file;
}

for (const [oldPath, newPath] of Object.entries(compatibilityAliases)) {
build.files[oldPath] = build.files[newPath];
}
const scratchblocksPath = pathUtil.join(__dirname, '../node_modules/scratchblocks/build/scratchblocks.min.js');
build.files['/docs-internal/scratchblocks.js'] = new BuildFile(scratchblocksPath);

for (const [filename, absolutePath] of recursiveReadDirectory(this.websiteRoot)) {
build.files[`/${filename}`] = new BuildFile(absolutePath);
build.files['/index.html'] = new HomepageFile(extensionFiles, extensionImages, this.mode);
build.files['/sitemap.xml'] = new SitemapFile(build);
}

build.files['/index.html'] = new HomepageFile(extensionFiles, extensionImages, this.mode);
build.files['/generated-metadata/extensions-v0.json'] = new JSONMetadataFile(extensionFiles, extensionImages);
build.files['/sitemap.xml'] = new SitemapFile(build);

for (const [oldPath, newPath] of Object.entries(compatibilityAliases)) {
build.files[oldPath] = build.files[newPath];
}

return build;
}
Expand Down