@stonecrop/nuxt 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Nuxt Stonecrop
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+
6
+ Nuxt module for Stonecrop.
7
+
8
+ ## Features
9
+
10
+ <!-- Highlight some of the features your module provide here -->
11
+ - ⛰ &nbsp;Foo
12
+ - 🚠 &nbsp;Bar
13
+ - 🌲 &nbsp;Baz
14
+
15
+ ## Quick Setup
16
+
17
+ Install the module to your Nuxt application with one command:
18
+
19
+ ```bash
20
+ npx nuxi module add @stonecrop/nuxt
21
+ ```
22
+
23
+ That's it! You can now use Nuxt Stonecrop in your Nuxt app ✨
24
+
25
+
26
+ ## Contribution
27
+
28
+ <details>
29
+ <summary>Local development</summary>
30
+
31
+ ```bash
32
+ # Install dependencies
33
+ npm install
34
+
35
+ # Generate type stubs
36
+ npm run dev:prepare
37
+
38
+ # Develop with the playground
39
+ npm run dev
40
+
41
+ # Build the playground
42
+ npm run dev:build
43
+
44
+ # Run ESLint
45
+ npm run lint
46
+
47
+ # Run Vitest
48
+ npm run test
49
+ npm run test:watch
50
+
51
+ # Release new version
52
+ npm run release
53
+ ```
54
+
55
+ </details>
56
+
57
+
58
+ <!-- Badges -->
59
+ [npm-version-src]: https://img.shields.io/npm/v/@stonecrop/nuxt/latest.svg?style=flat&colorA=020420&colorB=00DC82
60
+ [npm-version-href]: https://npmjs.com/package/@stonecrop/nuxt
61
+
62
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@stonecrop/nuxt.svg?style=flat&colorA=020420&colorB=00DC82
63
+ [npm-downloads-href]: https://npm.chart.dev/@stonecrop/nuxt
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -0,0 +1,11 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ declare const _default: _nuxt_schema.NuxtModule<{
4
+ router: {};
5
+ docbuilder: boolean;
6
+ }, {
7
+ router: {};
8
+ docbuilder: boolean;
9
+ }, false>;
10
+
11
+ export { _default as default };
@@ -0,0 +1,11 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ declare const _default: _nuxt_schema.NuxtModule<{
4
+ router: {};
5
+ docbuilder: boolean;
6
+ }, {
7
+ router: {};
8
+ docbuilder: boolean;
9
+ }, false>;
10
+
11
+ export { _default as default };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@stonecrop/nuxt",
3
+ "configKey": "stonecrop",
4
+ "version": "0.4.0",
5
+ "builder": {
6
+ "@nuxt/module-builder": "0.8.4",
7
+ "unbuild": "unknown"
8
+ }
9
+ }
@@ -0,0 +1,70 @@
1
+ import { createResolver, defineNuxtModule, addLayout, extendPages, addPlugin } from '@nuxt/kit';
2
+ import { existsSync, readdirSync } from 'node:fs';
3
+ import { extname } from 'node:path';
4
+
5
+
6
+
7
+ // -- Unbuild CommonJS Shims --
8
+ import __cjs_url__ from 'url';
9
+ import __cjs_path__ from 'path';
10
+ import __cjs_mod__ from 'module';
11
+ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
12
+ const __dirname = __cjs_path__.dirname(__filename);
13
+ const require = __cjs_mod__.createRequire(import.meta.url);
14
+ const { resolve } = createResolver(import.meta.url);
15
+ const module = defineNuxtModule({
16
+ meta: {
17
+ name: "@stonecrop/nuxt",
18
+ configKey: "stonecrop"
19
+ },
20
+ defaults: (nuxt) => {
21
+ return {
22
+ router: {},
23
+ docbuilder: false
24
+ };
25
+ },
26
+ setup(_options, nuxt) {
27
+ const layoutsDir = resolve("runtime/layouts");
28
+ const homeLayoutPath = resolve(layoutsDir, "StonecropHome.vue");
29
+ addLayout(homeLayoutPath, "home");
30
+ const rootDir = nuxt.options.srcDir;
31
+ const doctypesDir = resolve(rootDir, "doctypes");
32
+ if (existsSync(doctypesDir)) {
33
+ const schemas = readdirSync(doctypesDir).filter((file) => extname(file) === ".json");
34
+ const pagesDir = resolve("runtime/pages");
35
+ const homePagePath = resolve(pagesDir, "StonecropPage.vue");
36
+ extendPages((pages) => {
37
+ const pagePaths = pages.map((page) => page.path);
38
+ if (pagePaths.includes("/")) {
39
+ throw new Error("[@stonecrop/nuxt] Conflict found with existing root page");
40
+ }
41
+ pages.unshift({
42
+ name: "stonecrop-home",
43
+ path: "/",
44
+ file: homeLayoutPath
45
+ });
46
+ for (const schema of schemas) {
47
+ const schemaName = schema.replace(".json", "");
48
+ if (pagePaths.includes(`/${schemaName}`)) {
49
+ throw new Error(`[@stonecrop/nuxt] Conflict found with existing page for doctype: ${schemaName}`);
50
+ }
51
+ const schemaPath = resolve(doctypesDir, schema);
52
+ const jsonData = require(schemaPath);
53
+ if (jsonData.schema) {
54
+ pages.unshift({
55
+ name: `stonecrop-${schemaName}`,
56
+ path: `/${schemaName}`,
57
+ file: homePagePath,
58
+ meta: {
59
+ schema: jsonData.schema
60
+ }
61
+ });
62
+ }
63
+ }
64
+ });
65
+ }
66
+ addPlugin(resolve("./runtime/plugin"));
67
+ }
68
+ });
69
+
70
+ export { module as default };
@@ -0,0 +1,14 @@
1
+ <template>
2
+ <div>Stonecrop Home</div>
3
+
4
+ <div v-if="isReady">
5
+ <p>Stonecrop is ready!</p>
6
+ </div>
7
+ <pre>{{ stonecrop }}</pre>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ import { useStonecrop } from '@stonecrop/stonecrop'
12
+
13
+ const { stonecrop, isReady } = useStonecrop()
14
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div>Stonecrop Page</div>
3
+ <AForm v-model="schema" :data="schemaData" :key="componentKey" />
4
+ </template>
5
+
6
+ <script setup lang="ts">
7
+ import type { SchemaTypes } from '@stonecrop/aform'
8
+ import { useRoute } from 'nuxt/app'
9
+ import { onMounted, ref } from 'vue'
10
+
11
+ const route = useRoute()
12
+ const schema = ref<SchemaTypes[]>([])
13
+ const schemaData = ref<any[]>([])
14
+ const componentKey = ref(0)
15
+
16
+ onMounted(async () => {
17
+ // wait for the route-based schema to be resolved
18
+ schema.value = route.meta.schema as SchemaTypes[]
19
+
20
+ const res = await $fetch(`/api${route.path}`)
21
+ schemaData.value = res as any[]
22
+
23
+ // re-render form when data is available
24
+ componentKey.value++
25
+ })
26
+ </script>
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { install as AForm } from "@stonecrop/aform";
2
+ import { install as ATable } from "@stonecrop/atable";
3
+ import { Stonecrop } from "@stonecrop/stonecrop";
4
+ import { createPinia } from "pinia";
5
+ import { defineNuxtPlugin, useRouter } from "nuxt/app";
6
+ export default defineNuxtPlugin((nuxt) => {
7
+ const pinia = createPinia();
8
+ const router = useRouter();
9
+ const app = nuxt.vueApp;
10
+ app.use(pinia);
11
+ app.use(AForm);
12
+ app.use(ATable);
13
+ app.use(Stonecrop, { router });
14
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../.nuxt/tsconfig.server.json"
3
+ }
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.js'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.js'
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module'
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@stonecrop/nuxt",
3
+ "version": "0.4.0",
4
+ "description": "Nuxt module for Stonecrop",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "Tyler Matteson",
9
+ "email": "tyler@agritheory.com"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/agritheory/stonecrop",
14
+ "directory": "nuxt"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/types.d.ts",
19
+ "import": "./dist/module.mjs",
20
+ "require": "./dist/module.cjs"
21
+ }
22
+ },
23
+ "main": "./dist/module.cjs",
24
+ "types": "./dist/types.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "dependencies": {
29
+ "@nuxt/kit": "^3.15.2",
30
+ "pinia": "^2.3.0",
31
+ "@stonecrop/atable": "0.4.0",
32
+ "@stonecrop/aform": "0.4.0",
33
+ "@stonecrop/stonecrop": "0.4.0"
34
+ },
35
+ "devDependencies": {
36
+ "@nuxt/devtools": "^1.7.0",
37
+ "@nuxt/module-builder": "^0.8.4",
38
+ "@nuxt/schema": "^3.15.2",
39
+ "@nuxt/test-utils": "^3.15.4",
40
+ "eslint": "^8.40.0",
41
+ "h3": "*",
42
+ "nitropack": "*",
43
+ "nuxi": "^3.20.0",
44
+ "nuxt": "^3.15.2",
45
+ "typescript": "~5.6.3",
46
+ "vue": "^3.5.11",
47
+ "vite": "^5.4.5",
48
+ "vitest": "^2.1.1",
49
+ "vue-router": "^4.4.0"
50
+ },
51
+ "scripts": {
52
+ "prepublish": "rushx dev:prepare && nuxt-module-build build",
53
+ "build": "rushx dev:prepare && nuxt-module-build build",
54
+ "dev": "nuxi dev playground",
55
+ "dev:build": "nuxi build playground",
56
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
57
+ "lint": "eslint . --ext .ts,.vue",
58
+ "test": "vitest",
59
+ "test:ui": "vitest --ui"
60
+ }
61
+ }