Skip to content

Commit d6a0f43

Browse files
authored
feat: init command to scaffold a new project from a template (#217)
* feat: `init` command to scaffold a project from a template * feat: `node-typescript` project template * feat: `electron-typescript-react` project template * feat: debug mode * feat: load LoRA adapters * feat: link to CLI command docs from the CLI help * feat: improve Electron support * fix: improve binary compatibility detection on Linux * docs: CLI commands syntax highlighting
1 parent d321fe3 commit d6a0f43

File tree

119 files changed

+7528
-3210
lines changed

Some content is hidden

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

119 files changed

+7528
-3210
lines changed

.eslintrc.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"browser": false,
66
"es6": true
77
},
8-
"ignorePatterns": ["/dist", "/llama", "/docs-site"],
8+
"ignorePatterns": ["/dist", "/llama", "/docs-site", "/packages/create-node-llama-cpp/dist"],
99
"extends": [
1010
"eslint:recommended",
1111
"plugin:jsdoc/recommended"
@@ -15,10 +15,7 @@
1515
"SharedArrayBuffer": "readonly"
1616
},
1717
"parserOptions": {
18-
"ecmaFeatures": {
19-
"jsx": true
20-
},
21-
"ecmaVersion": 2021,
18+
"ecmaVersion": 2023,
2219
"sourceType": "module"
2320
},
2421
"overrides": [{
@@ -148,7 +145,9 @@
148145
}],
149146
"keyword-spacing": ["warn"],
150147
"space-infix-ops": ["warn"],
151-
"spaced-comment": ["warn", "always"],
148+
"spaced-comment": ["warn", "always", {
149+
"markers": ["/"]
150+
}],
152151
"eol-last": ["warn", "always"],
153152
"max-len": ["warn", {
154153
"code": 140,

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ body:
3939
Your bug can be investigated much faster if your code can be run without any dependencies other than `node-llama-cpp`.
4040
Issues without reproduction steps or code examples may be closed as not actionable.
4141
Please try to provide a Minimal, Complete, and Verifiable example ([link](http://stackoverflow.com/help/mcve)).
42-
Also, please enable enable debug logs by using `getLlama({logLevel: LlamaLogLevel.debug})` to get more information.
42+
Also, please enable enable debug logs by using `getLlama({debug: true})` to get more information.
4343
placeholder: >-
4444
Please try to provide a Minimal, Complete, and Verifiable example.
4545
http://stackoverflow.com/help/mcve

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ jobs:
334334
contents: write
335335
issues: write
336336
pull-requests: write
337+
discussions: write
337338
needs:
338339
- build
339340
- build-binaries
@@ -381,6 +382,32 @@ jobs:
381382
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
382383
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
383384
fi
385+
- name: Prepare `create-node-llama-cpp` module
386+
if: steps.set-npm-url.outputs.npm-url != ''
387+
run: |
388+
export DEPLOYED_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)
389+
390+
pushd packages/create-node-llama-cpp
391+
npm ci --ignore-scripts
392+
popd
393+
394+
npx --no vite-node ./scripts/prepareCreateNodeLlamaCppModuleForPublish.ts --packageVersion "$DEPLOYED_PACKAGE_VERSION"
395+
396+
pushd packages/create-node-llama-cpp
397+
npm run build
398+
- name: Release `create-node-llama-cpp` module
399+
if: steps.set-npm-url.outputs.npm-url != ''
400+
env:
401+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
402+
GH_RELEASE_REF: ${{ github.ref }}
403+
run: |
404+
cd packages/create-node-llama-cpp
405+
406+
if [ "$GH_RELEASE_REF" == "refs/heads/beta" ]; then
407+
npm publish --tag beta
408+
else
409+
npm publish
410+
fi
384411
- name: Generate docs with updated version
385412
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
386413
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules
66
/dist
77
/docs-site
88
/docs/api
9+
/templates/packed
910

1011
/.env
1112
/.eslintcache

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx --no -- commitlint --edit $1
4+
npx --no -- commitlint --edit "$1"

.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export default defineConfig({
226226
items: [
227227
{text: "Pull", link: "/pull"},
228228
{text: "Chat", link: "/chat"},
229+
{text: "Init", link: "/init"},
229230
{text: "Download", link: "/download"},
230231
{text: "Complete", link: "/complete"},
231232
{text: "Infill", link: "/infill"},

.vitepress/theme/style.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
transition: opacity 0.5s;
5151
opacity: 0;
5252
pointer-events: none;
53+
z-index: -1;
5354
}
5455

5556
.VPNavBar:not(.home) .divider-line[class] {
@@ -84,6 +85,7 @@
8485
content: "";
8586
transition: opacity 0.5s;
8687
pointer-events: none;
88+
z-index: -1;
8789
}
8890

8991
.main-badges>p {
@@ -94,6 +96,27 @@
9496
gap: 4px;
9597
}
9698

99+
.VPSidebarItem .text {
100+
word-break: break-word;
101+
line-height: 20px;
102+
padding: 6px 0px;
103+
}
104+
105+
a.inlineCodeLink {
106+
/*text-decoration: none;*/
107+
text-underline-offset: 4px;
108+
color: transparent;
109+
}
110+
a.inlineCodeLink:hover {
111+
color: inherit;
112+
}
113+
114+
a.inlineCodeLink pre>code {
115+
border-radius: 4px;
116+
padding: 3px 6px;
117+
background-color: var(--vp-code-bg);
118+
}
119+
97120
img[src$="assets/logo.roundEdges.png"],
98121
img[src$="assets/logo.png"] {
99122
box-shadow: 0px 4px 12px 0px rgb(0 0 0 / 16%), 0px 8px 64px 0px rgb(0 0 0 / 24%);

.vitepress/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,5 @@
3232
"./config.ts",
3333
"./utils",
3434
"../docs"
35-
],
36-
"ts-node": {
37-
"esm": true
38-
}
35+
]
3936
}

.vitepress/utils/getCommandHtmlDoc.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import {Argv, CommandModule, Options} from "yargs";
2+
import {createMarkdownRenderer} from "vitepress";
23
import {htmlEscape} from "./htmlEscape.js";
3-
import {cliBinName, npxRunPrefix} from "../../src/config.js";
44
import {buildHtmlTable} from "./buildHtmlTable.js";
55
import {buildHtmlHeading} from "./buildHtmlHeading.js";
66
import {htmlEscapeWithCodeMarkdown} from "./htmlEscapeWithCodeMarkdown.js";
7+
import {getInlineCodeBlockHtml} from "./getInlineCodeBlockHtml.js";
8+
import {cliBinName, npxRunPrefix} from "../../src/config.js";
9+
import {withoutCliCommandDescriptionDocsUrl} from "../../src/cli/utils/withCliCommandDescriptionDocsUrl.js";
710

811
export async function getCommandHtmlDoc(command: CommandModule<any, any>, {
912
cliName = cliBinName,
@@ -19,6 +22,7 @@ export async function getCommandHtmlDoc(command: CommandModule<any, any>, {
1922
const title = cliName + " " + (resolvedParentCommandCliCommand ?? "<command>").replace("<command>", currentCommandCliCommand ?? "");
2023
const description = command.describe ?? "";
2124
const {subCommands, optionGroups} = await parseCommandDefinition(command);
25+
const markdownRenderer = await createMarkdownRenderer(process.cwd());
2226

2327
let res = "";
2428

@@ -45,8 +49,17 @@ export async function getCommandHtmlDoc(command: CommandModule<any, any>, {
4549
cliCommand = (resolvedParentCommandCliCommand ?? "<command>").replace("<command>", cliCommand);
4650

4751
return [
48-
`<a href="${subCommandsParentPageLink != null ? (subCommandsParentPageLink + "/") : ""}${commandPageLink}"><code>` + htmlEscape(cliName + " " + cliCommand) + "</code></a>",
49-
htmlEscapeWithCodeMarkdown(String(subCommand.describe ?? ""))
52+
getInlineCodeBlockHtml(
53+
markdownRenderer,
54+
cliName + " " + cliCommand,
55+
"shell",
56+
(
57+
subCommandsParentPageLink != null
58+
? (subCommandsParentPageLink + "/")
59+
: ""
60+
) + commandPageLink
61+
),
62+
htmlEscapeWithCodeMarkdown(withoutCliCommandDescriptionDocsUrl(String(subCommand.describe ?? "")))
5063
];
5164
})
5265
.filter((row): row is string[] => row != null)
@@ -72,8 +85,9 @@ export async function getCommandHtmlDoc(command: CommandModule<any, any>, {
7285

7386
return {
7487
title,
75-
description,
88+
description: withoutCliCommandDescriptionDocsUrl(description),
7689
usage: npxRunPrefix + title,
90+
usageHtml: markdownRenderer.render("```shell\n" + npxRunPrefix + title + "\n```"),
7791
options: res
7892
};
7993
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {createMarkdownRenderer} from "vitepress";
2+
import {htmlEscape} from "./htmlEscape.js";
3+
4+
export function getInlineCodeBlockHtml(
5+
markdownRenderer: Awaited<ReturnType<typeof createMarkdownRenderer>>, code: string, lang: string, link?: string
6+
) {
7+
if (markdownRenderer.options.highlight != null) {
8+
const codeBlock = markdownRenderer.options.highlight(code, lang, "");
9+
10+
if (link != null && link !== "")
11+
return `<a class="inlineCodeLink" href="${link}">${codeBlock}</a>`;
12+
13+
return `<a class="inlineCodeLink">${codeBlock}</a>`;
14+
}
15+
16+
if (link != null && link !== "")
17+
return `<a href="${link}"><code>${htmlEscape(code)}</code></a>`;
18+
19+
return `<code>${htmlEscape(code)}</code>`;
20+
}

0 commit comments

Comments
 (0)