Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init command to scaffold a new project from a template #217

Merged
merged 18 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"browser": false,
"es6": true
},
"ignorePatterns": ["/dist", "/llama", "/docs-site"],
"ignorePatterns": ["/dist", "/llama", "/docs-site", "/packages/create-node-llama-cpp/dist"],
"extends": [
"eslint:recommended",
"plugin:jsdoc/recommended"
Expand All @@ -15,10 +15,7 @@
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2021,
"ecmaVersion": 2023,
"sourceType": "module"
},
"overrides": [{
Expand Down Expand Up @@ -148,7 +145,9 @@
}],
"keyword-spacing": ["warn"],
"space-infix-ops": ["warn"],
"spaced-comment": ["warn", "always"],
"spaced-comment": ["warn", "always", {
"markers": ["/"]
}],
"eol-last": ["warn", "always"],
"max-len": ["warn", {
"code": 140,
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ jobs:
contents: write
issues: write
pull-requests: write
discussions: write
needs:
- build
- build-binaries
Expand Down Expand Up @@ -381,6 +382,32 @@ jobs:
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
fi
- name: Prepare `create-node-llama-cpp` module
if: steps.set-npm-url.outputs.npm-url != ''
run: |
export DEPLOYED_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)

pushd packages/create-node-llama-cpp
npm ci --ignore-scripts
popd

npx --no vite-node ./scripts/prepareCreateNodeLlamaCppModuleForPublish.ts --packageVersion "$DEPLOYED_PACKAGE_VERSION"

pushd packages/create-node-llama-cpp
npm run build
- name: Release `create-node-llama-cpp` module
if: steps.set-npm-url.outputs.npm-url != ''
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_RELEASE_REF: ${{ github.ref }}
run: |
cd packages/create-node-llama-cpp

if [ "$GH_RELEASE_REF" == "refs/heads/beta" ]; then
npm publish --tag beta
else
npm publish
fi
- name: Generate docs with updated version
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
env:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
with:
node-version: "18"
- name: Install modules
run: npm ci
run: |
npm ci

cd templates
npm ci
- name: ESLint
run: npx eslint --ext .js --ext .ts .
- name: TypeScript validity
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
/dist
/docs-site
/docs/api
/templates/packed

/.env
/.eslintcache
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit $1
npx --no -- commitlint --edit "$1"
1 change: 1 addition & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export default defineConfig({
items: [
{text: "Pull", link: "/pull"},
{text: "Chat", link: "/chat"},
{text: "Init", link: "/init"},
{text: "Download", link: "/download"},
{text: "Complete", link: "/complete"},
{text: "Infill", link: "/infill"},
Expand Down
23 changes: 23 additions & 0 deletions .vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
transition: opacity 0.5s;
opacity: 0;
pointer-events: none;
z-index: -1;
}

.VPNavBar:not(.home) .divider-line[class] {
Expand Down Expand Up @@ -84,6 +85,7 @@
content: "";
transition: opacity 0.5s;
pointer-events: none;
z-index: -1;
}

.main-badges>p {
Expand All @@ -94,6 +96,27 @@
gap: 4px;
}

.VPSidebarItem .text {
word-break: break-word;
line-height: 20px;
padding: 6px 0px;
}

a.inlineCodeLink {
/*text-decoration: none;*/
text-underline-offset: 4px;
color: transparent;
}
a.inlineCodeLink:hover {
color: inherit;
}

a.inlineCodeLink pre>code {
border-radius: 4px;
padding: 3px 6px;
background-color: var(--vp-code-bg);
}

img[src$="assets/logo.roundEdges.png"],
img[src$="assets/logo.png"] {
box-shadow: 0px 4px 12px 0px rgb(0 0 0 / 16%), 0px 8px 64px 0px rgb(0 0 0 / 24%);
Expand Down
5 changes: 1 addition & 4 deletions .vitepress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@
"./config.ts",
"./utils",
"../docs"
],
"ts-node": {
"esm": true
}
]
}
22 changes: 18 additions & 4 deletions .vitepress/utils/getCommandHtmlDoc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {Argv, CommandModule, Options} from "yargs";
import {createMarkdownRenderer} from "vitepress";
import {htmlEscape} from "./htmlEscape.js";
import {cliBinName, npxRunPrefix} from "../../src/config.js";
import {buildHtmlTable} from "./buildHtmlTable.js";
import {buildHtmlHeading} from "./buildHtmlHeading.js";
import {htmlEscapeWithCodeMarkdown} from "./htmlEscapeWithCodeMarkdown.js";
import {getInlineCodeBlockHtml} from "./getInlineCodeBlockHtml.js";
import {cliBinName, npxRunPrefix} from "../../src/config.js";
import {withoutCliCommandDescriptionDocsUrl} from "../../src/cli/utils/withCliCommandDescriptionDocsUrl.js";

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

let res = "";

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

return [
`<a href="${subCommandsParentPageLink != null ? (subCommandsParentPageLink + "/") : ""}${commandPageLink}"><code>` + htmlEscape(cliName + " " + cliCommand) + "</code></a>",
htmlEscapeWithCodeMarkdown(String(subCommand.describe ?? ""))
getInlineCodeBlockHtml(
markdownRenderer,
cliName + " " + cliCommand,
"shell",
(
subCommandsParentPageLink != null
? (subCommandsParentPageLink + "/")
: ""
) + commandPageLink
),
htmlEscapeWithCodeMarkdown(withoutCliCommandDescriptionDocsUrl(String(subCommand.describe ?? "")))
];
})
.filter((row): row is string[] => row != null)
Expand All @@ -72,8 +85,9 @@ export async function getCommandHtmlDoc(command: CommandModule<any, any>, {

return {
title,
description,
description: withoutCliCommandDescriptionDocsUrl(description),
usage: npxRunPrefix + title,
usageHtml: markdownRenderer.render("```shell\n" + npxRunPrefix + title + "\n```"),
options: res
};
}
Expand Down
20 changes: 20 additions & 0 deletions .vitepress/utils/getInlineCodeBlockHtml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {createMarkdownRenderer} from "vitepress";
import {htmlEscape} from "./htmlEscape.js";

export function getInlineCodeBlockHtml(
markdownRenderer: Awaited<ReturnType<typeof createMarkdownRenderer>>, code: string, lang: string, link?: string
) {
if (markdownRenderer.options.highlight != null) {
const codeBlock = markdownRenderer.options.highlight(code, lang, "");

if (link != null && link !== "")
return `<a class="inlineCodeLink" href="${link}">${codeBlock}</a>`;

return `<a class="inlineCodeLink">${codeBlock}</a>`;
}

if (link != null && link !== "")
return `<a href="${link}"><code>${htmlEscape(code)}</code></a>`;

return `<code>${htmlEscape(code)}</code>`;
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summerize what you said";
const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/chat-prompt-wrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summerize what you said";
const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
Expand Down Expand Up @@ -124,7 +124,7 @@ const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summerize what you said";
const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/chat-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summerize what you said";
const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
Expand Down Expand Up @@ -59,7 +59,7 @@ const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summerize what you said";
const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
Expand Down
4 changes: 1 addition & 3 deletions docs/guide/cli/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ If the build fails on macOS with the error `"/usr/bin/cc" is not able to compile
:::

## Usage
```shell-vue
{{commandDoc.usage}}
```
<div v-html="commandDoc.usageHtml"></div>
<div v-html="commandDoc.options"></div>


Expand Down
4 changes: 1 addition & 3 deletions docs/guide/cli/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ const commandDoc = docs.chat;
{{commandDoc.description}}

## Usage
```shell-vue
{{commandDoc.usage}}
```
<div v-html="commandDoc.usageHtml"></div>
<div v-html="commandDoc.options"></div>
4 changes: 1 addition & 3 deletions docs/guide/cli/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ const commandDoc = docs.clear;
{{commandDoc.description}}

## Usage
```shell-vue
{{commandDoc.usage}}
```
<div v-html="commandDoc.usageHtml"></div>
<div v-html="commandDoc.options"></div>
26 changes: 18 additions & 8 deletions docs/guide/cli/cli.data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CommandModule} from "yargs";
import {getCommandHtmlDoc} from "../../../.vitepress/utils/getCommandHtmlDoc.js";
import {createMarkdownRenderer} from "vitepress";
import {PullCommand} from "../../../src/cli/commands/PullCommand.js";
import {BuildCommand} from "../../../src/cli/commands/BuildCommand.js";
import {ChatCommand} from "../../../src/cli/commands/ChatCommand.js";
Expand All @@ -10,22 +10,27 @@ import {InspectGpuCommand} from "../../../src/cli/commands/inspect/commands/Insp
import {InspectGgufCommand} from "../../../src/cli/commands/inspect/commands/InspectGgufCommand.js";
import {DownloadCommand} from "../../../src/cli/commands/DownloadCommand.js";
import {ClearCommand} from "../../../src/cli/commands/ClearCommand.js";
import {htmlEscape} from "../../../.vitepress/utils/htmlEscape.js";
import {InspectMeasureCommand} from "../../../src/cli/commands/inspect/commands/InspectMeasureCommand.js";
import {InitCommand} from "../../../src/cli/commands/InitCommand.js";
import {cliBinName, npxRunPrefix} from "../../../src/config.js";
import {htmlEscape} from "../../../.vitepress/utils/htmlEscape.js";
import {getCommandHtmlDoc} from "../../../.vitepress/utils/getCommandHtmlDoc.js";
import {buildHtmlHeading} from "../../../.vitepress/utils/buildHtmlHeading.js";
import {buildHtmlTable} from "../../../.vitepress/utils/buildHtmlTable.js";
import {setIsInDocumentationMode} from "../../../src/state.js";
import {InspectMeasureCommand} from "../../../src/cli/commands/inspect/commands/InspectMeasureCommand.js";
import {htmlEscapeWithCodeMarkdown} from "../../../.vitepress/utils/htmlEscapeWithCodeMarkdown.js";
import {getInlineCodeBlockHtml} from "../../../.vitepress/utils/getInlineCodeBlockHtml.js";
import {withoutCliCommandDescriptionDocsUrl} from "../../../src/cli/utils/withCliCommandDescriptionDocsUrl.js";

export default {
async load() {
setIsInDocumentationMode(true);

return {
index: buildIndexTable([
index: await buildIndexTable([
["pull", PullCommand],
["chat", ChatCommand],
["init", InitCommand],
["complete", CompleteCommand],
["infill", InfillCommand],
["inspect", InspectCommand],
Expand All @@ -36,6 +41,7 @@ export default {

pull: await getCommandHtmlDoc(PullCommand),
chat: await getCommandHtmlDoc(ChatCommand),
init: await getCommandHtmlDoc(InitCommand),
complete: await getCommandHtmlDoc(CompleteCommand),
infill: await getCommandHtmlDoc(InfillCommand),
inspect: {
Expand All @@ -59,8 +65,9 @@ export default {
}
};

function buildIndexTable(commands: [pageLink: string, command: CommandModule<any, any>][], cliName: string = cliBinName) {
async function buildIndexTable(commands: [pageLink: string, command: CommandModule<any, any>][], cliName: string = cliBinName) {
let res = "";
const markdownRenderer = await createMarkdownRenderer(process.cwd());

res += buildHtmlHeading("h2", htmlEscape("Commands"), "commands");
res += buildHtmlTable(
Expand All @@ -74,8 +81,8 @@ function buildIndexTable(commands: [pageLink: string, command: CommandModule<any
return null;

return [
`<a href="${pageLink}"><code>` + htmlEscape(cliName + " " + command.command) + "</code></a>",
htmlEscapeWithCodeMarkdown(String(command.describe ?? ""))
getInlineCodeBlockHtml(markdownRenderer, cliName + " " + command.command, "shell", pageLink),
htmlEscapeWithCodeMarkdown(withoutCliCommandDescriptionDocsUrl(String(command.describe ?? "")))
];
})
.filter((row): row is string[] => row != null)
Expand Down Expand Up @@ -105,10 +112,13 @@ function buildIndexTable(commands: [pageLink: string, command: CommandModule<any
]
);

const usage = npxRunPrefix + cliName + " <command> [options]";

return {
title: "CLI",
description: null,
usage: npxRunPrefix + cliName + " <command> [options]",
usage,
usageHtml: markdownRenderer.render("```shell\n" + usage + "\n```"),
options: res
};
}
Loading
Loading