From 2415e4945084d279455951f1d796398431565bab Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Wed, 20 Dec 2023 06:36:49 +1100 Subject: [PATCH 1/3] npx test --- .github/workflows/npx-test.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/npx-test.yaml diff --git a/.github/workflows/npx-test.yaml b/.github/workflows/npx-test.yaml new file mode 100644 index 00000000..56b7c830 --- /dev/null +++ b/.github/workflows/npx-test.yaml @@ -0,0 +1,23 @@ +name: Dojo npx create + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "20" + + - name: Create Dojo Project + run: npx @dojoengine/create-dojo From 2f2ebcc2748196ddbdd3fef2a438943be1c897b6 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Wed, 20 Dec 2023 06:38:01 +1100 Subject: [PATCH 2/3] lint --- packages/create-dojo/bin/index.js | 140 +++++++++++++++--------------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/packages/create-dojo/bin/index.js b/packages/create-dojo/bin/index.js index 65a91b46..faf94696 100755 --- a/packages/create-dojo/bin/index.js +++ b/packages/create-dojo/bin/index.js @@ -7,83 +7,87 @@ import path from "path"; import * as fs from "fs"; import { input, select } from "@inquirer/prompts"; var templates = [ - { - value: "react-app", - description: "React app using Dojo" - }, - { - value: "react-phaser-example", - description: "React/Phaser app using Dojo" - } + { + 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(); - console.log(`Downloading ${template}...`); - spawn.sync("npx", [ - "degit", - `dojoengine/dojo.js/examples/${template}`, - `${projectName}` - ]); - await rewritePackageJson(projectName); - console.log(`Downloading dojo-starter...`); - spawn.sync("npx", ["degit", `dojoengine/dojo-starter`, `dojo-starter`]); - } catch (e) { - console.log(e); - } + try { + const { template, projectName } = await prompt(); + console.log(`Downloading ${template}...`); + spawn.sync("npx", [ + "degit", + `dojoengine/dojo.js/examples/${template}`, + `${projectName}`, + ]); + await rewritePackageJson(projectName); + console.log(`Downloading dojo-starter...`); + spawn.sync("npx", ["degit", `dojoengine/dojo-starter`, `dojo-starter`]); + } catch (e) { + console.log(e); + } } async function rewritePackageJson(projectName) { - const packageJsonPath = path.join( - process.cwd(), - projectName, - "package.json" - ); - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); - const latestVersion = await getLatestVersion(); - packageJson.name = projectName; - for (let dep of Object.keys(packageJson.dependencies)) { - if (dep.startsWith("@dojoengine") && packageJson.dependencies[dep].startsWith("link:")) { - packageJson.dependencies[dep] = latestVersion; + const packageJsonPath = path.join( + process.cwd(), + projectName, + "package.json" + ); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); + const latestVersion = await getLatestVersion(); + packageJson.name = projectName; + 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)); + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); } async function prompt() { - const template = await select({ - message: "Select a template", - choices: templates - }); - const projectName = await input({ - message: "Project name ", - validate: (input2) => { - if (/^([A-Za-z\-\_\d])+$/.test(input2)) - return true; - else - return "Project name may only include letters, numbers, underscores and hashes."; - }, - default: template - }); - return { template, projectName }; + const template = await select({ + message: "Select a template", + choices: templates, + }); + const projectName = await input({ + message: "Project name ", + validate: (input2) => { + if (/^([A-Za-z\-\_\d])+$/.test(input2)) return true; + else + return "Project name may only include letters, numbers, underscores and hashes."; + }, + default: template, + }); + return { template, projectName }; } async function getLatestVersion() { - 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(); + 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(); + }); }); - }); } -//# sourceMappingURL=index.js.map \ No newline at end of file +//# sourceMappingURL=index.js.map From b3cc21d178b16861148c97e457337313ace083bd Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Wed, 20 Dec 2023 06:40:06 +1100 Subject: [PATCH 3/3] add install method --- .github/workflows/npx-test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/npx-test.yaml b/.github/workflows/npx-test.yaml index 56b7c830..4fdb819c 100644 --- a/.github/workflows/npx-test.yaml +++ b/.github/workflows/npx-test.yaml @@ -19,5 +19,8 @@ jobs: with: node-version: "20" + - name: Install Dojo CLI + run: npm i @dojoengine/create-dojo -g + - name: Create Dojo Project run: npx @dojoengine/create-dojo