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

Migrate to vue 3 + vite / vitest / vitepress for building #3565

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
073491d
Use vite instead of webpack for building the library
susnux Nov 27, 2022
74ae111
Move from jest to vitest for better integration with vite
susnux Nov 27, 2022
bdc5a3d
Move to vue-doc-gen + vitepress instead of styleguide
susnux Nov 27, 2022
8b17cc4
Upgrade cypress to version 11.2.0 to work with vite
susnux Nov 27, 2022
7e8d4b7
Beaking change: Only build one entrypoint
susnux Nov 27, 2022
1223608
Fix lint issues
susnux Dec 4, 2022
0a04055
Fix netlify build until its configuration is updated
susnux Dec 5, 2022
bc230c6
Migrate to vue 3
raimund-schluessler Apr 2, 2022
31117fd
Fix remaining merge issues
susnux Dec 6, 2022
80c4cbd
Fix styleguide + documentation examples for vue3
susnux Dec 6, 2022
6714bd9
Fix eslint errors
raimund-schluessler Dec 12, 2022
d402cd5
Add missing export for NcTimezonePicker
susnux Dec 12, 2022
8afd17b
vue3: Fix `NcColorPicker` for vue 3 compatibility
susnux Dec 12, 2022
8d1f8ff
Fix vue-live layout for NcContent examples
susnux Dec 12, 2022
d72e846
Adjust visual tests CSS import path + Fix assets path
raimund-schluessler Dec 13, 2022
6923e11
Inject process env on build
susnux Dec 14, 2022
387e21c
Fix deprecated title usage in NcAppNavigationItem
raimund-schluessler Jan 11, 2023
a105803
Fix lint warnings
raimund-schluessler Jan 11, 2023
5663c71
fix: vitepress documentation build | update dependencies
susnux Jan 30, 2023
f86181a
Fix NcActions inline action rendering
raimund-schluessler Jan 30, 2023
6127d9e
Run npm install
raimund-schluessler Jan 30, 2023
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {
oc_userconfig: true,
appName: true,
appVersion: true,
TRANSLATIONS: true,
SCOPE_VERSION: true,
},
extends: [
'@nextcloud',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-styling-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- name: Download css
run: |
cd styleguide/assets
cd docs/.vitepress/theme/assets
# Fix img css import
curl https://nextcloud.github.io/server/apps/theming/css/default.css | sed 's|/apps/theming/img|./img|g' > default.css
# Fix icons and img css import
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ yarn-error.log*
# Unit test / coverage reports
coverage

# genereated file
docs/components
docs/.vitepress

# Docs compiled build
styleguide/build/
styleguide/index.html
styleguide/*

# Cypress files
cypress/videos
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ stylelint-fix:
clean:
rm -rf dist/
rm -rf src/fonts/
rm -rf styleguide/build/

clean-dev:
rm -rf node_modules
Expand Down
42 changes: 21 additions & 21 deletions build/extract-l10n.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
const { GettextExtractor, JsExtractors } = require('gettext-extractor');
const { GettextExtractor, JsExtractors } = require('gettext-extractor')

let extractor = new GettextExtractor();
const extractor = new GettextExtractor()

extractor
.createJsParser([
JsExtractors.callExpression('t', {
arguments: {
text: 0,
}
}),
JsExtractors.callExpression('n', {
arguments: {
text: 0,
textPlural: 1,
}
}),
])
.parseFilesGlob('./src/**/*.@(ts|js|vue)');
.createJsParser([
JsExtractors.callExpression('t', {
arguments: {
text: 0,
},
}),
JsExtractors.callExpression('n', {
arguments: {
text: 0,
textPlural: 1,
},
}),
])
.parseFilesGlob('./src/**/*.@(ts|js|vue)')

// remove references to avoid conflicts
extractor.getMessages().forEach((msg) => {
msg.references = [];
});

extractor.savePotFile('./l10n/messages.pot');
msg.references = []
})

extractor.printStats();
extractor.savePotFile('./l10n/messages.pot')

extractor.printStats()
7 changes: 0 additions & 7 deletions build/usernameToColor-export.js

This file was deleted.

39 changes: 3 additions & 36 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
import { defineConfig } from 'cypress'
import { DefinePlugin } from 'webpack'
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin'
import path from 'path'
import webpackConfig from '@nextcloud/webpack-vue-config'
import webpackRules from '@nextcloud/webpack-vue-config/rules'

import { loadTranslations } from './resources/translations'

const SCOPE_VERSION = Date.now()
webpackRules.RULE_SCSS.use.push({
loader: 'sass-loader',
options: {
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
/**
* ! needed for resolve-url-loader
*/
sourceMap: true,
sassOptions: {
sourceMapContents: false,
includePaths: [
path.resolve(__dirname, './src/assets'),
],
},
},
})

webpackConfig.module.rules = Object.values(webpackRules)
import viteConfig from './vite.config.mjs'

