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

create-dojo #61

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
# "packages/torii-wasm",
# "packages/torii-client",
"packages/create-burner",
"packages/create-dojo",
"packages/utils",
"packages/core",
"packages/react",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
172 changes: 172 additions & 0 deletions packages/create-dojo/.gitignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions packages/create-dojo/README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added packages/create-dojo/bun.lockb
Binary file not shown.
22 changes: 22 additions & 0 deletions packages/create-dojo/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
101 changes: 101 additions & 0 deletions packages/create-dojo/src/index.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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();
});
});
}
22 changes: 22 additions & 0 deletions packages/create-dojo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
]
}
}
8 changes: 8 additions & 0 deletions packages/create-dojo/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "tsup";
import { tsupConfig } from "../../tsup.config";

export default defineConfig({
...tsupConfig,
minify: false,
splitting: false,
});
Loading