Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
casualmatt committed Nov 15, 2024
0 parents commit e18d40a
Show file tree
Hide file tree
Showing 21 changed files with 905 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npx nypm@latest i

- name: Lint
run: npm run lint

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npx nypm@latest i

- name: Playground prepare
run: npm run dev:prepare

- name: Test
run: npm run test
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Dependencies
node_modules

# Logs
*.log*

# Temp directories
.temp
.tmp
.cache

# Yarn
**/.yarn/cache
**/.yarn/*state*

# Generated dirs
dist

# Nuxt
.nuxt
.output
.data
.vercel_build_output
.build-*
.netlify

# Env
.env

# Testing
reports
coverage
*.lcov
.nyc_output

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Intellij idea
*.iml
.idea

# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.experimental.useFlatConfig": true
}
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--
Get your module up and running quickly.
Find and replace all on all files (CMD+SHIFT+F):
- Name: My Module
- Package name: my-module
- Description: My new Nuxt module
-->

# My Module

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
[![Nuxt][nuxt-src]][nuxt-href]

My new Nuxt module for doing amazing things.

- [&nbsp;Release Notes](/CHANGELOG.md)
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
<!-- - [📖 &nbsp;Documentation](https://example.com) -->

## Features

<!-- Highlight some of the features your module provide here -->
-&nbsp;Foo
- 🚠 &nbsp;Bar
- 🌲 &nbsp;Baz

## Quick Setup

Install the module to your Nuxt application with one command:

```bash
npx nuxi module add my-module
```

That's it! You can now use My Module in your Nuxt app ✨


## Contribution

<details>
<summary>Local development</summary>

```bash
# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release
```

</details>


<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
[npm-version-href]: https://npmjs.com/package/my-module

[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
[npm-downloads-href]: https://npm.chart.dev/my-module

[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
[license-href]: https://npmjs.com/package/my-module

[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
[nuxt-href]: https://nuxt.com
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

// Run `npx @eslint/config-inspector` to inspect the resolved config interactively
export default createConfigForNuxt({
features: {
// Rules for module authors
tooling: true,
// Rules for formatting
stylistic: true,
},
dirs: {
src: [
'./playground',
],
},
})
.append(
// your custom flat config here...
)
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "my-module",
"version": "1.0.0",
"description": "My new Nuxt module",
"repository": "your-org/my-module",
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"scripts": {
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch",
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
},
"dependencies": {
"@nuxt/kit": "^3.14.159" },
"devDependencies": {
"@nuxt/devtools": "^1.6.0",
"@nuxt/eslint-config": "^0.6.1",
"@nuxt/module-builder": "^0.8.4",
"@nuxt/schema": "^3.14.159",
"@nuxt/test-utils": "^3.14.4",
"@types/node": "latest",
"changelogen": "^0.5.7",
"eslint": "^9.14.0",
"nuxt": "^3.14.159",
"typescript": "latest",
"vitest": "^2.1.5",
"vue-tsc": "^2.1.10"
}
}
14 changes: 14 additions & 0 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div>
Nuxt module playground!

<p>{{ status }}</p>
<p v-if="status === 'success'">Your country is: {{ data }}</p>

Check warning on line 6 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break after opening tag (`<p>`), but no line breaks found

Check warning on line 6 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break before closing tag (`</p>`), but no line breaks found
<p v-if="status === 'error'">Error: {{ data }}</p>

Check warning on line 7 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break after opening tag (`<p>`), but no line breaks found

Check warning on line 7 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break before closing tag (`</p>`), but no line breaks found
<button @click="refresh">Refresh</button>

Check warning on line 8 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break after opening tag (`<button>`), but no line breaks found

Check warning on line 8 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break before closing tag (`</button>`), but no line breaks found
</div>
</template>

<script setup>
const { data, refresh, status } = await useUserCountry();

Check failure on line 13 in playground/app.vue

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
</script>
5 changes: 5 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default defineNuxtConfig({
modules: ['../src/module'],
devtools: { enabled: true },
compatibilityDate: '2024-11-15',
})

Check failure on line 5 in playground/nuxt.config.ts

View workflow job for this annotation

GitHub Actions / lint

Newline required at end of file but not found
13 changes: 13 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "my-module-playground",
"type": "module",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"dependencies": {
"nuxt": "^3.14.159"
}
}
3 changes: 3 additions & 0 deletions playground/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
3 changes: 3 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}
27 changes: 27 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineNuxtModule, createResolver, addImportsDir } from "@nuxt/kit";

Check failure on line 1 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 1 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
import { defu } from "defu";

Check failure on line 2 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 2 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

export interface ModuleOptions {
endpoint: string;

Check failure on line 5 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected separator (;)
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: "User Country",

Check failure on line 10 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
configKey: "userCountry",

Check failure on line 11 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
},
defaults: {
endpoint: "https://where-am-i.jamflow.app/",

Check failure on line 14 in src/module.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
},
setup(_options, _nuxt) {
const resolver = createResolver(import.meta.url);
_nuxt.options.runtimeConfig.public.userCountry = defu(
_nuxt.options.runtimeConfig.public.userCountry,
{
endpoint: _options.endpoint,
}
);

addImportsDir(resolver.resolve("./runtime/composables"));
},
});
Loading

0 comments on commit e18d40a

Please sign in to comment.