Skip to content

Commit

Permalink
Merge pull request #262 from Hexagon/dev
Browse files Browse the repository at this point in the history
9.0 stable
  • Loading branch information
Hexagon authored Oct 15, 2024
2 parents 5840c20 + 7bfefc4 commit 4847b7d
Show file tree
Hide file tree
Showing 79 changed files with 4,519 additions and 12,719 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
dist/* linguist-generated
dist-docs/* linguist-documentation
src/helpers/minitz.ts linguist-vendored
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ A clear and concise description of what you expected to happen.
**System:**
- OS: [e.g. iOS, Linux, Windows]
- Runtime [Node.js, Deno, Bun, Chrome, Safari, Firefox]
- Version [e.g. 22]
- Runtime Version [e.g. 22]
- Croner Version [e.g. 9.0.0-dev.11]

**Additional context**
Add any other context about the problem here.
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/bun.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/deno.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/node.js.yml

This file was deleted.

10 changes: 9 additions & 1 deletion .github/workflows/npm-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ jobs:
- uses: actions/checkout@v3
with:
ref: dev

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: "2.x"

- uses: actions/setup-node@v3.5.1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install

- run: deno task build

- run: npm publish --tag dev
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 10 additions & 2 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ jobs:
- uses: actions/checkout@v3
with:
ref: master

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: "2.x"

- uses: actions/setup-node@v3.5.1
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install

- run: deno task build

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Cross Runtime Tests

on:
push:
branches: [main, dev, dev-9.0]
pull_request:
branches: [main, dev, dev-9.0]

jobs:
deno_ci:
uses: cross-org/workflows/.github/workflows/deno-ci.yml@main
with:
entrypoint: src/croner.ts
lint_docs: false
bun_ci:
uses: cross-org/workflows/.github/workflows/bun-ci.yml@main
with:
jsr_dependencies: "@cross/test @std/assert"
node_ci:
uses: cross-org/workflows/.github/workflows/node-ci.yml@main
with:
test_target: "test/*.test.ts"
jsr_dependencies: "@cross/test @std/assert"
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ dist-docs
_site

# TypeScript incremental compilation information
.tsbuildinfo
.tsbuildinfo

# Built NPM package
dist
package.json
package-lock.json

# TypeScript configuration is added on-demand
tsconfig.json
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ Quick examples:

```javascript
// Basic: Run a function at the interval defined by a cron expression
const job = Cron('*/5 * * * * *', () => {
const job = new Cron('*/5 * * * * *', () => {
console.log('This will run every fifth second');
});

// Enumeration: What dates do the next 100 sundays occur on?
const nextSundays = Cron('0 0 0 * * 7').nextRuns(100);
const nextSundays = new Cron('0 0 0 * * 7').nextRuns(100);
console.log(nextSundays);

// Days left to a specific date
const msLeft = Cron('59 59 23 24 DEC *').nextRun() - new Date();
const msLeft = new Cron('59 59 23 24 DEC *').nextRun() - new Date();
console.log(Math.floor(msLeft/1000/3600/24) + " days left to next christmas eve");

// Run a function at a specific date/time using a non-local timezone (time is ISO 8601 local time)
// This will run 2024-01-23 00:00:00 according to the time in Asia/Kolkata
Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });
new Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });

```

Expand Down Expand Up @@ -96,13 +96,13 @@ Cron takes three arguments
// - First: Cron pattern, js date object (fire once), or ISO 8601 time string (fire once)
// - Second: Options (optional)
// - Third: Function run trigger (optional)
const job = Cron("* * * * * *", { maxRuns: 1 }, () => {} );
const job = new Cron("* * * * * *", { maxRuns: 1 }, () => {} );

// If function is omitted in constructor, it can be scheduled later
job.schedule(job, /* optional */ context) => {});
```

The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.
The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `new Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.

#### Status

Expand Down
117 changes: 117 additions & 0 deletions build/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import esbuild from "esbuild";
import { dtsPlugin } from "esbuild-plugin-d.ts";
import { cp, readFile, writeFile } from "@cross/fs";

/**
* Build helpers
*/
export async function build(
baseConfig: esbuild.BuildOptions,
configs?: esbuild.BuildOptions[],
): Promise<void> {
const buildConfigs = configs?.map((config) => ({ ...baseConfig, ...config })) || [baseConfig];
try {
await Promise.all(buildConfigs.map((config) => esbuild.build(config)));
console.log("All builds completed successfully.");
} catch (error) {
console.error("Build failed:", error);
}
}
async function readJson<T>(filePath: string): Promise<T> {
const jsonData = await readFile(filePath);
return JSON.parse(new TextDecoder().decode(jsonData)) as T;
}

/**
* Now the actual build script
*/
import { dirname, fromFileUrl, resolve } from "@std/path";

/* Preparations - Work out paths */
const baseRelativeProjectRoot = "../"; // Where is this script located relative to the project root
const currentScriptDir = dirname(fromFileUrl(import.meta.url));
const relativeProjectRoot = resolve(currentScriptDir, baseRelativeProjectRoot);
const resolvedDistPath = resolve(relativeProjectRoot, "dist");

/* Handle argument `clean`: Rimraf build artifacts */
if (Deno.args[1] === "clean") {
for (
const filePath of [
"package.json",
"tsconfig.json",
"node_modules",
"dist",
]
) {
try {
await Deno.remove(filePath, { recursive: true });
} catch (_e) { /* No-op */ }
}

/* Handle argument `build`: Transpile and generate typings */
} else if (Deno.args[1] === "build") {
await build({
entryPoints: [resolve(relativeProjectRoot, "src/croner.ts")],
bundle: true,
minify: true,
sourcemap: false,
}, [
{
outdir: resolvedDistPath,
platform: "node",
format: "cjs",
outExtension: { ".js": ".cjs" },
},
{
entryPoints: [],
stdin: {
contents: 'import { Cron } from "./croner.ts";module.exports = Cron;',
resolveDir: "./src/",
},
outfile: resolve(resolvedDistPath, "croner.umd.js"),
platform: "browser",
format: "iife",
globalName: "Cron",
},
{
outdir: resolvedDistPath,
platform: "neutral",
format: "esm",
plugins: [dtsPlugin({
experimentalBundling: true,
tsconfig: {
compilerOptions: {
declaration: true,
emitDeclarationOnly: true,
allowImportingTsExtensions: true,
lib: ["es6", "dom"],
},
},
})],
},
]);

// Just re-use the .d.ts for commonjs, as .d.cts
await cp(
resolve(resolvedDistPath, "croner.d.ts"),
resolve(resolvedDistPath, "croner.d.cts"),
);

/* Handle argument `package`: Generate package.json based on a base config and values from deno,json */
} else if (Deno.args[1] === "package") {
// Read version from deno.json
const denoConfig = await readJson<{ version: string }>(resolve(relativeProjectRoot, "deno.json"));

// Write package.json
await writeFile(
resolve(relativeProjectRoot, "package.json"),
new TextEncoder().encode(JSON.stringify(
{
...await readJson<object>(resolve(relativeProjectRoot, "build/package.template.json")),
version: denoConfig.version,
},
null,
2,
)),
);
}
Loading

0 comments on commit 4847b7d

Please sign in to comment.