Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Jan 22, 2024
1 parent 1bbc192 commit 553f612
Show file tree
Hide file tree
Showing 13 changed files with 1,045 additions and 8 deletions.
21 changes: 21 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
54 changes: 54 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Starlight Starter Kit: Basics

[![Built with Starlight](https://astro.badg.es/v2/built-with-starlight/tiny.svg)](https://starlight.astro.build)

```
npm create astro@latest -- --template starlight
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fwithastro%2Fstarlight%2Ftree%2Fmain%2Fexamples%2Fbasics&project-name=my-starlight-docs&repository-name=my-starlight-docs)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
## 🚀 Project Structure

Inside of your Astro + Starlight project, you'll see the following folders and files:

```
.
├── public/
├── src/
│ ├── assets/
│ ├── content/
│ │ ├── docs/
│ │ └── config.ts
│ └── env.d.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.

Images can be added to `src/assets/` and embedded in Markdown with a relative link.

Static assets, like favicons, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).
20 changes: 20 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

// https://astro.build/config
export default defineConfig({
integrations: [
starlight({
title: 'Inox Tools',
social: {
github: 'https://github.com/Fryuni/inox-tools',
},
sidebar: [
{
label: 'Inline Virtual Module',
autogenerate: { directory: 'inline-mod' },
},
],
}),
],
});
17 changes: 17 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "docs",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/starlight": "^0.16.0",
"astro": "^4.2.1",
"sharp": "^0.33.2"
}
}
1 change: 1 addition & 0 deletions docs/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/src/assets
7 changes: 7 additions & 0 deletions docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineCollection } from 'astro:content';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
};
38 changes: 38 additions & 0 deletions docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Inox Tools
description: A collection of oxygen-free tools for Astronauts
template: splash
hero:
tagline: A collection of oxygen-free tools for Astronauts
image:
file: ../../assets/shield.png
# actions:
# - text: Overview
# link: /overview
# icon: right-arrow
# variant: primary
# - text: Read the Starlight docs
# link: https://starlight.astro.build
# icon: external
---

import { Card, CardGrid } from '@astrojs/starlight/components';

## Next steps

<CardGrid stagger>
<a href="/inline-mod">
<Card title="Inline Virtual Module" icon="pencil">
Pass inline JS values and functions as a virtual module to Vite projects.
</Card>
</a>
{/* <Card title="Add new content" icon="add-document">
Add Markdown or MDX files to `src/content/docs` to create new pages.
</Card>
<Card title="Configure your site" icon="setting">
Edit your `sidebar` and other config in `astro.config.mjs`.
</Card>
<Card title="Read the docs" icon="open-book">
Learn more in [the Starlight Docs](https://starlight.astro.build/).
</Card> */}
</CardGrid>
123 changes: 123 additions & 0 deletions docs/src/content/docs/inline-mod/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Inline Virtual Modules
description: Pass inline JS values and functions as a virtual module to Vite projects.
sidebar:
label: Overview
order: 0
---

:::caution[Experimental plugin]
This library is still highly experimental. Many scenarios, even though work sometimes, have not been properly tested yet.
The public API may (and probably will) break compatibility at any moment.
:::

This libray has two parts, a inline module definition and a Vite plugin to expose those defined modules.
Plugins for other bundlers may be added using the same core logic as its base.

The idea of this library is to allow developers to pass and receive non-trivial values on configuration files
that affect the behavior of an application at runtime. For example, defining a middleware function in a config
file and having that middleware running on the server after the deployment.

Imagine if you could have a Vite plugin with this API:

```ts title="vite.config.ts"
export default defineConfig({
plugins: [
yourPlugin({
fetchFunction: (url, requestInit) => {
console.log('Lib is calling fetch');
return fetch(url, requestInit);
},
}),
],
});
```

And access your configuration at runtime inside your runtime code like a normal module:

