Skip to content

Commit

Permalink
build and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Aug 5, 2023
1 parent ba0a971 commit 2b64c1f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and Deploy
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Use Node.js 😂
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install and Build 🔧
run: |
npm ci
npm run build-ci
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: .
8 changes: 4 additions & 4 deletions tools/fixup.d.ts.js → build/tools/fixup.d.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import fs from 'fs';
import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
const readTextFile = n => fs.readFileSync(n, {encoding: 'utf-8'});

const pkg = JSON.parse(readTextFile(path.join(__dirname, '..', 'package.json')));
const pkg = JSON.parse(readTextFile(path.join(dirname, '..', 'package.json')));
const majorVersion = pkg.version.split('.')[0];

const dtsFilename = path.join(__dirname, '..', 'dist', `${majorVersion}.x`, 'buffer-views.d.ts');
const s = readTextFile(dtsFilename)
const dtsFilename = path.join(dirname, '..', 'dist', `${majorVersion}.x`, 'buffer-views.d.ts');
const s = readTextFile(dtsFilename);
const newS = s.replace(
/export\s+type\s+ArrayBufferViews\s+=\s+{\s+views:\s+TypedArrayOrViews;/m,
`export type ArrayBufferViews = {
Expand Down
13 changes: 7 additions & 6 deletions build/tools/makeindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import fs from 'fs';
import path from 'path';
import MarkdownIt from 'markdown-it';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const dirname = url.fileURLToPath(new URL('.', import.meta.url));

// eslint-disable-next-line new-cap
const md = MarkdownIt({
html: true,
langPrefix: 'lang-',
typographer: true,
quotes: '“”‘’',
});

const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), {encoding: 'utf8'}));
const pkg = JSON.parse(fs.readFileSync(path.join(dirname, '..', '..', 'package.json'), {encoding: 'utf8'}));

function getLicense(pkg) {
return `@license webgpu-utils ${pkg.version} Copyright (c) 2023, Gregg Tavares All Rights Reserved.
Expand All @@ -30,15 +31,15 @@ see: http://github.com/greggman/webgpu-utils for details`;
* @param {Object|Object[]} params one or more objects.
* @returns {string} string with replaced parts
*/
const replaceParams = (function() {
const replaceParams = (function () {
const replaceParamsRE = /%\(([^)]+)\)s/g;

return function(str, params) {
return function (str, params) {
if (!params.length) {
params = [params];
}

return str.replace(replaceParamsRE, function(match, key) {
return str.replace(replaceParamsRE, function (match, key) {
const colonNdx = key.indexOf(':');
if (colonNdx >= 0) {
/*
Expand All @@ -49,7 +50,7 @@ const replaceParams = (function() {
if (handler) {
return handler(args[handlerName]);
}
console.error("unknown substition handler: " + handlerName);
console.error("unknown substitution handler: " + handlerName);
} catch (e) {
console.error(e);
console.error("bad substitution: %(" + key + ")s");
Expand Down
9 changes: 9 additions & 0 deletions build/tools/prep-for-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'fs';
import path from 'path';
import * as url from 'url';
const dirname = url.fileURLToPath(new URL('.', import.meta.url));

const ignoreFilename = path.join(dirname, '..', '..', '.gitignore');
const ignore = fs.readFileSync(ignoreFilename, {encoding: 'utf8'});
const newIgnore = ignore.replace(/# -- clip-for-deploy-start --[\s\S]*?# -- clip-for-deploy-end --/, '');
fs.writeFileSync(ignoreFilename, newIgnore);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"scripts": {
"build": "npm run make && npm run docs && npm run makeindex",
"make": "rollup -c && node tools/fixup.d.ts.js",
"build-ci": "npm run build && node build/tools/prep-for-deploy.js",
"make": "rollup -c && node build/tools/fixup.d.ts.js",
"check": "npm run lint",
"check-ci": "npm run pre-push",
"docs": "typedoc --disableSources src/webgpu-utils.ts",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"src/**/*.ts",
"examples/**/*.js",
"test/**/*.js",
"build/**/*.js",
".eslintrc.cjs",
"*.js",
"test/tests/**/*.html",
Expand Down

0 comments on commit 2b64c1f

Please sign in to comment.