Skip to content

Commit

Permalink
chore(cleanup): some small updates based on learnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Jan 24, 2024
1 parent 6955b70 commit f99a4f1
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 401 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/**/*.test.ts
lib
**/*.cjs
**/*.mjs
examples
1 change: 0 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
* @ardriveapp/services
310 changes: 155 additions & 155 deletions LICENSE → LICENSE.md

Large diffs are not rendered by default.

110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,111 @@
# node-sdk-template

Hello developer, welcome to this SDK!!
This is the home of [INSERT SDK NAME] SDK. This SDK provides functionality for [SHORT DESCRIPTION HERE] available for both NodeJS and Web environments.

## Table of Contents

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [NodeJS Environments](#node)
- [Web Environments](#web)
- [Typescript](#typescript)
- [APIs](#apis)
- [Examples](./examples)
- [Developers](#developers)
- [Requirements](#requirements)
- [Setup & Build](#setup--build)
- [Testing](#testing)
- [Linting and Formatting](#linting--formatting)
- [Architecture](#architecture)
- [Contributing](./CONTRIBUTING.md)

## Installation

```shell
npm install @ardrive/INSERT-SDK-NAME
```

or

```shell
yarn add @ardrive/INSERT-SDK-NAME
```

## Quick Start

```typescript
// INSERT A SHORT EXAMPLE OF HOW TO SETUP AND USE THE SDK
```

## Usage

The SDK is provided in both CommonJS and ESM formats, and it's compatible with bundlers such as Webpack, Rollup, and ESbuild. Utilize the appropriately named exports provided by this SDK's [package.json] based on your project's configuration. Refer to the [examples] directory to see how to use the SDK in various environments.

### Web

#### Bundlers (Webpack, Rollup, ESbuild, etc.)

```javascript
// INSERT EXAMPLE FOR USING IN ESM PROJECT
```

#### Browser

```javascript
// INSERT EXAMPLE FOR USING IN BROWSER PROJECT
```

### Node

```javascript
// INSERT EXAMPLE FOR USING IN CJS PROJECT
```

### Typescript

The SDK provides TypeScript types. When you import the SDK in a TypeScript project:

Types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized, offering benefits such as type-checking and autocompletion.

## APIs

[INSERT A LIST OF ALL THE APIS PROVIDED BY THE SDK AND HOW TO USE THEM]

## Developers

### Requirements

- `nvm`
- `node` (>= 18)
- `yarn`

### Setup & Build

- `yarn install` - installs dependencies
- `yarn build` - builds web/node/bundled outputs

### Testing

- `yarn test` - runs integration tests
- `yarn example:web` - opens up the example web page
- `yarn example:cjs` - runs example CJS node script
- `yarn example:esm` - runs example ESM node script

### Linting & Formatting

- `yarn lint:check` - checks for linting errors
- `yarn lint:fix` - fixes linting errors
- `yarn format:check` - checks for formatting errors
- `yarn format:fix` - fixes formatting errors

### Architecture

- Code to interfaces.
- Prefer type safety over runtime safety.
- Prefer composition over inheritance.
- Prefer integration tests over unit tests.

For more information on how to contribute, please see [CONTRIBUTING.md].

<!-- ADD ALL LINK REFERENCES BELOW -->
34 changes: 34 additions & 0 deletions bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { build } from 'esbuild';
import { polyfillNode } from 'esbuild-plugin-polyfill-node';

const bundle = () => {
console.log('Building web bundle esm.');
const result = build({
entryPoints: ['./src/index.ts'],
bundle: true,
platform: 'browser',
target: ['esnext'],
format: 'esm',
globalName: 'turbo',
plugins: [
polyfillNode({
polyfills: {
crypto: true,
},
}),
],
tsconfig: './tsconfig.web.json',
outfile: './bundles/web.bundle.min.js',
})
.catch((e) => {
console.log(e);
process.exit(1);
})
.then(() => {
console.log('Successfully built web bundle.');
});
};

bundle();

export { bundle };
34 changes: 22 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,34 @@
"website": "https://ardrive.io"
},
"exports": {
"./web": "./bundles/web.bundle.min.js",
".": {
"import": "./lib/index.js",
"require": "./lib/index.js"
"import": "./lib/esm/node/index.js",
"require": "./lib/cjs/node/index.js",
"types": "./lib/types/node/index.d.ts",
"browser": "./bundles/web.bundle.min.js"
},
"./node": {
"import": "./lib/esm/node/index.js",
"require": "./lib/cjs/node/index.js",
"types": "./lib/types/node/index.d.ts"
},
"./web": {
"import": "./bundles/web.bundle.min.js",
"require": "./bundles/web.bundle.min.js",
"types": "./lib/types/web/index.d.ts",
"browser": "./bundles/web.bundle.min.js"
}
},
"engines": {
"node": ">=18"
},
"license": "AGPL-3.0-or-later",
"scripts": {
"build:web": "node bundle.cjs",
"build:esm": "yarn tsc -p tsconfig.json && cp package.json README.md LICENSE.md ./lib",
"build": "yarn clean && yarn build:web && yarn build:esm",
"build:web": "node bundle.mjs",
"build:esm": "yarn tsc -p tsconfig.json",
"build:cjs": "yarn tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
"build:types": "yarn tsc -p tsconfig.types.json",
"build": "yarn clean && yarn build:web && yarn build:esm && yarn build:cjs && yarn build:types",
"clean": "rimraf [ lib coverage bundles ]",
"postinstall": "husky install",
"lint": "eslint src",
Expand All @@ -42,12 +56,7 @@
"example:cjs": "yarn build:esm && node examples/node/index.mjs",
"example:web": "yarn build:web && cp -r bundles/* examples/web && http-server --port 8080 --host -o examples/web"
},
"dependencies": {
"arweave": "^1.14.4",
"axios": "^1.4.0",
"retry-axios": "^3.0.0",
"winston": "^3.10.0"
},
"dependencies": {},
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
Expand All @@ -64,6 +73,7 @@
"c8": "^8.0.1",
"chai": "^4.3.7",
"esbuild": "^0.19.2",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^37.0.0",
Expand Down
2 changes: 1 addition & 1 deletion resources/license.header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./lib/cjs"
}
}
9 changes: 4 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"compilerOptions": {
"target": "es6",
"target": "ES6",
"allowSyntheticDefaultImports": true,
"declaration": true,
"lib": ["esnext", "dom"],
"outDir": "./lib",
"outDir": "./lib/esm",
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "nodenext",
Expand All @@ -23,6 +22,6 @@
"skipLibCheck": true,
"strictNullChecks": true
},
"include": ["src"],
"exclude": ["lib", "node_modules"]
"include": ["src", "resources"],
"exclude": ["lib", "node_modules", "bundles"]
}
9 changes: 9 additions & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"outDir": "./lib/types",
"emitDeclarationOnly": true
}
}
7 changes: 7 additions & 0 deletions tsconfig.web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/web", "src/common", "src/utils"],
"compilerOptions": {
"outDir": "./lib/web"
}
}
Loading

0 comments on commit f99a4f1

Please sign in to comment.