```ts
// plugin/runtime.ts
import { fetchFunction } from 'yourLib:config';

const response = await fetchFunction(/* ... */);
```

No more weirdly JSON-based JS generators replicated in every project to serialize a configuration.
No more oceans of flags an options to encode every possible use case as a plain object that can be turned into
a JSON to decide what to do at runtime. Let your consumers give you functions with exact behavior they want.

## Origins

This plugin was based on the [work by the Pulumi Corporation][original code] for their inline lambda feature.
[Pulumi](https://pulumi.com) is an Infrastructure as Code platform that allows declaring the desired state of
your infrastructure and construct those declaration using a familiar language like TypeScript, Python or Go.

:::tip
Pulumi's product is just their management portal for team collaboration and AI solutions,
the IaC engine is entirely open source with no locked features, so you can use it for free forever on personal
projects with no limits by managing the state yourself (which is easy if you don't need to manager permissions
of a team) or on smaller projects in your company for evaluating it.

Do check them out!
:::

The original work was strictly for serializing a single exported function along with its captured environment,
and was limited to CommonJS operation mode. This library ports all that logic to ECMAScript Modules and rework
all the logic to support the definition of arbitrary modules.

[original code]: https://github.com/pulumi/pulumi/tree/d4969f3338eb55f8072518ca89ed17a9b72bde93/sdk/nodejs/runtime/closure

Thank you to the authors of the original inline closure serialization code who brought this idea into existence
years ago.

### Licensing notice

Because this is a port and derivation of part of an idea that is within some existing code,
the appropriate licensing for this is somewhat confusing. This section describes all that
I currenly know about it.

The original code by Pulumi Corporation is licensed under the Apache 2.0 license.
All the code made by me is licensed under the MIT license.

I tried to the best of my abilities to find whether this project would have some limitations
under Apache 2.0 and as far as I can tell there is none.

But I am not a lawyer, so if there _is_ an infringiment in any sense of the Apache 2.0 license
for the Pulumi code that you can explain to me, please reach out to at [[email protected]](mailto:[email protected]).

So at best this library is under a dual Apache 2.0 and MIT license and at worst it is fully under Apache 2.0
license in case I can't publish my derivative work under MIT. This will be updated as soon as I get confirmation about it.

As I understood, the code of this library falls into 3 categories:

#### Copied files

Some files of the original code were preserved verbatim since they apply to general JS code
regardless of the different target environments (like [this one][verbatim sample]).

Those files retain the original copyright notice from the Pulumi project as well as their
Apache 2.0 license.

[verbatim sample]: https://github.com/Fryuni/inox-tools/blob/main/packages/inline-mod/src/closure/v8.ts

#### Ported files

Some files have the same logic and goal as the original code from Pulumi, but entirely rewritten
to account for the different targets of both projects, one being solely for CJS functions and
the other for arbitrary ES modules (like [this one][rewrite sample]).

Those may contain snippets of the original code and different code that achieves the same as some
segments of Pulumi's code mixed with new code.

To the best of my knowledge, those are considered my code, so they are licensed under MIT.

[rewrite sample]: https://github.com/Fryuni/inox-tools/blob/main/packages/inline-mod/src/closure/inspectCode.ts

#### Original files

Lastly, some files were written from scratch, like the [inline module declaration][inline decl] and
[Vite plugin][vite plugin]. Those are under MIT.

[inline decl]: https://github.com/Fryuni/inox-tools/blob/main/packages/inline-mod/src/inlining.ts
[vite plugin]: https://github.com/Fryuni/inox-tools/blob/main/packages/inline-mod/src/vite.ts
[verbatim sample]: https://github.com/Fryuni/inox-tools/blob/main/packages/inline-mod/src/closure/v8.ts#L1-L13
2 changes: 2 additions & 0 deletions docs/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
4 changes: 4 additions & 0 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../tsconfig.base.json"
}
Loading

0 comments on commit 553f612

Please sign in to comment.