Skip to content

Commit 48e3fdd

Browse files
authored
Setup: Initial files (#1)
1 parent 6451a58 commit 48e3fdd

File tree

13 files changed

+2597
-243
lines changed

13 files changed

+2597
-243
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Settings for editors and IDEs.
2+
# References at https://editorconfig.org/.
3+
4+
root = true
5+
6+
# Settings for any file.
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_size = 2
11+
indent_style = space
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true

.eslintignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Unlinted files and folders.
2+
# References at https://eslint.org/docs/user-guide/configuring#eslintignore
3+
4+
# Generated docs, bundles and type definitions.
5+
docs/
6+
dist/
7+
types/

.eslintrc.json

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
{
22
"plugins": ["@typescript-eslint"],
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaFeatures": {
6+
"jsx": true
7+
},
8+
"ecmaVersion": 2021
9+
},
310
"extends": [
4-
"plugin:astro/recommended",
5-
"plugin:@typescript-eslint/recommended",
6-
"prettier"
7-
],
8-
"overrides": [
9-
{
10-
"files": ["*.astro"],
11-
// Allows Astro components to be parsed.
12-
"parser": "astro-eslint-parser",
13-
// Parse the script in `.astro` as TypeScript by adding the following configuration.
14-
// It's the setting you need when using TypeScript.
15-
"parserOptions": {
16-
"parser": "@typescript-eslint/parser",
17-
"extraFileExtensions": [".astro"]
18-
},
19-
"rules": {}
20-
}
11+
"eslint:recommended",
12+
"plugin:prettier/recommended",
13+
"plugin:@typescript-eslint/eslint-recommended",
14+
"plugin:@typescript-eslint/recommended"
2115
],
2216
"rules": {
2317
"semi": [1, "always"],

.github/actions/setup/action.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Setup'
2+
description: "Setups Node.js and npm to run GitHub Actions' jobs."
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: 'Setup Node.js'
7+
uses: 'actions/setup-node@v3'
8+
with:
9+
node-version: '16.x'
10+
cache: 'npm'
11+
cache-dependency-path: '**/package-lock.json'
12+
13+
- name: 'Keep npm cache for future workflows'
14+
uses: 'actions/cache@v3'
15+
with:
16+
key: "${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}"
17+
path: '~/.npm'
18+
restore-keys: |
19+
${{ runner.os }}-node-
20+
21+
- name: 'Install dependencies'
22+
run: 'npm ci'
23+
shell: 'bash'
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: 'Continuous Integrations'
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
jobs:
8+
lint:
9+
name: 'Run ESLint and Prettier'
10+
runs-on: 'ubuntu-latest'
11+
steps:
12+
- name: 'Checkout the repository'
13+
uses: 'actions/checkout@v3'
14+
15+
- name: 'Setup Node.js and npm'
16+
uses: './.github/actions/setup'
17+
18+
- name: 'Execute the lint script'
19+
run: 'npm run lint'
20+
21+
22+
test:
23+
name: 'Run unit tests with Jest'
24+
runs-on: 'ubuntu-latest'
25+
steps:
26+
- name: 'Checkout the repository'
27+
uses: 'actions/checkout@v3'
28+
29+
- name: 'Setup Node.js and npm'
30+
uses: './.github/actions/setup'
31+
32+
- name: 'Execute the test script'
33+
run: 'npm run test'
34+
35+
bundle:
36+
name: 'Bundle package with Rollup.js'
37+
runs-on: 'ubuntu-latest'
38+
steps:
39+
- name: 'Checkout the repository'
40+
uses: 'actions/checkout@v3'
41+
42+
- name: 'Setup Node.js and npm'
43+
uses: './.github/actions/setup'
44+
45+
- name: 'Execute the build script'
46+
run: 'npm run build'

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Unlinted files and folders.
2+
# References at https://prettier.io/docs/en/ignore.html#ignoring-files.
3+
4+
# Generated docs, bundles and type definitions.
5+
docs/
6+
dist/
7+
types/

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# js-sdk
1+
# HawAPI - js-sdk
2+
23
HawAPI SDK for JavaScript/TypeScript
4+
5+
## Repository template
6+
7+
This library has build using [typescript-library-boilerplate](https://github.com/VitorLuizC/typescript-library-boilerplate) as template.

jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
/* eslint-env node */
3+
4+
/**
5+
* An object with Jest options.
6+
* @type {import('@jest/types').Config.InitialOptions}
7+
*/
8+
const options = {
9+
preset: 'ts-jest',
10+
resolver: 'ts-jest-resolver',
11+
};
12+
13+
module.exports = options;

package.json

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,55 @@
1414
"email": "[email protected]"
1515
},
1616
"license": "MIT",
17-
"main": "index.js",
1817
"keywords": [
1918
"hawapi",
2019
"hawapi-js-sdk",
2120
"haw-api",
2221
"stranger-things",
2322
"stranger-things-api"
2423
],
24+
"cdn": "dist/index.umd.js",
25+
"main": "dist/index.js",
26+
"types": "types/index.d.ts",
27+
"unpkg": "dist/index.umd.js",
28+
"module": "dist/index.esm.js",
29+
"jsdelivr": "dist/index.umd.js",
30+
"umd:main": "dist/index.umd.js",
31+
"exports": {
32+
".": [
33+
{
34+
"import": "./dist/index.mjs",
35+
"require": "./dist/index.cjs",
36+
"default": "./dist/index.js"
37+
},
38+
"./dist/index.js"
39+
]
40+
},
41+
"scripts": {
42+
"test": "jest",
43+
"lint": "eslint \"*/**/*.{ts,js,json}\"",
44+
"lint:fix": "eslint \"*/**/*.{ts,js,json}\" --fix",
45+
"clear": "rm -rf ./dist/",
46+
"build": "yarn clear && rollup --config ./rollup.config.mjs",
47+
"pre-publish": "yarn lint && yarn test && yarn build",
48+
"pre-publish-wot": "yarn lint && yarn build"
49+
},
2550
"devDependencies": {
26-
"typescript": "^4.1.2",
27-
"@typescript-eslint/eslint-plugin": "^4.22.0",
28-
"@typescript-eslint/parser": "^4.22.0",
29-
"eslint": "^7.24.0",
51+
"@types/eslint": "^8.4.10",
52+
"@types/jest": "^29.2.4",
53+
"@types/prettier": "^2.7.2",
54+
"@typescript-eslint/eslint-plugin": "^5.47.0",
55+
"@typescript-eslint/parser": "^5.47.0",
56+
"eslint": "^8.30.0",
3057
"eslint-config-prettier": "^8.5.0",
31-
"prettier": "^2.8.1"
58+
"eslint-plugin-prettier": "^4.2.1",
59+
"jest": "^29.3.1",
60+
"prettier": "^2.8.1",
61+
"rollup": "^2.79.1",
62+
"rollup-plugin-terser": "^7.0.2",
63+
"rollup-plugin-typescript2": "^0.34.1",
64+
"ts-jest": "^29.0.3",
65+
"ts-jest-resolver": "^2.0.0",
66+
"typescript": "^4.9.4"
3267
}
3368
}

