Skip to content

Commit 49fd783

Browse files
committed
feat: first commit
0 parents  commit 49fd783

Some content is hidden

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

43 files changed

+14153
-0
lines changed

.commitlintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"]
3+
}

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
7+
[{*.ts,*.tsx,*.js,*.jsx,*.css,*.scss}]
8+
insert_final_newline = true
9+
10+
[{package.json,package-lock.json,manifest.json}]
11+
indent_size = 2
12+
13+
[.babelrc]
14+
indent_size = 2
15+
16+
[*.yml]
17+
indent_size = 2

.eslintrc.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"node": true,
5+
"browser": false,
6+
"es6": true
7+
},
8+
"ignorePatterns": ["/dist", "/llama"],
9+
"extends": [
10+
"eslint:recommended"
11+
],
12+
"globals": {
13+
"Atomics": "readonly",
14+
"SharedArrayBuffer": "readonly"
15+
},
16+
"parserOptions": {
17+
"ecmaFeatures": {
18+
"jsx": true
19+
},
20+
"ecmaVersion": 2021,
21+
"sourceType": "module"
22+
},
23+
"overrides": [{
24+
"files": ["**.ts"],
25+
"extends": [
26+
"eslint:recommended",
27+
"plugin:@typescript-eslint/recommended"
28+
],
29+
"parser": "@typescript-eslint/parser",
30+
"plugins": [
31+
"@typescript-eslint",
32+
"import",
33+
"node"
34+
],
35+
"rules": {
36+
"@typescript-eslint/explicit-module-boundary-types": ["off"],
37+
"@typescript-eslint/ban-ts-comment": ["off"],
38+
"@typescript-eslint/no-explicit-any": ["off"],
39+
"semi": ["off"],
40+
"@typescript-eslint/semi": ["warn", "always"],
41+
"@typescript-eslint/no-inferrable-types": ["off"]
42+
}
43+
}],
44+
"plugins": [
45+
"@typescript-eslint",
46+
"import",
47+
"node"
48+
],
49+
"settings": {
50+
"import/parsers": {
51+
"@typescript-eslint/parser": [".ts"]
52+
}
53+
},
54+
"rules": {
55+
"indent": ["warn", 4, {
56+
"SwitchCase": 1,
57+
"FunctionDeclaration": {
58+
"parameters": "first"
59+
}
60+
}],
61+
"eqeqeq": ["off"],
62+
"no-undef": "off",
63+
"quotes": ["warn", "double", { "avoidEscape": true }],
64+
"no-unused-vars": ["warn", {
65+
"args": "none",
66+
"ignoreRestSiblings": true,
67+
"varsIgnorePattern": "^set"
68+
}],
69+
"no-prototype-builtins": ["off"],
70+
"object-curly-spacing": ["warn", "never"],
71+
"semi": ["warn", "always"],
72+
"no-undefined": ["off"],
73+
"array-bracket-newline": ["error", "consistent"],
74+
"brace-style": ["error", "1tbs", {
75+
"allowSingleLine": false
76+
}],
77+
"comma-spacing": ["error", {
78+
"before": false,
79+
"after": true
80+
}],
81+
"comma-style": ["error", "last"],
82+
"comma-dangle": ["error", "never"],
83+
"no-var": ["error"],
84+
"import/order": ["error", {
85+
"groups": ["builtin", "external","internal", "parent", "sibling", "index", "type", "object", "unknown"],
86+
"warnOnUnassignedImports": true
87+
}],
88+
"node/file-extension-in-import": ["error", "always", {
89+
"tryExtensions": [".js", ".json"]
90+
}],
91+
"newline-per-chained-call": ["error", {
92+
"ignoreChainWithDepth": 2
93+
}],
94+
"no-confusing-arrow": ["error"],
95+
"no-const-assign": ["error"],
96+
"no-duplicate-imports": ["error", {
97+
"includeExports": true
98+
}],
99+
"camelcase": ["warn"],
100+
"jsx-quotes": ["warn"],
101+
"yoda": ["error", "never", {
102+
"exceptRange": true
103+
}],
104+
"no-eval": ["error"],
105+
"array-callback-return": ["error"],
106+
"valid-jsdoc": ["error", {
107+
"requireParamType": true,
108+
"requireReturnType": true,
109+
"requireReturn": false,
110+
"requireParamDescription": false,
111+
"requireReturnDescription": false
112+
}],
113+
"no-empty": ["error", {
114+
"allowEmptyCatch": true
115+
}],
116+
"keyword-spacing": ["warn"],
117+
"space-infix-ops": ["warn"],
118+
"spaced-comment": ["warn", "always"],
119+
"eol-last": ["warn", "always"],
120+
"max-len": ["warn", {
121+
"code": 140,
122+
"tabWidth": 4,
123+
"ignoreStrings": true
124+
}]
125+
}
126+
}

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.ico filter=lfs diff=lfs merge=lfs -text
2+
*.png filter=lfs diff=lfs merge=lfs -text
3+
*.jpg filter=lfs diff=lfs merge=lfs -text
4+
*.webp filter=lfs diff=lfs merge=lfs -text
5+
*.woff2 filter=lfs diff=lfs merge=lfs -text

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
### Description of change
2+
3+
<!--
4+
Please be clear and concise what the change is intended to do,
5+
why this change is needed, and how you've verified that it
6+
corrects what you intended to correct.
7+
8+
In some cases, it may be helpful to include the current behavior
9+
and the new behavior.
10+
11+
If the change is related to an open issue, you can link it here.
12+
If you include `Fixes #0000` (replacing `0000` with the issue number)
13+
when this is merged, it will automatically mark the issue as fixed and
14+
close it.
15+
-->
16+
17+
18+
### Pull-Request Checklist
19+
20+
<!--
21+
Please make sure to review and check all the following items:
22+
23+
If an item is not applicable, you can add "N/A" to the end.
24+
-->
25+
26+
- [ ] Code is up-to-date with the `master` branch
27+
- [ ] `npm run format` to apply prettier formatting
28+
- [ ] `npm run test` passes with this change
29+
- [ ] This pull request links relevant issues as `Fixes #0000`
30+
- [ ] There are new or updated unit tests validating the change
31+
- [ ] Documentation has been updated to reflect this change
32+
- [ ] The new commits follow conventions explained in [CONTRIBUTING.md](https://github.com/withcatai/node-llama-cpp/blob/master/CONTRIBUTING.md)

.github/workflows/build.yml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Build
2+
on:
3+
push:
4+
5+
workflow_dispatch:
6+
7+
8+
9+
concurrency: release-${{ github.ref }}
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: "20"
19+
- name: Install modules
20+
run: npm ci --ignore-scripts
21+
- name: Build
22+
run: npm run build
23+
- name: Publish artifact
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: "build"
27+
path: "dist"
28+
29+
build-binaries:
30+
name: Build binaries - ${{ matrix.config.name }}
31+
needs:
32+
- build
33+
runs-on: ${{ matrix.config.os }}
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
config:
38+
- name: "Windows MSVC"
39+
os: windows-2022
40+
cc: "cl"
41+
cxx: "cl"
42+
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
43+
generators: "Visual Studio 17 2022"
44+
artifact: "win"
45+
- name: "Ubuntu GCC"
46+
os: ubuntu-22.04
47+
cc: "gcc"
48+
cxx: "g++"
49+
generators: "Ninja"
50+
artifact: "linux"
51+
- name: "macOS Clang"
52+
os: macos-12
53+
cc: "clang"
54+
cxx: "clang++"
55+
generators: "Xcode"
56+
artifact: "mac"
57+
58+
steps:
59+
- uses: actions/checkout@v3
60+
- uses: actions/setup-node@v3
61+
with:
62+
node-version: "20"
63+
64+
- uses: actions/download-artifact@v3
65+
with:
66+
name: build
67+
path: dist
68+
69+
- uses: actions/setup-python@v4
70+
with:
71+
python-version: "3.10"
72+
73+
- name: Install dependencies on windows
74+
if: startsWith(matrix.config.os, 'windows')
75+
run: |
76+
choco install ninja cmake
77+
78+
- name: Install dependencies on ubuntu
79+
if: startsWith(matrix.config.name, 'Ubuntu Latest GCC')
80+
run: |
81+
sudo apt-get update
82+
sudo apt-get install ninja-build cmake libtbb-dev
83+
84+
- name: Install dependencies on macos
85+
if: startsWith(matrix.config.os, 'macos')
86+
run: |
87+
brew install cmake ninja
88+
alias make=cmake
89+
90+
- name: Setup & Build
91+
id: build
92+
shell: bash
93+
timeout-minutes: 40
94+
env:
95+
ARTIFACT_NAME: ${{ matrix.config.artifact }}
96+
run: |
97+
npm ci --ignore-scripts
98+
99+
npx zx -y <<'EOF'
100+
101+
async function getLatestNodeVersions(maxDate) {
102+
const res = await fetch("https://nodejs.org/dist/index.json");
103+
const data = await res.json();
104+
const versions = new Map();
105+
let latestVersion = null;
106+
107+
for (const version of data) {
108+
const majorVersion = Number(version.version.split(".")[0].slice("v".length));
109+
const versionDate = new Date(version.date);
110+
111+
if (maxDate != null && versionDate.getTime() > maxDate)
112+
continue;
113+
114+
if (!versions.has(majorVersion)) {
115+
versions.set(majorVersion, version.version);
116+
}
117+
118+
if (latestVersion === null || majorVersion > latestVersion) {
119+
latestVersion = majorVersion;
120+
}
121+
}
122+
123+
return {versions, latestVersion};
124+
}
125+
126+
function getArches() {
127+
switch (process.env.ARTIFACT_NAME) {
128+
case "win":
129+
return ["x64"];
130+
case "linux":
131+
return ["x64", "arm64", "armv7l", "ppc64le"];
132+
case "mac":
133+
return ["x64", "arm64"];
134+
}
135+
136+
return ["x64"];
137+
}
138+
139+
const {versions: latestNodeVersions, latestVersion: latestNodeVersion} = await getLatestNodeVersions(Date.now() - 1000 * 60 * 60 * 24 * 14);
140+
141+
const minNodeVersion = latestNodeVersion - 4;
142+
143+
const nodeVersions = [...latestNodeVersions].reduce((acc, [majorVersion, version]) => {
144+
if (majorVersion >= minNodeVersion)
145+
acc.push(version);
146+
147+
return acc;
148+
}, []);
149+
const arches = getArches();
150+
151+
console.log("Building for node versions", nodeVersions, "and archs", arches);
152+
153+
await $`mkdir -p llamaBins`;
154+
155+
for (const nodeVersion of nodeVersions) {
156+
for (const arch of arches) {
157+
console.log(`Building ${arch} for node ${nodeVersion}`);
158+
159+
const majorNodeVersion = parseInt(nodeVersion.slice("v".length))
160+
161+
const binName = `${process.env.ARTIFACT_NAME}-${arch}-${majorNodeVersion}.node`;
162+
await $`node ./dist/cli/cli.js download --arch ${arch} --nodeTarget ${nodeVersion}`;
163+
await $`mv ./llama/build/Release/llama.node ${"./llamaBins/" + binName}`;
164+
}
165+
}
166+
167+
await $`echo "Built binaries:"`;
168+
await $`ls llamaBins`;
169+
170+
EOF
171+
172+
- name: Publish artifact
173+
uses: actions/upload-artifact@v3
174+
with:
175+
name: "bins-${{ matrix.config.artifact }}"
176+
path: "llamaBins/*"
177+
178+
release:
179+
name: Release
180+
if: github.ref == 'refs/heads/master'
181+
runs-on: ubuntu-latest
182+
needs:
183+
- build
184+
- build-binaries
185+
steps:
186+
- uses: actions/checkout@v3
187+
- uses: actions/setup-node@v3
188+
with:
189+
node-version: "20"
190+
- name: Install modules
191+
run: npm ci --ignore-scripts
192+
- uses: actions/download-artifact@v3
193+
with:
194+
path: artifacts
195+
- name: Move artifacts
196+
run: |
197+
mkdir -p llamaBins
198+
mv artifacts/bins-*/* llamaBins/
199+
mv artifacts/build dist/
200+
201+
echo "Built binaries:"
202+
ls llamaBins
203+
- name: Release
204+
env:
205+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
207+
run: npx semantic-release
208+

0 commit comments

Comments
 (0)