diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cccad425..e16e3bd3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,8 +57,22 @@ jobs: mv target/i686-pc-windows-gnu/release/create-o7-app.exe artifacts/create-o7-app-win32.exe mv target/x86_64-apple-darwin/release/create-o7-app artifacts/create-o7-app-macos mv target/aarch64-apple-darwin/release/create-o7-app artifacts/create-o7-app-macos-arm64 - - name: Release + - name: Get version + id: get_version + run: echo "version=$(cargo pkgid | cut -d@ -f2)" >> $GITHUB_OUTPUT + - name: Release Binaries uses: softprops/action-gh-release@v1 with: - tag_name: '0.0.0' + tag_name: ${{ steps.get_version.outputs.version }} files: artifacts/* + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Publish NPM Package + run: | + cd pkg + jq '.version = "${{ steps.get_version.outputs.version }}"' package.json > tmp && mv tmp package.json + npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + npm publish diff --git a/package.json b/package.json deleted file mode 100644 index fbf03a01..00000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scripts": { - "dev": "cargo run" - } -} diff --git a/pkg/bin.js b/pkg/bin.js new file mode 100644 index 00000000..f8c91835 --- /dev/null +++ b/pkg/bin.js @@ -0,0 +1,50 @@ + +const { Binary } = require('binary-install'); +const os = require('os'); +const { version } = require('./package.json'); + +const platforms = [ + { + type: 'Windows_NT', + arch: 'x64', + file: 'win64.exe' + }, + { + type: 'Windows_NT', + arch: 'ia32', + file: 'win32.exe' + }, + { + type: 'Linux', + arch: 'x64', + file: 'linux' + }, + { + type: 'Darwin', + arch: 'x64', + file: 'macos' + }, + { + type: 'Darwin', + arch: 'arm64', + file: 'macos-arm64' + }, +]; + +const type = os.type(); +const arch = os.arch(); +const supported = platforms.find( + (p) => p.type === type && p.arch === arch +); +if (!supported) { + throw new Error( + `Unsupported platform: ${type} ${arch}` + ); +} + +module.exports = { + bin: new Binary( + 'create-o7-app', + `https://github.com/ottomated/create-o7-app/releases/download/v${version}/create-o7-app-${supported.file}` + ), +}; diff --git a/pkg/install.js b/pkg/install.js new file mode 100644 index 00000000..7946b131 --- /dev/null +++ b/pkg/install.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +const bin = require("./bin"); +bin.install(); diff --git a/pkg/package.json b/pkg/package.json new file mode 100644 index 00000000..db1d03c3 --- /dev/null +++ b/pkg/package.json @@ -0,0 +1,28 @@ +{ + "name": "create-o7-app", + "version": "TEMPLATE", + "description": "Create web applications with the o7 stack", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/ottomated/create-o7-app.git" + }, + "keywords": [ + "create-o7-app", + "o7", + "svelte", + "sveltekit", + "tailwind", + "tRPC", + "typescript", + "planetscale", + "prisma", + "kysely" + ], + "bin": { + "create-o7-app": "./run.js" + }, + "scripts": { + "postinstall": "node ./install.js" + } +} diff --git a/pkg/run.js b/pkg/run.js new file mode 100644 index 00000000..3fee3790 --- /dev/null +++ b/pkg/run.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +const bin = require("./bin"); +bin.run();