Skip to content

Commit

Permalink
feat: init www
Browse files Browse the repository at this point in the history
  • Loading branch information
binhtran432k committed Jun 17, 2024
1 parent ebd7373 commit dc8befa
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
root = true

[*.{js,ts}]
[*.{js,ts,css,html}]
indent_size = 2
indent_style = space
175 changes: 175 additions & 0 deletions packages/www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions packages/www/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# story-mapping-www

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.1.9. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
20 changes: 20 additions & 0 deletions packages/www/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "story-mapping-generator-www",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"dev": "bun scripts/xtask.ts",
"build:ts": "bun build --watch index.ts --outdir './dist'",
"build:public": "bun scripts/build.public.ts"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"vanjs-core": "^1.5.0"
}
}
15 changes: 15 additions & 0 deletions packages/www/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.5.0.nomodule.min.js"></script>
<title>Story Mapping Web</title>
</head>
<body>
<script type="module">
import main from "./pages/index.js";
main();
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions packages/www/public/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Reset css for cross-platform and easier edit */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
33 changes: 33 additions & 0 deletions packages/www/scripts/build.public.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { watch, readdir } from "fs";
import { join } from "path";

const OUTDIR = "./dist";
const DIR = join(import.meta.dir, "..");

readdir(DIR, { recursive: true }, (_err, files) => {
for (const filename of files) {
typeof filename == "string" && watchFilename(filename);
}
});

const watcher = watch(DIR, { recursive: true }, async (_event, filename) => {
filename && watchFilename(filename);
});

process.on("SIGINT", () => {
// close watcher when Ctrl-C is pressed
console.log("Closing watcher...");
watcher.close();
process.exit(0);
});

function watchFilename(filename: string) {
if (filename.match(/^public[\\/]/)) {
copyFile(filename, filename.replace(/^public/, OUTDIR));
}
}

function copyFile(path: string, outpath: string) {
const file = Bun.file(path);
Bun.write(outpath, file);
}
39 changes: 39 additions & 0 deletions packages/www/scripts/xtask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
interface BuildOption {
minify?: boolean;
watch?: boolean;
noBundle?: boolean;
splitting?: boolean;
outdir?: string; // output directory
root?: string; // project root
entrypoints: string[];
}

async function build(opts: BuildOption) {
const buildTypescriptCmd = [
"bun",
"build",
opts.entrypoints.join(" "),
opts.outdir && `--outdir ${opts.outdir}`,
opts.watch && "--watch",
opts.noBundle && "--no-bundle",
opts.splitting && "--splitting",
opts.minify && "--minify",
opts.root && `--root ${opts.root}`,
]
.filter(Boolean)
.join(" ");

const buildPublicCmd = "bun scripts/build.public.ts";

// HACK: Fake how tempalte literal work
return await Bun.$({
raw: [[buildTypescriptCmd, buildPublicCmd].join(" | ")],
} as unknown as TemplateStringsArray);
}

await build({
entrypoints: ["index.ts"].map((page) => `src/pages/${page}`),
outdir: "./dist",
root: "./src",
watch: true,
});
7 changes: 7 additions & 0 deletions packages/www/src/components/Hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { div } = van.tags;

const Hello = () => {
return div("Hello World, My name is Binh");
};

export default Hello;
5 changes: 5 additions & 0 deletions packages/www/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Van } from "vanjs-core";

declare global {
const van: Van;
}
5 changes: 5 additions & 0 deletions packages/www/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Hello from "../components/Hello";

export default function main() {
van.add(document.body, Hello());
}
28 changes: 28 additions & 0 deletions packages/www/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
},
"include": ["scripts/*.ts", "src/**/*.ts"]
}

0 comments on commit dc8befa

Please sign in to comment.