Skip to content

Instantly share code, notes, and snippets.

@jrson83
jrson83 / action.test.ts
Created February 11, 2023 22:28
github-action-test
import { RunOptions, RunTarget } from 'github-action-ts-run-api'
import assert from 'node:assert'
import fs from 'node:fs'
import http from 'node:http'
async function runTest() {
const port = 8234
const server = http
.createServer((req, res) => {
if (req.url === '/repos/owner/repo') {
// Adapted from https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_transpiler_loader
import { readFileSync, writeFileSync } from 'fs'
import { dirname } from 'path'
import { URL, pathToFileURL, fileURLToPath } from 'url'
import esbuild from 'esbuild'
const baseURL = pathToFileURL(`${process.cwd()}/`).href
const tsExtensionRegex = /\.(tsx?)$/
function readJSON(path) {
@jrson83
jrson83 / update-config.js
Created February 6, 2023 21:47 — forked from jbreckmckye/update-config.js
Beanstalk / general-purpose JSON mass updater
const fs = require('fs');
const cliArgs = process.argv.slice(2);
const key = cliArgs[0];
const val = cliArgs[1];
function parseJSON(string) {
const sanitised = string.replace(/\s\$\w*/g, substr => `"__SANITISED__${substr}"`);
return JSON.parse(sanitised);
}
@jrson83
jrson83 / cypress-plugins-index.js
Created February 6, 2023 21:46 — forked from estefafdez/cypress-plugins-index.js
cypress/plugins/index.js with different configuration files.
// promisified fs module
const fs = require('fs-extra')
const path = require('path')
function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve(__dirname, '../config', `${file}.json`)
return fs.readJson(pathToConfigFile)
}
@jrson83
jrson83 / createPackage.ts
Created February 6, 2023 21:43 — forked from mattmazzola/createPackage.ts
Create Package Script
import * as fs from 'fs-extra'
import * as path from 'path'
const packageJsonPath = path.join(__dirname, '..', 'package.json')
const buildPath = path.join(__dirname, '..', 'build')
const uiPackagePath = path.join(__dirname, '..', 'package')
const indexJsPath = path.join(uiPackagePath, 'index.js')
const indexDtsPath = path.join(uiPackagePath, 'index.d.ts')
async function main() {
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import glob from 'glob';
import path from 'path';
const globAsync = (pattern: string): Promise<string[]> =>
new Promise<string[]>((res, rej) =>
glob(pattern, (err, matches) => (err ? rej(err) : res(matches))),
);
const paths = await globAsync('src/**/*.ts');
@jrson83
jrson83 / package-json.ts
Created January 22, 2023 05:22 — forked from LeeCheneler/package-json.ts
typescript type for package.json
export interface Package {
name: string;
version: string;
description?: string;
keywords?: string[];
homepage?: string;
bugs?: {
url: string;
email: string;
@jrson83
jrson83 / cp.js
Created January 20, 2023 17:28 — forked from lmammino/cp.js
Session about Node.js streams with Kelvin
import { createReadStream, createWriteStream } from 'fs'
const source = createReadStream('./assets/moby-dick.txt')
const dest = createWriteStream('./assets/moby-dick-decompressed.txt')
source
.pipe(dest)
@jrson83
jrson83 / keyboard-move.js
Created January 16, 2023 16:21 — forked from kirbee/keyboard-move.js
Small node program reading each keystroke from the command line
const readline = require('readline');
const stdin = process.stdin;
readline.emitKeypressEvents(stdin);
stdin.setRawMode(true);
class Coordinates {
constructor(x = 0, y = 0) {
this.x = x;
@jrson83
jrson83 / node12.js
Created January 12, 2023 06:19 — forked from gpDA/node12.js
const path = require('path');
const string = __filename;
// path.sep: /
console.log('path.sep:', path.sep);
// path.delimiter: :
console.log('path.delimiter:', path.delimiter);
console.log('------');
// path.dirname(): /Users/gp/Desktop/node_module