Skip to content

Commit

Permalink
NPM script
Browse files Browse the repository at this point in the history
  • Loading branch information
j3lte committed Dec 6, 2023
1 parent ef7d2a2 commit da3bdc2
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 59 deletions.
41 changes: 26 additions & 15 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
{
"tasks": {
"fetch": "deno run -A scripts/fetch-databases.ts",
"format": "deno fmt",
"fetch-data": "deno run -A scripts/fetch-databases.ts && deno fmt -q ./src/providers && deno lint"
},
"fmt": {
"options": {
"indentWidth": 2,
"lineWidth": 100,
"singleQuote": false,
"useTabs": false,
"proseWrap": "preserve"
"tasks": {
"fetch": "deno run -A scripts/fetch-databases.ts",
"format": "deno fmt",
"lint": "deno lint ./src/",
"fetch-data": "deno run -A scripts/fetch-databases.ts && deno fmt -q ./src/providers && deno lint",
"npm": "deno run -A ./scripts/build-npm.ts"
},
"files": {
"exclude": []
"fmt": {
"options": {
"indentWidth": 2,
"lineWidth": 100,
"singleQuote": false,
"useTabs": false,
"proseWrap": "preserve"
},
"exclude": []
},
"lint": {
"rules": {
"include": [
"ban-untagged-todo",
"explicit-function-return-type"
]
},
"exclude": [
"npm/"
]
}
}
}
80 changes: 39 additions & 41 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dev_deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { render } from "https://deno.land/x/[email protected]/mod.ts";
export { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
90 changes: 90 additions & 0 deletions scripts/build-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { SpecifierMappings } from "https://deno.land/x/[email protected]/transform.ts";
import { build, emptyDir } from "../dev_deps.ts";
import { getLatestVersion } from "./fetch-databases.ts";

const cleanupTypes = async (dir: string) => {
for await (const dirEntry of Deno.readDir(dir)) {
const entryPath = `${dir}/${dirEntry.name}`;
if (dirEntry.isDirectory) {
await cleanupTypes(entryPath);
} else {
const file = await Deno.readTextFile(entryPath);
const newFile = file.replaceAll('.js"', '"');
await Deno.writeTextFile(entryPath, newFile);
}
}
};

await emptyDir("./npm");

const latestVersion = await getLatestVersion();

if (!latestVersion) {
console.log("Error fetching latest version, aborting");
Deno.exit(1);
}

const mappings: SpecifierMappings = {};
mappings[`https://deno.land/x/soda@${latestVersion}/mod.ts`] = {
name: "soda-query",
version: `^${latestVersion}`,
};

console.log("Building npm package");
console.log(mappings);

await build({
entryPoints: ["./src/mod.ts"],
outDir: "./npm",
mappings,
declaration: "separate",
skipSourceOutput: true,
// scriptModule: false,
shims: {},
test: false,
typeCheck: false,
compilerOptions: {
importHelpers: true,
target: "ES2021",
lib: ["ESNext"],
},
package: {
// package.json properties
name: "rdw-data",
version: Deno.args[0] || "1.0.0",
description: "Get RDW data from the RDW Open Data API",
license: "MIT",
publishConfiig: {
access: "public",
},
keywords: [
"soda",
"socrata",
"open data",
"api",
"rdw",
"kenteken",
"parking",
"voertuig",
"deno",
"typescript",
],
author: {
name: "J.W. Lagendijk",
email: "[email protected]",
},
repository: {
type: "git",
url: "git+https://github.com/j3lte/rdw-data.git",
},
bugs: {
url: "https://github.com/j3lte/rdw-data/issues",
},
},
async postBuild(): Promise<void> {
// steps to run after building and before running the tests
await Deno.copyFile("./LICENSE", "npm/LICENSE");
await Deno.copyFile("./README.md", "npm/README.md");
await cleanupTypes("./npm/types");
},
});
2 changes: 1 addition & 1 deletion scripts/fetch-databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const renderAndWrite = async (template: string, item: WithSodaVersion) => {
return Deno.writeTextFile(`${outputFolder}/${item.name}.ts`, rendered);
};

const getLatestVersion = async () => {
export const getLatestVersion = async () => {
const mod = "https://deno.land/x/soda/mod.ts";
const { output, code } = await runCmd([
"deno",
Expand Down
1 change: 0 additions & 1 deletion scripts/templates/mod.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export {
SystemFields,
Where,
} from "https://deno.land/x/soda@<%= it.sodaVersion %>/mod.ts";

<% it.items.forEach(function (item) { %>
export * as <%= item.name %> from "./<%= item.name %>.ts";<% }); %>
1 change: 0 additions & 1 deletion src/providers/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export {
Where,
} from "https://deno.land/x/[email protected]/mod.ts";


export * as AsGegevensEegUitvoering from "./AsGegevensEegUitvoering.ts";
export * as BasisgegevensEegUitvoering from "./BasisgegevensEegUitvoering.ts";
export * as BrandstoffenOpPc4 from "./BrandstoffenOpPc4.ts";
Expand Down

0 comments on commit da3bdc2

Please sign in to comment.