generated from brckd/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Bar from "./widget/Bar"; | ||
// @ts-ignore | ||
import style from "./style.scss"; | ||
|
||
App.addIcons(`${App.configDir}/assets`); | ||
App.config({ | ||
windows: [Bar(0)], | ||
style: `${App.configDir}/style.css`, | ||
}); | ||
App.applyCss(style); | ||
App.config({ windows: [Bar(0)] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
{ | ||
"name": "@bricked/ags-dots", | ||
"module": "src/index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/bun": "latest" | ||
"@types/bun": "latest", | ||
"sass": "^1.72.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"scripts": { | ||
"postinstall": "rm types; ln -s $HOME/.local/share/com.github.Aylur.ags/types types", | ||
"build": "bun build:bun & bun build:sass", | ||
"build:bun": "bun build ./config.ts --outfile ./config.js --external \"resource://*\" --external \"gi://*\"", | ||
"build:sass": "sass style.scss:style.css", | ||
"watch": "bun watch:bun & bun watch:sass", | ||
"watch:bun": "bun build:bun --watch", | ||
"watch:sass": "bun build:sass --watch", | ||
"start": "ags --config ./config.js" | ||
} | ||
"comp": "bun scripts/build.ts", | ||
"watch": "bun scripts/watch.ts", | ||
"start": "bun scripts/start.ts", | ||
"dev": "bun scripts/dev.ts" | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { BuildOutput, BuildConfig as BunBuildConfig } from "bun"; | ||
import sassPlugin from "./sassPlugin"; | ||
import { benchmark } from "./log"; | ||
|
||
export interface BuildConfig extends Partial<BunBuildConfig> {} | ||
|
||
export function build(config?: BuildConfig) { | ||
return Bun.build({ | ||
entrypoints: ["./config.ts"], | ||
outdir: ".", | ||
external: ["resource://*", "gi://*"], | ||
plugins: [sassPlugin], | ||
...config, | ||
}); | ||
} | ||
|
||
export async function logOutput(output: BuildOutput) { | ||
if (output.logs.length) { | ||
console.log(output.logs.join("\n")); | ||
} | ||
} | ||
|
||
if (import.meta.main) { | ||
const output = await benchmark(build(), "build"); | ||
logOutput(output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { build, logOutput } from "./build"; | ||
import { watch } from "./watch"; | ||
import { start, restart } from "./start"; | ||
import { benchmark } from "./log"; | ||
|
||
if (import.meta.main) { | ||
const output = await benchmark(build(), "build"); | ||
logOutput(output); | ||
start(); | ||
for await (const { filename } of watch(`${import.meta.dir}/..`)) { | ||
const output = await benchmark(build(), "build", filename!); | ||
logOutput(output); | ||
restart(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function format(name: string, ...reason: string[]) { | ||
return [`\x1b[32m${name}\x1b[0m`, ...reason].join(" "); | ||
} | ||
|
||
export function log(name: string, ...reason: string[]) { | ||
console.log(format(name, ...reason)); | ||
} | ||
|
||
export async function benchmark( | ||
process: Promise<any>, | ||
name: string, | ||
...reason: string[] | ||
) { | ||
const message = format(name, ...reason); | ||
console.time(message); | ||
const result = await process; | ||
console.timeEnd(message); | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type BunPlugin } from "bun"; | ||
|
||
export const sassPlugin: BunPlugin = { | ||
name: "Sass", | ||
async setup(build) { | ||
const { compile } = await import("sass"); | ||
|
||
build.onLoad({ filter: /\.(scss|sass)$/ }, (args) => { | ||
const result = compile(args.path); | ||
return { | ||
contents: result.css, | ||
loader: "text", | ||
}; | ||
}); | ||
}, | ||
}; | ||
|
||
export default sassPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { $ } from "bun"; | ||
import { log } from "./log"; | ||
|
||
export async function start(configPath = "./config.js") { | ||
return await $`ags --config ${configPath} 2> /dev/null`; | ||
} | ||
|
||
export async function stop() { | ||
return await $`ags --quit`; | ||
} | ||
|
||
export async function restart(configPath = "./config.js") { | ||
await stop(); | ||
return await start(configPath); | ||
} | ||
|
||
if (import.meta.main) { | ||
log("start", "config.js"); | ||
await start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { watch as fsWatch } from "fs/promises"; | ||
import { build, logOutput } from "./build"; | ||
import { benchmark } from "./log"; | ||
|
||
interface WatchConfig { | ||
filename?: string | RegExp; | ||
} | ||
|
||
export async function* watch(dirname: string, config?: WatchConfig) { | ||
config ??= {}; | ||
config.filename ??= | ||
/^(config\.ts|style\.scss|(widget|service|style|assets)\/.*\.\w+)$/; | ||
|
||
const watcher = fsWatch(dirname, { recursive: true }); | ||
for await (const event of watcher) { | ||
const { filename } = event; | ||
if (typeof filename !== "string") continue; | ||
if (/\/\d+$/.test(filename)) continue; | ||
if (!filename.match(config.filename)) continue; | ||
yield event; | ||
} | ||
} | ||
|
||
if (import.meta.main) { | ||
const output = await benchmark(build(), "build"); | ||
logOutput(output); | ||
for await (const { filename } of watch(`${import.meta.dir}/..`)) { | ||
const output = await benchmark(build(), "build", filename!); | ||
logOutput(output); | ||
} | ||
} |