Skip to content

Commit

Permalink
initial commit (#1)
Browse files Browse the repository at this point in the history
* initial commit

* format

---------

Co-authored-by: Pistonight <[email protected]>
  • Loading branch information
Pistonight and Pistonight authored May 9, 2024
1 parent 343a114 commit 249bfa3
Show file tree
Hide file tree
Showing 14 changed files with 865 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Adder of Time - CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: baptiste0928/cargo-install@v3
with:
crate: dprint
- uses: oven-sh/setup-bun@v1
- run: bun install --frozon-lockfile
- run: task check
- run: task test
- run: task build
- uses: actions/upload-pages-artifact@v3
with:
path: dist
retention-days: 3

deploy:
name: Deploy
needs: [build]
if: github.event_name != 'pull_request'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- id: deployment
uses: actions/deploy-pages@v4

178 changes: 178 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# 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*

# Caches

.cache

# 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/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# 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

# 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

# Finder (MacOS) folder config
.DS_Store

/dist
/temp
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# addtime
Adder of Time https://pistonite.github.io/addtime


## To use in Google Sheet Apps Script
In your Google Sheet, go to `Extensions > Apps Script`, and paste
in [this script](https://pistonite.github.io/addtime/appscript.txt)

You will have access to the `ADDTIME` function which adds a range of cells,
and the `SUBTIME` function that subtracts 2 cells

## To consume as TypeScript library
Download the source to your project
```
curl https://pistonite.github.io/addtime/time.ts > somewhere/addtime.ts
```
Then map the path in your `tsconfig.json`
```json
{
"compilerOptions": {
"paths": {
"addtime": ["base/rel/path/to/somewhere/addtime.ts"]
}
},
"include": ["path/to/somewhere"]
}
```
Finally import and use
```typescript
import { calc } from "addtime";
```
45 changes: 45 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3'

tasks:
test:
desc: Run tests
cmds:
- bun test

dev:
desc: Run tests in watch mode
cmds:
- bun test --watch

check:
desc: Check for issues
cmds:
- bunx --bun tsc
- dprint check

fix:
desc: Fix issues
cmds:
- dprint fmt

build:
desc: Build the distributable web app
cmds:
- mkdir -p dist temp
- rm -rf dist/*
- cp src/index.html dist/index.html
- bun build ./src/main.ts --outfile=dist/main.js --minify
- bun build ./src/code.ts --outfile=temp/code.gs --minify
- sed -i -e '1s/^/var calc=(function(){ /' temp/code.gs
- sed -i -e 's/;window\.__calc=/;return /' temp/code.gs
- cp src/code.gs dist/appscript.txt
- cat temp/code.gs >> dist/appscript.txt
- echo '})()' >> dist/appscript.txt
- echo '//! https://github.com/Pistonite/addtime' > dist/time.ts
- echo '' >> dist/time.ts
- cat src/time.ts >> dist/time.ts

serve:
desc: Serve /dist
cmds:
- bunx --bun serve dist
Binary file added bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"typescript": {
"indentWidth": 4,
"semiColons": "always",
"useBraces": "always",
"bracePosition": "sameLine"
},
"json": {
"indentWidth": 4
},
"excludes": [
"**/node_modules",
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.90.5.wasm",
"https://plugins.dprint.dev/json-0.19.2.wasm"
]
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "addtime",
"devDependencies": {
"@types/bun": "latest",
"serve": "^14.2.3",
"typescript": "^5.0.0"
}
}
19 changes: 19 additions & 0 deletions src/code.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// ADDTIME function: adds a range of cells
/// Usage: =ADDTIME(range)
/// Example: =ADDTIME(A1:A36)
function ADDTIME(times) {
return calc(
times.map(t=>t.filter(t=>t).join("+")).filter(t=>t).join("+"),
BigInt(30)
).answers.join(",\n");
}

/// SUBTIME function: subtract 2 cells
/// Usage: =SUBTIME(cell1, cell2)
/// Example: =SUBTIME(A1, B2)
function SUBTIME(time1, time2){
var r =calc(time1+"-"+time2, BigInt(30));
return [r.answers.join(",\n"), r.errors.join(",\n")];
}

/// https://github.com/Pistonite/addtime
4 changes: 4 additions & 0 deletions src/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { calc } from "./time.ts";

// @ts-ignore
window.__calc = calc;
Loading

0 comments on commit 249bfa3

Please sign in to comment.