From aa83fea68c6c8bb07d908767d8b1eae52882ebcf Mon Sep 17 00:00:00 2001 From: notV4l Date: Wed, 22 Nov 2023 17:07:40 +0100 Subject: [PATCH] create-dojo --- .github/workflows/release.yaml | 1 + package.json | 1 + packages/create-dojo/.gitignore | 172 ++++++++++++++++++++++++++++ packages/create-dojo/README.md | 15 +++ packages/create-dojo/bun.lockb | Bin 0 -> 20030 bytes packages/create-dojo/package.json | 22 ++++ packages/create-dojo/src/index.ts | 101 ++++++++++++++++ packages/create-dojo/tsconfig.json | 22 ++++ packages/create-dojo/tsup.config.ts | 8 ++ 9 files changed, 342 insertions(+) create mode 100644 packages/create-dojo/.gitignore create mode 100644 packages/create-dojo/README.md create mode 100755 packages/create-dojo/bun.lockb create mode 100644 packages/create-dojo/package.json create mode 100644 packages/create-dojo/src/index.ts create mode 100644 packages/create-dojo/tsconfig.json create mode 100644 packages/create-dojo/tsup.config.ts diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c24f1c2d..68d12f18 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,6 +15,7 @@ jobs: # "packages/torii-wasm", # "packages/torii-client", "packages/create-burner", + "packages/create-dojo", "packages/utils", "packages/core", "packages/react", diff --git a/package.json b/package.json index 1329e5a3..35300a95 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "scripts": { "build-core": "bun run --cwd packages/core build", "build-create-burner": "bun run --cwd packages/create-burner build", + "build-create-dojo": "bun run --cwd packages/create-dojo build", "build-utils": "bun run --cwd packages/utils build", "build-torii-client": "bun run --cwd packages/torii-client build", "build-torii-wasm": "bun run --cwd packages/torii-wasm build", diff --git a/packages/create-dojo/.gitignore b/packages/create-dojo/.gitignore new file mode 100644 index 00000000..3d75225a --- /dev/null +++ b/packages/create-dojo/.gitignore @@ -0,0 +1,172 @@ +# 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* + +# 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/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# 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 +.cache + +# 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 diff --git a/packages/create-dojo/README.md b/packages/create-dojo/README.md new file mode 100644 index 00000000..31531da4 --- /dev/null +++ b/packages/create-dojo/README.md @@ -0,0 +1,15 @@ +# create-dojo + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/packages/create-dojo/bun.lockb b/packages/create-dojo/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..11cc7db1f9bd0f3fc058adbca7260733870b6dbf GIT binary patch literal 20030 zcmeHPd0fof`=2sW(I$zIX_J}Za#3V`hQbzwa3`Qr&^J2Ne zIH>a&@|uv3 z*0*aXPoF^^amOI959wY=kv|LGV>(xXo1)0e6!}<45jPrAls`yO-Wka8y*uPPLb@E< z$9~R)6!S@tqCWVLB5sr-eFBZ)ds(~~dd*-Y0SWfQ15%V%36zJtpchFLU&e3-9P*k% zioE84!TNfTV*dWGw*($l_j?SRDm-v&XHmhq_{{ekhQ1lF#rlVvBRW36=B-z?((SP7 z6!m96^zd4@;A4gKaKn}19%^f*nRd9nw@^#JsD69sBwxoge^&RKyVX)Mb9asUJmtcu z3lGw513Qnq-oKQ`D>wgLvgB6mK8?|pXNK4uTi^9eX{X3U)4tyAwOlWa&c8V5?b=6f z(fQIP=HcUyc66_c2wZ%2UBJ}sZMdTcMJi zBbxW}^1H~|NiSl`=XR_%-V&>Q;9Zt=1WW@eOmI;=D3ULVFu}zm`7_vXSvPrs#|U{E zvi|g&1)~@Y7;Y*A!e37qXE0YPfcdv75PT8Twg)`Ple8rgQt#1U@Gap;Il=3LA_maf zC*>`r1V0||K7em+zX>nF7XaQ>fyXhy*qT7_4*}qAEsy@abR+-3Z$)H0FU+q%P%E6dEXKVsrMG}et<{&CGT3oVmYbn3Jv4< zVf)__2wn_8)IZ`ulvW3V-w!|^z?1y9j$b=axCh`7hq1N&Ano}A-W%{le)7Jhj*xl_ z0PhZXtdHM}*6M)ZPXgWz@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a=Ob zh?hUfcQGwau*TyW*}78_$anFeP5dA=FGAzV4}gu&)Hv8tW7$lf6-x~5gouqdofoN( Osx!7PKc)Wf{rx|pbX2?m literal 0 HcmV?d00001 diff --git a/packages/create-dojo/package.json b/packages/create-dojo/package.json new file mode 100644 index 00000000..e57f3d4e --- /dev/null +++ b/packages/create-dojo/package.json @@ -0,0 +1,22 @@ +{ + "name": "create-dojo", + "module": "index.ts", + "type": "module", + "bin": { + "create-dojo": "./dist/index.js" + }, + "scripts": { + "build": "tsup --dts-resolve" + }, + "dependencies": { + "@inquirer/prompts": "^3.3.0", + "cross-spawn": "^7.0.3" + }, + "devDependencies": { + "@types/cross-spawn": "^6.0.6", + "bun-types": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} \ No newline at end of file diff --git a/packages/create-dojo/src/index.ts b/packages/create-dojo/src/index.ts new file mode 100644 index 00000000..c77a6d92 --- /dev/null +++ b/packages/create-dojo/src/index.ts @@ -0,0 +1,101 @@ +#!/usr/bin/env node + +import https from 'https'; +import spawn from 'cross-spawn'; +import path from "path"; +import * as fs from "fs"; + +import { input, select } from '@inquirer/prompts'; + +const templates = [ + { + value: 'react-app', + description: 'React app using Dojo', + }, + { + value: 'react-phaser-example', + description: 'React/Phaser app using Dojo', + }, +] + +run(); + +async function run() { + + try { + const { template, projectName } = await prompt(); + + // clone template using degit into projectName directory + spawn.sync("npx", ["degit", `dojoengine/dojo.js/examples/${template}`, `${projectName}`]) + + // rewrite package.json + await rewritePackageJson(projectName); + + } catch (e: any) { + console.log(e) + } + +} + + +async function rewritePackageJson(projectName: string) { + + const packageJsonPath = path.join(process.cwd(), projectName, 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); + const latestVersion = await getLatestVersion(); + + // rename using projectName + packageJson.name = projectName; + + // rewrite all link:dojo-packages/packages/... with latest version + for (let dep of Object.keys(packageJson.dependencies)) { + if (dep.startsWith("@dojoengine") && packageJson.dependencies[dep].startsWith("link:")) { + packageJson.dependencies[dep] = latestVersion + } + } + + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); + +} + +async function prompt(): Promise<{ template: string, projectName: string }> { + + const template = await select({ + message: 'Select a template', + choices: templates + }); + + const projectName = await input({ + message: "Project name ", validate: (input: string) => { + if (/^([A-Za-z\-\_\d])+$/.test(input)) return true; + else return 'Project name may only include letters, numbers, underscores and hashes.'; + }, + default: template + }) + + return { template, projectName } + +} + +async function getLatestVersion(): Promise { + return new Promise((resolve, reject) => { + https + .get( + 'https://registry.npmjs.org/-/package/@dojoengine/core/dist-tags', + res => { + if (res.statusCode === 200) { + let body = ''; + res.on('data', data => (body += data)); + res.on('end', () => { + resolve(JSON.parse(body).latest); + }); + } else { + reject(); + } + } + ) + .on('error', () => { + reject(); + }); + }); +} \ No newline at end of file diff --git a/packages/create-dojo/tsconfig.json b/packages/create-dojo/tsconfig.json new file mode 100644 index 00000000..7556e1d4 --- /dev/null +++ b/packages/create-dojo/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "allowImportingTsExtensions": true, + "noEmit": true, + "composite": true, + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "jsx": "react-jsx", + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "types": [ + "bun-types" // add Bun global + ] + } +} diff --git a/packages/create-dojo/tsup.config.ts b/packages/create-dojo/tsup.config.ts new file mode 100644 index 00000000..386ba488 --- /dev/null +++ b/packages/create-dojo/tsup.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from "tsup"; +import { tsupConfig } from "../../tsup.config"; + +export default defineConfig({ + ...tsupConfig, + minify: false, + splitting: false, +});