rollup.config.mjs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// @ts-check
2+
3+
import { readFile } from 'node:fs/promises';
4+
5+
import { terser } from 'rollup-plugin-terser';
6+
import typescript2 from 'rollup-plugin-typescript2';
7+
8+
const packageJSON = JSON.parse(await readFile('./package.json', 'utf-8'));
9+
10+
const today = Date().split(' ').splice(1, 3).join(' ');
11+
12+
/**
13+
* Comment with library information to be appended in the generated bundles.
14+
*/
15+
const banner = `/*!
16+
* v${packageJSON.version}
17+
* ${packageJSON.name} (${today})
18+
*
19+
* Website: https://hawapi.theproject.id
20+
* Docs: https://hawapi.theproject.id/docs
21+
* Github: https://github.com/HawAPI/js-sdk
22+
*
23+
* (c) ${packageJSON.author.name}
24+
* Released under the ${packageJSON.license} License.
25+
*/
26+
`;
27+
28+
/**
29+
* Creates an output options object for Rollup.js.
30+
* @param {import('rollup').OutputOptions} options
31+
* @returns {import('rollup').OutputOptions}
32+
*/
33+
function createOutputOptions(options) {
34+
return {
35+
banner,
36+
name: 'HawAPI',
37+
exports: 'named',
38+
sourcemap: true,
39+
...options,
40+
};
41+
}
42+
43+
/**
44+
* @type {import('rollup').RollupOptions}
45+
*/
46+
const options = {
47+
input: './src/index.ts',
48+
output: [
49+
createOutputOptions({
50+
file: './dist/index.js',
51+
format: 'commonjs',
52+
}),
53+
createOutputOptions({
54+
file: './dist/cjs/index.cjs',
55+
format: 'commonjs',
56+
}),
57+
createOutputOptions({
58+
file: './dist/esm/index.mjs',
59+
format: 'esm',
60+
}),
61+
createOutputOptions({
62+
file: './dist/esm/index.esm.js',
63+
format: 'esm',
64+
}),
65+
createOutputOptions({
66+
file: './dist/umd/index.umd.js',
67+
format: 'umd',
68+
}),
69+
createOutputOptions({
70+
file: './dist/umd/index.umd.min.js',
71+
format: 'umd',
72+
plugins: [terser()],
73+
}),
74+
],
75+
plugins: [
76+
typescript2({
77+
clean: true,
78+
useTsconfigDeclarationDir: true,
79+
}),
80+
],
81+
};
82+
83+
export default options;

0 commit comments

Comments
 (0)