Skip to content

Commit

Permalink
Merge pull request #3 from LemLib/main
Browse files Browse the repository at this point in the history
Put actual package contents on npm
  • Loading branch information
meisZWFLZ authored Dec 20, 2023
2 parents baf9458 + 440d11d commit ddaa80b
Show file tree
Hide file tree
Showing 32 changed files with 27,058 additions and 10,771 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"plugin:@typescript-eslint/recommended",
"standard-with-typescript",
"prettier"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {}
}
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/BUG_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Bug Report
about: Report a bug in the project
title: "[BUG]"
labels: "needs confirmation"
assignees: ""
---

#### Expected Behavior

<!-- Concisely describe the behavior you expected -->

#### Observed Behavior

<!-- Concisely describe the behavior you observed -->

#### Steps to Reproduce

<!-- Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant -->

#### Environment

<!-- Please provide the following information -->

- LemLink Version: <!-- (e.g. 0.4.5) -->

#### Additional Information

<!-- Add any other relevant information about the problem here -->
<!-- This includes screenshots, code snippets, videos, anything you think is relevant -->
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Feature Request
about: Suggest an idea for the project
title: "[FEATURE]"
labels: "enhancement"
assignees: ""
---

#### Requested Feature

<!-- Concisely describe the behavior you are requesting here -->

<!-- Describe any details in point form here -->

- a
- b
- c

#### Current Implementation

<!-- Describe the current implementation here -->

#### Motivation

<!-- Explain why this feature would benefit users and/or maintainers -->

#### (Optional) Possible Implementations and Alternatives

<!-- Describe any possible implementations or alternatives you have considered -->
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
69 changes: 69 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: ci
on:
pull_request:
branches: "*"
push:
branches: "*"

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Copy repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm i

- name: Lint
run: npm run check-lint

- name: Check formatting
run: npm run check-format

- name: Build
run: npm run build

- name: Test
run: npm test
release_and_publish:
if: github.ref == 'refs/heads/pre-release' || github.ref == 'refs/heads/stable'
runs-on: ubuntu-latest
environment: npm_publish_env
needs: build
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: npm ci

- name: Build project
run: npm run build

- name: Run Semantic Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASR_TOKEN }}
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run pre-commit
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
out
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
20 changes: 10 additions & 10 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: { "node": true }
},
"@babel/preset-typescript"
]
]
}
presets: [
[
"@babel/preset-env",
{
targets: { node: true },
},
"@babel/preset-typescript",
],
],
};
10 changes: 5 additions & 5 deletions examples/connect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { serial } from "node-web-serial-ponyfill";
import { V5SerialDevice } from "../src";

(async function() {
let device = new V5SerialDevice(serial);
void (async function () {
const device = new V5SerialDevice(serial);

await device.connect();
await device.connect();

console.log(device.brain.systemVersion);
})();
console.log(device.brain.systemVersion);
})();
54 changes: 24 additions & 30 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
{
"compilerOptions": {
//
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
//
"isolatedModules": false,
"module": "commonjs",
//
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": false, // it is ok for the example
"noUnusedParameters": false,
"removeComments": true,
"preserveConstEnums": true,
//
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"esModuleInterop": true, // testing
"sourceMap": false,
"target": "es6",
"strictNullChecks": true,
"lib": [
"es5",
"es2015",
"es2016",
"es2017",
"dom"
]
}
}
"compilerOptions": {
//
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
//
"isolatedModules": false,
"module": "commonjs",
//
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": false, // it is ok for the example
"noUnusedParameters": false,
"removeComments": true,
"preserveConstEnums": true,
//
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"esModuleInterop": true, // testing
"sourceMap": false,
"target": "es6",
"strictNullChecks": true,
"lib": ["es5", "es2015", "es2016", "es2017", "dom"]
}
}
64 changes: 36 additions & 28 deletions examples/upload.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
import { serial } from "node-web-serial-ponyfill";
import { ProgramIniConfig, V5SerialDevice, ZerobaseSlotNumber } from "../src";
import {
ProgramIniConfig,
V5SerialDevice,
type ZerobaseSlotNumber,
} from "../src";

import fs from 'fs';
import fs from "fs";

function toUint8(b: Buffer): Uint8Array {
let ab = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
return new Uint8Array(ab);
const ab = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
return new Uint8Array(ab);
}

(async function() {
let device = new V5SerialDevice(serial);

await device.connect();

let slot = 2;
let bin = toUint8(fs.readFileSync("./examples/pros-demo-program/hot.package.bin"));
let cold = toUint8(fs.readFileSync("./examples/pros-demo-program/cold.package.bin"));

let ini = new ProgramIniConfig();
ini.autorun = true;
ini.baseName = "slot_" + slot;
ini.program.name = "PROS Demo";
ini.program.slot = (slot - 1) as ZerobaseSlotNumber;
ini.program.icon = "USER902x.bmp";
ini.program.description = "Demo";

const onProgress = (state: string, current: number, total: number) => {
console.log(state, current, total);
};

let isDone = await device.brain.uploadProgram(ini, bin, cold, onProgress);
console.log("done", isDone);
})();
void (async function () {
const device = new V5SerialDevice(serial);

await device.connect();

const slot = 2;
const bin = toUint8(
fs.readFileSync("./examples/pros-demo-program/hot.package.bin"),
);
const cold = toUint8(
fs.readFileSync("./examples/pros-demo-program/cold.package.bin"),
);

const ini = new ProgramIniConfig();
ini.autorun = true;
ini.baseName = "slot_" + slot;
ini.program.name = "PROS Demo";
ini.program.slot = (slot - 1) as ZerobaseSlotNumber;
ini.program.icon = "USER902x.bmp";
ini.program.description = "Demo";

const onProgress = (state: string, current: number, total: number): void => {
console.log(state, current, total);
};

const isDone = await device.brain.uploadProgram(ini, bin, cold, onProgress);
console.log("done", isDone);
})();
10 changes: 5 additions & 5 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

export default {
preset: 'ts-jest',
preset: "ts-jest",

testEnvironment: 'node',
testEnvironment: "node",

transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.ts?$': 'ts-jest',
"^.+\\.jsx?$": "babel-jest",
"^.+\\.ts?$": "ts-jest",
},

// Indicates whether the coverage information should be collected while executing the test
Expand All @@ -20,5 +20,5 @@ export default {
coverageDirectory: "coverage",

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8"
coverageProvider: "v8",
};
Loading

0 comments on commit ddaa80b

Please sign in to comment.