export default defineConfig({
projectId: '3paxvy',
Expand Down Expand Up @@ -67,17 +43,8 @@ export default defineConfig({

devServer: {
framework: 'vue',
bundler: 'webpack',
webpackConfig: async () => {
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))
webpackConfig.plugins.push(new DefinePlugin({
PRODUCTION: false,
SCOPE_VERSION,
TRANSLATIONS: JSON.stringify(translations),
}))

return webpackConfig
},
bundler: 'vite',
viteConfig,
},
},
})
2 changes: 1 addition & 1 deletion cypress/support/component-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<body>
<div data-cy-root></div>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions cypress/visual/NcAppSidebar/NcAppSidebar-compact.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Raimund Schlüßler <[email protected]>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,6 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import BuildAppSidebarTest from './NcAppSidebarMixin'
import BuildAppSidebarTest from './NcAppSidebarMixin.js'

BuildAppSidebarTest(true)
4 changes: 2 additions & 2 deletions cypress/visual/NcAppSidebar/NcAppSidebar.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Raimund Schlüßler <[email protected]>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,6 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import BuildAppSidebarTest from './NcAppSidebarMixin'
import BuildAppSidebarTest from './NcAppSidebarMixin.js'

BuildAppSidebarTest(false)
4 changes: 2 additions & 2 deletions cypress/visual/NcAppSidebar/NcAppSidebarMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import NcAppSidebar from '../../../src/components/NcAppSidebar/NcAppSidebar.vue'
import NcActionButton from '../../../src/components/NcActionButton/NcActionButton.vue'

// Server CSS styles
import '../../../styleguide/assets/icons.css'
import '../../../styleguide/assets/additional.css'
import '../../../docs/.vitepress/theme/assets/icons.css'
import '../../../docs/.vitepress/theme/assets/additional.css'

/**
* We need this custom style because we run the AppSidebar component without a Content component,
Expand Down
24 changes: 24 additions & 0 deletions docgen.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { defineConfig } = require('vue-docgen-cli')
const fs = require('fs')

const generatePages = () => {
const path = 'src/components'
return fs.readdirSync(path)
.filter(file => fs.statSync(`${path}/${file}`).isDirectory())
.map(file => {
return {
components: `${file}/*.vue`,
outFile: `${file}.md`,
}
})
}

module.exports = defineConfig({
componentsRoot: 'src/components',
docsRepo: 'nextcloud/nextcloud-vue',
docsBranch: 'master',
editLinkLabel: 'Fork me on GitHub',
outDir: 'docs/components',

pages: generatePages(),
})
110 changes: 110 additions & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import * as path from "path";
import * as fs from 'fs'
import { fileURLToPath } from "url";
import { defineConfig } from "vitepress";
import { SearchPlugin } from 'vitepress-plugin-search'
import PackageJSON from '../../package.json'
import vueLiveMd from './vue-live-md-it.mjs'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const version = PackageJSON.version
const docsPath = path.resolve(__dirname, '..')

/**
* Generate list of all components grouped by functionality for sidebar menu
*
* @returns {import('vitepress').DefaultTheme.SidebarItem[]}
*/
function getComponents() {
const sections = {}

fs.readdirSync(path.resolve(docsPath, 'components'))
.forEach(file => {
const name = file.replace('.md', '')
const words = name.split(/(?=[A-Z])/)
const section = words
.slice(0, (words[1] === 'App' && words.length >= 3 ? 3 : 2))
.join('')
.replace(/s$/, '') // fix NcActions
if (!(section in sections)) sections[section] = []
sections[section].push(name)
})

return Object.keys(sections)
.sort()
.map(section => {
// Get base component as first entry, sort is not enogh because of `NcActions` vs `NcActionX`
const first = sections[section].sort((p, q) => p.length - q.length)[0]
const other = sections[section].filter(p => p !== first).sort()
return {
text: section,
items: [
first,
...other
].map(file => ({ text: file, link: `/components/${file}` }))
}
})
}


// Plugin for stripping out <docs> sections from vue files
const vueDocsPlugin = {
name: 'vue-i18n',
transform(code, id) {
if (!/vue&type=doc/.test(id)) {
return
}
return 'export default ""'
},
}

export default defineConfig({
title: '@nextcloud/vue',
description: 'Vue.js components for Nextcloud app development',

ignoreDeadLinks: true,

themeConfig: {
logo: 'https://nextcloud.com/wp-content/uploads/2022/10/nextcloud-logo-blue-transparent.svg',
nav: [
{
text: `${version}`, items: [
{ text: 'Changelog', link: `https://github.com/nextcloud/nextcloud-vue/blob/v${version}/CHANGELOG.md` },
]
},
],
sidebar: [
{
text: 'Components',
collapsible: true,
collapsed: true,
items: getComponents(),
},
{
items: [{
text: 'Directives',
link: '/directives'
}]
},
],
socialLinks: [
{
icon: 'github',
link: 'https://github.com/nextcloud/nextcloud-vue'
}
],
},

outDir: '../styleguide',
vite: {
plugins: [vueDocsPlugin, SearchPlugin()],
},

markdown: {
config(md){
md.use(vueLiveMd)
},
},
})
Loading