Skip to content

Commit 4847b7d

Browse files
authored
Merge pull request #262 from Hexagon/dev
9.0 stable
2 parents 5840c20 + 7bfefc4 commit 4847b7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4519
-12719
lines changed

.gitattributes

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
dist/* linguist-generated
2-
dist-docs/* linguist-documentation
31
src/helpers/minitz.ts linguist-vendored

.github/ISSUE_TEMPLATE/bug_report.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ A clear and concise description of what you expected to happen.
2626
**System:**
2727
- OS: [e.g. iOS, Linux, Windows]
2828
- Runtime [Node.js, Deno, Bun, Chrome, Safari, Firefox]
29-
- Version [e.g. 22]
29+
- Runtime Version [e.g. 22]
30+
- Croner Version [e.g. 9.0.0-dev.11]
3031

3132
**Additional context**
3233
Add any other context about the problem here.

.github/dependabot.yml

-6
This file was deleted.

.github/workflows/bun.yaml

-32
This file was deleted.

.github/workflows/deno.yaml

-33
This file was deleted.

.github/workflows/node.js.yml

-34
This file was deleted.

.github/workflows/npm-prerelease.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ jobs:
99
- uses: actions/checkout@v3
1010
with:
1111
ref: dev
12+
13+
- name: Setup Deno
14+
uses: denoland/setup-deno@v2
15+
with:
16+
deno-version: "2.x"
17+
1218
- uses: actions/[email protected]
1319
with:
1420
node-version: '16.x'
1521
registry-url: 'https://registry.npmjs.org'
16-
- run: npm install
22+
23+
- run: deno task build
24+
1725
- run: npm publish --tag dev
1826
env:
1927
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/npm.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ jobs:
99
- uses: actions/checkout@v3
1010
with:
1111
ref: master
12+
13+
- name: Setup Deno
14+
uses: denoland/setup-deno@v2
15+
with:
16+
deno-version: "2.x"
17+
1218
- uses: actions/[email protected]
1319
with:
14-
node-version: '16.x'
20+
node-version: '18.x'
1521
registry-url: 'https://registry.npmjs.org'
16-
- run: npm install
22+
23+
- run: deno task build
24+
1725
- run: npm publish
1826
env:
1927
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Cross Runtime Tests
2+
3+
on:
4+
push:
5+
branches: [main, dev, dev-9.0]
6+
pull_request:
7+
branches: [main, dev, dev-9.0]
8+
9+
jobs:
10+
deno_ci:
11+
uses: cross-org/workflows/.github/workflows/deno-ci.yml@main
12+
with:
13+
entrypoint: src/croner.ts
14+
lint_docs: false
15+
bun_ci:
16+
uses: cross-org/workflows/.github/workflows/bun-ci.yml@main
17+
with:
18+
jsr_dependencies: "@cross/test @std/assert"
19+
node_ci:
20+
uses: cross-org/workflows/.github/workflows/node-ci.yml@main
21+
with:
22+
test_target: "test/*.test.ts"
23+
jsr_dependencies: "@cross/test @std/assert"

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ dist-docs
4545
_site
4646

4747
# TypeScript incremental compilation information
48-
.tsbuildinfo
48+
.tsbuildinfo
49+
50+
# Built NPM package
51+
dist
52+
package.json
53+
package-lock.json
54+
55+
# TypeScript configuration is added on-demand
56+
tsconfig.json

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ Quick examples:
2626

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

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

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

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

4545
```
4646

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

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

105-
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.
105+
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.
106106

107107
#### Status
108108

build/build.ts

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import esbuild from "esbuild";
2+
import { dtsPlugin } from "esbuild-plugin-d.ts";
3+
import { cp, readFile, writeFile } from "@cross/fs";
4+
5+
/**
6+
* Build helpers
7+
*/
8+
export async function build(
9+
baseConfig: esbuild.BuildOptions,
10+
configs?: esbuild.BuildOptions[],
11+
): Promise<void> {
12+
const buildConfigs = configs?.map((config) => ({ ...baseConfig, ...config })) || [baseConfig];
13+
try {
14+
await Promise.all(buildConfigs.map((config) => esbuild.build(config)));
15+
console.log("All builds completed successfully.");
16+
} catch (error) {
17+
console.error("Build failed:", error);
18+
}
19+
}
20+
async function readJson<T>(filePath: string): Promise<T> {
21+
const jsonData = await readFile(filePath);
22+
return JSON.parse(new TextDecoder().decode(jsonData)) as T;
23+
}
24+
25+
/**
26+
* Now the actual build script
27+
*/
28+
import { dirname, fromFileUrl, resolve } from "@std/path";
29+
30+
/* Preparations - Work out paths */
31+
const baseRelativeProjectRoot = "../"; // Where is this script located relative to the project root
32+
const currentScriptDir = dirname(fromFileUrl(import.meta.url));
33+
const relativeProjectRoot = resolve(currentScriptDir, baseRelativeProjectRoot);
34+
const resolvedDistPath = resolve(relativeProjectRoot, "dist");
35+
36+
/* Handle argument `clean`: Rimraf build artifacts */
37+
if (Deno.args[1] === "clean") {
38+
for (
39+
const filePath of [
40+
"package.json",
41+
"tsconfig.json",
42+
"node_modules",
43+
"dist",
44+
]
45+
) {
46+
try {
47+
await Deno.remove(filePath, { recursive: true });
48+
} catch (_e) { /* No-op */ }
49+
}
50+
51+
/* Handle argument `build`: Transpile and generate typings */
52+
} else if (Deno.args[1] === "build") {
53+
await build({
54+
entryPoints: [resolve(relativeProjectRoot, "src/croner.ts")],
55+
bundle: true,
56+
minify: true,
57+
sourcemap: false,
58+
}, [
59+
{
60+
outdir: resolvedDistPath,
61+
platform: "node",
62+
format: "cjs",
63+
outExtension: { ".js": ".cjs" },
64+
},
65+
{
66+
entryPoints: [],
67+
stdin: {
68+
contents: 'import { Cron } from "./croner.ts";module.exports = Cron;',
69+
resolveDir: "./src/",
70+
},
71+
outfile: resolve(resolvedDistPath, "croner.umd.js"),
72+
platform: "browser",
73+
format: "iife",
74+
globalName: "Cron",
75+
},
76+
{
77+
outdir: resolvedDistPath,
78+
platform: "neutral",
79+
format: "esm",
80+
plugins: [dtsPlugin({
81+
experimentalBundling: true,
82+
tsconfig: {
83+
compilerOptions: {
84+
declaration: true,
85+
emitDeclarationOnly: true,
86+
allowImportingTsExtensions: true,
87+
lib: ["es6", "dom"],
88+
},
89+
},
90+
})],
91+
},
92+
]);
93+
94+
// Just re-use the .d.ts for commonjs, as .d.cts
95+
await cp(
96+
resolve(resolvedDistPath, "croner.d.ts"),
97+
resolve(resolvedDistPath, "croner.d.cts"),
98+
);
99+
100+
/* Handle argument `package`: Generate package.json based on a base config and values from deno,json */
101+
} else if (Deno.args[1] === "package") {
102+
// Read version from deno.json
103+
const denoConfig = await readJson<{ version: string }>(resolve(relativeProjectRoot, "deno.json"));
104+
105+
// Write package.json
106+
await writeFile(
107+
resolve(relativeProjectRoot, "package.json"),
108+
new TextEncoder().encode(JSON.stringify(
109+
{
110+
...await readJson<object>(resolve(relativeProjectRoot, "build/package.template.json")),
111+
version: denoConfig.version,
112+
},
113+
null,
114+
2,
115+
)),
116+
);
117+
}

0 commit comments

Comments
 (0)