Skip to content

Commit

Permalink
Relocate our existing web code to subdirectories
Browse files Browse the repository at this point in the history
 - Move the frontend code into src/frontend
 - Move our custom element SSR system into src/htmlTransform.

This is mostly in prep for merging in copy-cat's core, as that's a whole
bunch of extra code.
  • Loading branch information
SquidDev committed Sep 28, 2023
1 parent e6125bc commit 663eecf
Show file tree
Hide file tree
Showing 73 changed files with 51 additions and 30 deletions.
14 changes: 7 additions & 7 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Files:
projects/common/src/testMod/resources/data/cctest/structures/*
projects/fabric/src/generated/*
projects/forge/src/generated/*
projects/web/src/export/index.json
projects/web/src/export/items/minecraft/*
projects/web/src/htmlTransform/export/index.json
projects/web/src/htmlTransform/export/items/minecraft/*
Comment: Generated/data files are CC0.
Copyright: The CC: Tweaked Developers
License: CC0-1.0
Expand All @@ -37,10 +37,10 @@ Files:
projects/fabric/src/testMod/resources/computercraft-gametest.fabric.mixins.json
projects/fabric/src/testMod/resources/fabric.mod.json
projects/forge/src/client/resources/computercraft-client.forge.mixins.json
projects/web/src/mount/.settings
projects/web/src/mount/example.nfp
projects/web/src/mount/example.nft
projects/web/src/mount/expr_template.lua
projects/web/src/frontend/mount/.settings
projects/web/src/frontend/mount/example.nfp
projects/web/src/frontend/mount/example.nft
projects/web/src/frontend/mount/expr_template.lua
projects/web/tsconfig.json
Comment: Several assets where it's inconvenient to create a .license file.
Copyright: The CC: Tweaked Developers
Expand All @@ -56,7 +56,7 @@ Files:
projects/core/src/main/resources/data/computercraft/lua/rom/autorun/.ignoreme
projects/core/src/main/resources/data/computercraft/lua/rom/help/*
projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/levels/*
projects/web/src/export/items/computercraft/*
projects/web/src/htmlTransform/export/items/computercraft/*
Comment: Bulk-license original assets as CCPL.
Copyright: 2011 Daniel Ratcliffe
License: LicenseRef-CCPL
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/cc/tweaked/gradle/ExecTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

package cc.tweaked.gradle

import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.AbstractExecTask
import org.gradle.api.tasks.OutputDirectory
import java.io.File

abstract class ExecToDir : AbstractExecTask<ExecToDir>(ExecToDir::class.java) {
@get:OutputDirectory
abstract val output: Property<File>
abstract val output: DirectoryProperty
}
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cc.tweaked.gradle

import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.FileSystemLocationProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.JavaExec
Expand Down Expand Up @@ -124,3 +125,6 @@ class CloseScope : AutoCloseable {

/** Proxy method to avoid overload ambiguity. */
fun <T> Property<T>.setProvider(provider: Provider<out T>) = set(provider)

/** Short-cut method to get the absolute path of a [FileSystemLocationProperty]. */
fun FileSystemLocationProperty<*>.getAbsolutePath(): String = get().asFile.absolutePath
6 changes: 3 additions & 3 deletions illuaminate.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/projects/core/src/main/resources/data/computercraft/lua/bios.lua
/projects/core/src/main/resources/data/computercraft/lua/rom/
/projects/core/src/test/resources/test-rom
/projects/web/src/mount)
/projects/web/src/frontend/mount)

(doc
; Also defined in projects/web/build.gradle.kts
Expand All @@ -23,7 +23,7 @@
(url https://tweaked.cc/)
(source-link https://github.com/cc-tweaked/CC-Tweaked/blob/${commit}/${path}#L${line})

(styles /projects/web/src/styles.css)
(styles /projects/web/src/frontend/styles.css)
(scripts /projects/web/build/rollup/index.js)
(head doc/head.html))

Expand Down Expand Up @@ -115,4 +115,4 @@
:max sleep write
cct_test describe expect howlci fail it pending stub before_each)))

(at /projects/web/src/mount/expr_template.lua (lint (globals :max __expr__)))
(at /projects/web/src/frontend/mount/expr_template.lua (lint (globals :max __expr__)))
38 changes: 24 additions & 14 deletions projects/web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MPL-2.0

import cc.tweaked.gradle.getAbsolutePath

