diff --git a/.gitignore b/.gitignore index 213f0996..fbd040db 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ yarn-error.log* dist dist-ssr .cache +**/.vitepress/cache/ .rpt2_cache .yarn diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..bf2e7648 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +shamefully-hoist=true diff --git a/package.json b/package.json index 4dc848f1..a44f6ba9 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "packages/*" ], "scripts": { - "dev:vue2-firestore": "pnpm --filter dev-vue2-firestore dev", + "dev:nuxt-firestore": "pnpm --filter dev-nuxt-firestore dev", "dev:vue3-firestore": "pnpm --filter dev-vue3-firestore dev", + "dep:del-all": "npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules", "dep:update-minor": "ncu --target minor -u && pnpm --parallel exec ncu --target minor -u && echo \"review git changes and install with ni\"", "dep:update-major": "ncu -u && pnpm --parallel exec ncu -u && echo \"review git changes and install with ni\"", "docs:dev": "vitepress dev docs", @@ -15,6 +16,9 @@ "docs:serve": "vitepress serve docs", "build": "pnpm -r build", "build-and-commit": "npm run build && git add -A && git commit -m \"chore: build\"", + "build:nuxt-firestore": "pnpm --filter dev-nuxt-firestore build", + "generate:nuxt-firestore": "pnpm --filter dev-nuxt-firestore generate", + "preview:nuxt-firestore": "pnpm --filter dev-nuxt-firestore preview", "typecheck": "tsc --noEmit", "test": "pnpm test:core && pnpm test:plugin-simple-store && pnpm test:plugin-vue2 && pnpm test:plugin-vue3 && pnpm test:plugin-firestore", "_test:admin-broken": "pnpm test:core && pnpm test:plugin-simple-store && pnpm test:plugin-vue2 && pnpm test:plugin-vue3 && pnpm test:plugin-firestore-admin", @@ -30,25 +34,25 @@ }, "devDependencies": { "@types/node": "^18.11.9", - "@typescript-eslint/eslint-plugin": "^5.42.1", - "@typescript-eslint/parser": "^5.42.1", + "@typescript-eslint/eslint-plugin": "^5.49.0", + "@typescript-eslint/parser": "^5.49.0", "ava": "^4.3.3", "bumpp": "^8.2.1", "copyfiles": "^2.4.1", "esbuild": "^0.15.13", "esbuild-register": "^3.4.1", - "eslint": "^8.27.0", + "eslint": "^8.33.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-tree-shaking": "^1.10.0", "exec-sh": "^0.4.0", "npm-check-updates": "^16.3.25", - "prettier": "^2.7.1", + "prettier": "^2.8.3", "rimraf": "^3.0.2", "tslib": "^2.4.1", "tsup": "^6.4.0", "turbo": "^1.6.3", - "typescript": "^4.8.4", - "vitepress": "1.0.0-alpha.28" + "typescript": "^4.9.4", + "vitepress": "1.0.0-alpha.43" }, "author": "Luca Ban - Mesqueeb", "funding": "https://github.com/sponsors/mesqueeb", @@ -75,6 +79,7 @@ "ignorePatterns": [ "node_modules", "dist", + "/packages/dev-nuxt-firestore", "/packages/dev-firestore", "/packages/dev-vue2", "/packages/dev-vue2-firestore", diff --git a/packages/dev-nuxt-firestore/.gitignore b/packages/dev-nuxt-firestore/.gitignore new file mode 100644 index 00000000..438cb086 --- /dev/null +++ b/packages/dev-nuxt-firestore/.gitignore @@ -0,0 +1,8 @@ +node_modules +*.log* +.nuxt +.nitro +.cache +.output +.env +dist diff --git a/packages/dev-nuxt-firestore/README.md b/packages/dev-nuxt-firestore/README.md new file mode 100644 index 00000000..d4b81ef6 --- /dev/null +++ b/packages/dev-nuxt-firestore/README.md @@ -0,0 +1,3 @@ +# dev-vue3-firestore + +🚧 This is WIP diff --git a/packages/dev-nuxt-firestore/app.vue b/packages/dev-nuxt-firestore/app.vue new file mode 100644 index 00000000..d01de097 --- /dev/null +++ b/packages/dev-nuxt-firestore/app.vue @@ -0,0 +1,14 @@ + + + + + + + diff --git a/packages/dev-nuxt-firestore/assets/style.css b/packages/dev-nuxt-firestore/assets/style.css new file mode 100644 index 00000000..0192f9aa --- /dev/null +++ b/packages/dev-nuxt-firestore/assets/style.css @@ -0,0 +1,81 @@ +:root { + font-family: Inter, Avenir, Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 24px; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +.card { + padding: 2em; +} + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/packages/dev-nuxt-firestore/components/ButtonToggle.vue b/packages/dev-nuxt-firestore/components/ButtonToggle.vue new file mode 100644 index 00000000..fda576ae --- /dev/null +++ b/packages/dev-nuxt-firestore/components/ButtonToggle.vue @@ -0,0 +1,57 @@ + + + + + + emit('update:modelValue', o.value)" + > + {{ o.label }} + + + + + + diff --git a/packages/dev-nuxt-firestore/components/TestFirestorePluginFetch.vue b/packages/dev-nuxt-firestore/components/TestFirestorePluginFetch.vue new file mode 100644 index 00000000..3b87dfa1 --- /dev/null +++ b/packages/dev-nuxt-firestore/components/TestFirestorePluginFetch.vue @@ -0,0 +1,83 @@ + + + + + plugin-vue3 + plugin-firestore Todo list ({{ size }}) + + show done items + + alphabetically + + + + fetchMore()">fetch more + reached end: {{ query.fetched.reachedEnd }} + + diff --git a/packages/dev-nuxt-firestore/components/TestFirestorePluginStream.vue b/packages/dev-nuxt-firestore/components/TestFirestorePluginStream.vue new file mode 100644 index 00000000..4493b674 --- /dev/null +++ b/packages/dev-nuxt-firestore/components/TestFirestorePluginStream.vue @@ -0,0 +1,79 @@ + + + + + plugin-vue3 + plugin-firestore Todo list ({{ size }}) + + show done items + + alphabetically + + + + + diff --git a/packages/dev-nuxt-firestore/components/TodoApp.vue b/packages/dev-nuxt-firestore/components/TodoApp.vue new file mode 100644 index 00000000..38b4abfd --- /dev/null +++ b/packages/dev-nuxt-firestore/components/TodoApp.vue @@ -0,0 +1,117 @@ + + + + + + toggleItemDone(item)"> + {{ item.isDone ? '☑️' : '◻️' }} + + + editItem(i)">{{ item.title }} + saveEdits()" + /> + + saveEdits()">✅ + editItem(i)">✏️ + deleteItem(item)">❌ + + + addItem()" /> + addItem()">➕ + + + + + diff --git a/packages/dev-nuxt-firestore/nuxt.config.ts b/packages/dev-nuxt-firestore/nuxt.config.ts new file mode 100644 index 00000000..7a34e34f --- /dev/null +++ b/packages/dev-nuxt-firestore/nuxt.config.ts @@ -0,0 +1,31 @@ +/** + * NOTE: + * avoid typedef errors due to `tsc --noEmit`. + * `defineNuxtConfig` is defined by default in IDE like vscode. + */ +import { defineNuxtConfig } from 'nuxt/config' + +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + runtimeConfig: { + public: { + apiKey: 'AIzaSyDivMlXIuHqDFsTCCqBDTVL0h29xbltcL8', + authDomain: 'tests-firestore.firebaseapp.com', + databaseURL: 'https://tests-firestore.firebaseio.com', + projectId: 'tests-firestore', + }, + }, + css: ['~/assets/style.css'], + /** + * NOTE: + * 'fast-sort' is provided by CommonJS module as default. + * Nuxt 3 need to require ES Modules. + * https://nuxt.com/docs/guide/concepts/esm#troubleshooting-esm-issues + */ + build: { + transpile: ['fast-sort'], + }, + modules: [ + '@nuxt/devtools' + ] +}) diff --git a/packages/dev-nuxt-firestore/nuxt.d.ts b/packages/dev-nuxt-firestore/nuxt.d.ts new file mode 100644 index 00000000..36070a6e --- /dev/null +++ b/packages/dev-nuxt-firestore/nuxt.d.ts @@ -0,0 +1,10 @@ +declare module '#app' { + interface NuxtApp { + payload: { + // add payload for magnetar SSR + magnetar: Record + } + } +} + +export {} diff --git a/packages/dev-nuxt-firestore/package.json b/packages/dev-nuxt-firestore/package.json new file mode 100644 index 00000000..21f56d24 --- /dev/null +++ b/packages/dev-nuxt-firestore/package.json @@ -0,0 +1,22 @@ +{ + "name": "dev-nuxt-firestore", + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "dependencies": { + "@magnetarjs/core": "workspace:*", + "@magnetarjs/plugin-firestore": "workspace:*", + "@magnetarjs/plugin-vue3": "workspace:*", + "firebase": "^9.14.0" + }, + "devDependencies": { + "nuxt": "^3.2.3", + "@nuxt/devtools": "^0.2.4", + "vue": "^3.2.45" + } +} diff --git a/packages/dev-nuxt-firestore/pages/index.vue b/packages/dev-nuxt-firestore/pages/index.vue new file mode 100644 index 00000000..c9cc284d --- /dev/null +++ b/packages/dev-nuxt-firestore/pages/index.vue @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/packages/dev-nuxt-firestore/plugins/magetar.ts b/packages/dev-nuxt-firestore/plugins/magetar.ts new file mode 100644 index 00000000..4f4cd331 --- /dev/null +++ b/packages/dev-nuxt-firestore/plugins/magetar.ts @@ -0,0 +1,46 @@ +import { initializeApp } from 'firebase/app' +import { getFirestore, collection, doc } from 'firebase/firestore' +import { Magnetar } from '@magnetarjs/core' +import { CreatePlugin as PluginFirestore } from '@magnetarjs/plugin-firestore' +import { CreatePlugin as PluginVue3 } from '@magnetarjs/plugin-vue3' + +export default defineNuxtPlugin((nuxtApp) => { + const config = useRuntimeConfig() + const firebaseApp = initializeApp(config.public) + const db = getFirestore(firebaseApp) + + const generateRandomId = (): string => doc(collection(db, 'random')).id + + // create the local store plugin instance + const local = PluginVue3({ generateRandomId }) + // create the remote store plugin instance + const remote = PluginFirestore({ db }) + + // instantiate the Magnetar instance with the store plugins + const magnetar = Magnetar({ + stores: { local, remote }, + localStoreName: 'local', + executionOrder: { + read: ['local', 'remote'], + write: ['local', 'remote'], + delete: ['local', 'remote'], + }, + }) + + /** + * TODO: hydration for SSR + */ + if (process.server) { + // collect the initial state + nuxtApp.payload.magnetar = {} + } else if (nuxtApp.payload?.magnetar) { + // ... hydrate the state + } + + return { + provide: { + magnetar, + generateRandomId, + }, + } +}) diff --git a/packages/dev-nuxt-firestore/tsconfig.json b/packages/dev-nuxt-firestore/tsconfig.json new file mode 100644 index 00000000..a746f2a7 --- /dev/null +++ b/packages/dev-nuxt-firestore/tsconfig.json @@ -0,0 +1,4 @@ +{ + // https://nuxt.com/docs/guide/concepts/typescript + "extends": "./.nuxt/tsconfig.json" +} diff --git a/packages/dev-vue2-firestore/.eslintignore b/packages/dev-vue2-firestore/.eslintignore deleted file mode 100644 index e18a6734..00000000 --- a/packages/dev-vue2-firestore/.eslintignore +++ /dev/null @@ -1,17 +0,0 @@ -# don't ever lint node_modules -node_modules -# don't lint build output (make sure it's set to your correct build folder name) -dist -# don't lint nyc coverage output -coverage - -/test/**.* -test -.eslintrc.js - -/dist -/src-bex/www -/src-capacitor -/src-cordova -/.quasar -/node_modules diff --git a/packages/dev-vue2-firestore/.gitignore b/packages/dev-vue2-firestore/.gitignore deleted file mode 100644 index 23efb531..00000000 --- a/packages/dev-vue2-firestore/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -.DS_Store -node_modules -/dist -dist - -# local env files -.env.local -.env.*.local - -# Log files -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/packages/dev-vue2-firestore/.prettierrc b/packages/dev-vue2-firestore/.prettierrc deleted file mode 100644 index d7a23054..00000000 --- a/packages/dev-vue2-firestore/.prettierrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "printWidth": 100, - "tabWidth": 2, - "singleQuote": true, - "trailingComma": "es5", - "semi": false, - "bracketSpacing": true, - "arrowParens": "always", - "quoteProps": "consistent", - "vueIndentScriptAndStyle": false -} diff --git a/packages/dev-vue2-firestore/README.md b/packages/dev-vue2-firestore/README.md deleted file mode 100644 index 559516de..00000000 --- a/packages/dev-vue2-firestore/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# dev-vue2 - -## Project setup -``` -npm install -``` - -### Compiles and hot-reloads for development -``` -npm run serve -``` - -### Compiles and minifies for production -``` -npm run build -``` - -### Lints and fixes files -``` -npm run lint -``` - -### Customize configuration -See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/packages/dev-vue2-firestore/babel.config.js b/packages/dev-vue2-firestore/babel.config.js deleted file mode 100644 index c1b783ea..00000000 --- a/packages/dev-vue2-firestore/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: ['@vue/cli-plugin-babel/preset'], -} diff --git a/packages/dev-vue2-firestore/package.json b/packages/dev-vue2-firestore/package.json deleted file mode 100644 index 30d9d7c9..00000000 --- a/packages/dev-vue2-firestore/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "dev-vue2-firestore", - "version": "0.11.3", - "private": true, - "scripts": { - "dev": "vue-cli-service serve", - "build--": "vue-cli-service build" - }, - "dependencies": { - "@magnetarjs/plugin-vue2": "workspace:*", - "core-js": "^3.26.1", - "firebase": "^9.14.0", - "magnetar": "workspace:*", - "vue": "^2.7.14" - }, - "devDependencies": { - "@vue/cli-plugin-babel": "~4.5.19", - "@vue/cli-plugin-vuex": "~4.5.19", - "@vue/cli-service": "~4.5.19", - "sass": "^1.56.1", - "sass-loader": "^10.3.1", - "vue-template-compiler": "^2.7.14" - }, - "browserslist": [ - "> 1%", - "last 2 versions", - "not dead" - ] -} diff --git a/packages/dev-vue2-firestore/public/favicon.ico b/packages/dev-vue2-firestore/public/favicon.ico deleted file mode 100644 index df36fcfb..00000000 Binary files a/packages/dev-vue2-firestore/public/favicon.ico and /dev/null differ diff --git a/packages/dev-vue2-firestore/public/index.html b/packages/dev-vue2-firestore/public/index.html deleted file mode 100644 index 41235286..00000000 --- a/packages/dev-vue2-firestore/public/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - <%= htmlWebpackPlugin.options.title %> - - - - We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue. - - - - - diff --git a/packages/dev-vue2-firestore/src/App.vue b/packages/dev-vue2-firestore/src/App.vue deleted file mode 100644 index 3e8e2af8..00000000 --- a/packages/dev-vue2-firestore/src/App.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - diff --git a/packages/dev-vue2-firestore/src/assets/logo.png b/packages/dev-vue2-firestore/src/assets/logo.png deleted file mode 100644 index f3d2503f..00000000 Binary files a/packages/dev-vue2-firestore/src/assets/logo.png and /dev/null differ diff --git a/packages/dev-vue2-firestore/src/components/TestManual.vue b/packages/dev-vue2-firestore/src/components/TestManual.vue deleted file mode 100644 index acae95ff..00000000 --- a/packages/dev-vue2-firestore/src/components/TestManual.vue +++ /dev/null @@ -1,51 +0,0 @@ - - - manual implementation: - {{ itemsModuleData }} - - - - - - - diff --git a/packages/dev-vue2-firestore/src/components/TestVue2Plugin.vue b/packages/dev-vue2-firestore/src/components/TestVue2Plugin.vue deleted file mode 100644 index a0008d81..00000000 --- a/packages/dev-vue2-firestore/src/components/TestVue2Plugin.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - plugin-vue2 Todo list ({{ size }}) - - show done items - - alphabetically - - - - - - - - - diff --git a/packages/dev-vue2-firestore/src/components/TodoApp.vue b/packages/dev-vue2-firestore/src/components/TodoApp.vue deleted file mode 100644 index 557cee8b..00000000 --- a/packages/dev-vue2-firestore/src/components/TodoApp.vue +++ /dev/null @@ -1,114 +0,0 @@ - - - - {{ item.isDone ? '☑️' : '◻️' }} - - {{ item.title }} - - - ✅ - ✏️ - ❌ - - - - ➕ - - - - - - - diff --git a/packages/dev-vue2-firestore/src/components/_Template.vue b/packages/dev-vue2-firestore/src/components/_Template.vue deleted file mode 100644 index 7f8d3d15..00000000 --- a/packages/dev-vue2-firestore/src/components/_Template.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - diff --git a/packages/dev-vue2-firestore/src/initFirebase.js b/packages/dev-vue2-firestore/src/initFirebase.js deleted file mode 100644 index f18c1161..00000000 --- a/packages/dev-vue2-firestore/src/initFirebase.js +++ /dev/null @@ -1,13 +0,0 @@ -import { initializeApp } from 'firebase/app' -import { getFirestore } from 'firebase/firestore' - -const config = { - apiKey: 'AIzaSyDivMlXIuHqDFsTCCqBDTVL0h29xbltcL8', - authDomain: 'tests-firestore.firebaseapp.com', - databaseURL: 'https://tests-firestore.firebaseio.com', - projectId: 'tests-firestore', - // storageBucket: 'tests-firestore.appspot.com', - // messagingSenderId: '743555674736' -} -const firebaseApp = initializeApp(config) -export const db = getFirestore(firebaseApp) diff --git a/packages/dev-vue2-firestore/src/magnetar.js b/packages/dev-vue2-firestore/src/magnetar.js deleted file mode 100644 index e9a6d4f7..00000000 --- a/packages/dev-vue2-firestore/src/magnetar.js +++ /dev/null @@ -1,28 +0,0 @@ -// --------------------------------------- -// plugin vue2 for local data store -// --------------------------------------- -import { Magnetar, PluginFirestore } from 'magnetar' -import { CreatePlugin as CreatePluginVue2 } from '@magnetarjs/plugin-vue2' -import Vue from 'vue' -import { db } from './initFirebase' - -const vueInstance = Vue -const generateRandomId = () => Math.random().toString() - -// create the local store plugin instance: -const local = CreatePluginVue2({ vueInstance, generateRandomId }) - -const remote = PluginFirestore.CreatePlugin({ db }) - -// ----------------------------------------------------- -// instantiate the Magnetar instance with the store plugins -// ----------------------------------------------------- -export const magnetar = Magnetar({ - stores: { local, remote }, - localStoreName: 'local', - executionOrder: { - read: ['local', 'remote'], - write: ['local', 'remote'], - delete: ['local', 'remote'], - }, -}) diff --git a/packages/dev-vue2-firestore/src/main.js b/packages/dev-vue2-firestore/src/main.js deleted file mode 100644 index dd079f8d..00000000 --- a/packages/dev-vue2-firestore/src/main.js +++ /dev/null @@ -1,8 +0,0 @@ -import Vue from 'vue' -import App from './App.vue' - -Vue.config.productionTip = false - -new Vue({ - render: (h) => h(App), -}).$mount('#app') diff --git a/packages/dev-vue3-firestore/package.json b/packages/dev-vue3-firestore/package.json index 826b6012..d91006fb 100644 --- a/packages/dev-vue3-firestore/package.json +++ b/packages/dev-vue3-firestore/package.json @@ -13,9 +13,10 @@ "vue": "^3.2.45" }, "devDependencies": { - "@vitejs/plugin-vue": "^3.2.0", - "typescript": "^4.8.4", - "vite": "^3.2.3", - "vue-tsc": "^1.0.9" + "@vitejs/plugin-vue": "^4.0.0", + "typescript": "^4.9.4", + "vite": "^4.0.4", + "sass": "^1.57.1", + "vue-tsc": "^1.0.24" } } diff --git a/packages/dev-vue3-firestore/src/components/TodoApp.vue b/packages/dev-vue3-firestore/src/components/TodoApp.vue index 882d3cf0..7d7dcd4a 100644 --- a/packages/dev-vue3-firestore/src/components/TodoApp.vue +++ b/packages/dev-vue3-firestore/src/components/TodoApp.vue @@ -1,5 +1,5 @@
{{ itemsModuleData }}