plugins {
`lifecycle-base`
id("cc-tweaked.node")
Expand All @@ -21,13 +23,13 @@ val rollup by tasks.registering(cc.tweaked.gradle.NpxExecToDir::class) {
description = "Bundles JS into rollup"

// Sources
inputs.files(fileTree("src")).withPropertyName("sources")
inputs.files(fileTree("src/frontend")).withPropertyName("sources")
// Config files
inputs.file("tsconfig.json").withPropertyName("Typescript config")
inputs.file("rollup.config.js").withPropertyName("Rollup config")

// Output directory. Also defined in illuaminate.sexp and rollup.config.js
output.set(buildDir.resolve("rollup"))
output.set(layout.buildDirectory.dir("rollup"))

args = listOf("rollup", "--config", "rollup.config.js")
}
Expand All @@ -44,38 +46,46 @@ val illuaminateDocs by tasks.registering(cc.tweaked.gradle.IlluaminateExecToDir:
inputs.files(project(":forge").tasks.named("luaJavadoc"))
// Additional assets
inputs.files(rollup)
inputs.file("src/styles.css").withPropertyName("styles")
inputs.file("src/frontend/styles.css").withPropertyName("styles")

// Output directory. Also defined in illuaminate.sexp and transform.tsx
output.set(buildDir.resolve("illuaminate"))
// Output directory. Also defined in illuaminate.sexp.
output.set(layout.buildDirectory.dir("illuaminate"))

args = listOf("doc-gen")
workingDir = rootProject.projectDir
}

val jsxDocs by tasks.registering(cc.tweaked.gradle.NpxExecToDir::class) {
val htmlTransform by tasks.registering(cc.tweaked.gradle.NpxExecToDir::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Post-processes documentation to statically render some dynamic content."

val sources = fileTree("src/htmlTransform")

// Config files
inputs.file("tsconfig.json").withPropertyName("Typescript config")
// Sources
inputs.files(fileTree("src")).withPropertyName("sources")
inputs.file(file("src/export/index.json")).withPropertyName("export")
inputs.files(sources).withPropertyName("sources")
inputs.files(illuaminateDocs)

// Output directory. Also defined in src/transform.tsx
output.set(buildDir.resolve("jsxDocs"))
// Output directory.
output.set(layout.buildDirectory.dir(name))

args = listOf("tsx", "src/transform.tsx")
argumentProviders.add {
listOf(
"tsx", sources.dir.resolve("index.tsx").absolutePath,
illuaminateDocs.get().output.getAbsolutePath(),
sources.dir.resolve("export/index.json").absolutePath,
output.getAbsolutePath(),
)
}
}

val docWebsite by tasks.registering(Copy::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assemble docs and assets together into the documentation website."
duplicatesStrategy = DuplicatesStrategy.FAIL

from(jsxDocs)
from(htmlTransform)

// Pick up assets from the /docs folder
from(rootProject.file("doc")) {
Expand All @@ -87,9 +97,9 @@ val docWebsite by tasks.registering(Copy::class) {
// Grab illuaminate's assets. HTML files are provided by jsxDocs
from(illuaminateDocs) { exclude("**/*.html") }
// And item/block images from the data export
from(file("src/export/items")) { into("images/items") }
from(file("src/htmlTransform/export/items")) { into("images/items") }

into(buildDir.resolve("site"))
into(layout.buildDirectory.dir("site"))
}

tasks.assemble { dependsOn(docWebsite) }
2 changes: 1 addition & 1 deletion projects/web/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import url from "@rollup/plugin-url";

const input = "src";
const input = "src/frontend";
const requirejs = readFileSync("../../node_modules/requirejs/require.js");

/** @type import("rollup").RollupOptions */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import { noChildren } from "./components/support";
import { WithExport, type DataExport } from "./components/WithExport";

(async () => {
const base = "build/illuaminate";
if (process.argv.length !== 5) {
console.error("npx tsx ./index.tsx SOURCE EXPORT_JSON OUTPUT");
console.error(`Received ${process.argv.length - 1} arguments, expected 4`);
process.exit(1);
}

const [_node, _file, sourceDir, dataFile, outputDir] = process.argv;

const reactOptions: ReactOptions = {
...(runtime as ReactOptions),
Expand All @@ -46,14 +52,14 @@ import { WithExport, type DataExport } from "./components/WithExport";
.use(rehypeHighlight as unknown as Plugin<[HighlightOptions], import("hast").Root>, { prefix: "" })
.use(rehypeReact, reactOptions);

const dataExport = JSON.parse(await fs.readFile("src/export/index.json", "utf-8")) as DataExport;
const dataExport = JSON.parse(await fs.readFile(dataFile, "utf-8")) as DataExport;

for (const file of await glob(base + "/**/*.html")) {
for (const file of await glob(sourceDir + "/**/*.html")) {
const contents = await fs.readFile(file, "utf-8");

const { result } = await processor.process(contents);

const outputPath = path.resolve("build/jsxDocs", path.relative(base, file));
const outputPath = path.resolve(outputDir, path.relative(sourceDir, file));
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, "<!doctype HTML>" + renderToStaticMarkup(<WithExport data={dataExport}>{result}</WithExport>));
}
Expand Down

0 comments on commit 663eecf

Please sign in to comment.