@opencloud-eu/extension-sdk 3.2.0 → 4.1.0-alpha.1

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.
Files changed (2) hide show
  1. package/index.mjs +69 -26
  2. package/package.json +4 -5
package/index.mjs CHANGED
@@ -5,10 +5,10 @@
5
5
  import { mergeConfig, searchForWorkspaceRoot } from 'vite'
6
6
  import { join } from 'path'
7
7
  import { cwd } from 'process'
8
- import { readFileSync } from 'fs'
8
+ import { readFileSync, existsSync } from 'fs'
9
+ import tailwindcss from '@tailwindcss/vite'
9
10
 
10
11
  import vue from '@vitejs/plugin-vue'
11
- import serve from 'rollup-plugin-serve'
12
12
 
13
13
  const distDir = process.env.OPENCLOUD_EXTENSION_DIST_DIR || 'dist'
14
14
 
@@ -19,11 +19,70 @@ const defaultHttps = () =>
19
19
  cert: readFileSync(join(certsDir, 'server.crt'))
20
20
  }
21
21
 
22
+ const manifestFile = 'manifest.json'
23
+ const manifestPath = join('./src/', manifestFile)
24
+ const manifestPlugin = () => {
25
+ let outputDir
26
+
27
+ return {
28
+ name: 'manifest',
29
+ apply: 'build',
30
+ configResolved(config) {
31
+ outputDir = config.build.outDir
32
+ },
33
+ buildStart() {
34
+ this.addWatchFile(manifestPath)
35
+ },
36
+ generateBundle(options, bundle) {
37
+ const generatedManifestPath = join(outputDir, manifestFile)
38
+ if (existsSync(generatedManifestPath)) {
39
+ this.warn(
40
+ `${generatedManifestPath} already exists in output directory (likely from public/), skipping generation\n` +
41
+ `Consider using --emptyOutDir if outDir is outside of project root.`
42
+ )
43
+ return
44
+ }
45
+
46
+ // Find the entry chunk
47
+ const entryChunk = Object.values(bundle).find(
48
+ (chunk) => chunk.type === 'chunk' && chunk.isEntry
49
+ )
50
+
51
+ if (!entryChunk) {
52
+ this.error('No entry chunk found')
53
+ return
54
+ }
55
+
56
+ let manifest = {}
57
+ if (existsSync(manifestPath)) {
58
+ try {
59
+ manifest = JSON.parse(readFileSync(manifestPath).toString())
60
+ } catch (err) {
61
+ this.error(
62
+ `Failed to parse manifest.json at ${manifestPath}: ${err.message}\n` +
63
+ `Please ensure manifest.json contains a valid JSON object.`
64
+ )
65
+ return
66
+ }
67
+ }
68
+
69
+ // set entryPoint
70
+ manifest.entrypoint = entryChunk.fileName
71
+
72
+ // Add manifest.json to the bundle
73
+ this.emitFile({
74
+ type: 'asset',
75
+ fileName: 'manifest.json',
76
+ source: JSON.stringify(manifest, null, 2)
77
+ })
78
+ }
79
+ }
80
+ }
81
+
22
82
  export const defineConfig = (overrides = {}) => {
23
83
  return ({ mode }) => {
24
84
  const isProduction = mode === 'production'
25
85
  const isTesting = mode === 'test'
26
- const isServing = !isProduction && !isTesting
27
86
 
28
87
  // read package name from vite workspace
29
88
  const packageJson = JSON.parse(
@@ -32,20 +91,13 @@ export const defineConfig = (overrides = {}) => {
32
91
 
33
92
  const name = overrides.name || packageJson.name
34
93
 
35
- // take vite standard config and reuse it for rollup-plugin-serve config
36
- const { https = defaultHttps(), port = 9210, host = 'localhost' } = overrides?.server || {}
94
+ // set default config
95
+ const { https = defaultHttps(), port = 9210 } = overrides?.server || {}
37
96
  const isHttps = !!https
38
97
 
39
- if (isServing) {
40
- console.log(
41
- `>>> Serving extension at http${isHttps ? 's' : ''}://${host}:${port}/js/${name}.js`
42
- )
43
- }
44
-
45
98
  return mergeConfig(
46
99
  {
47
100
  server: {
48
- host,
49
101
  port,
50
102
  strictPort: true,
51
103
  ...(isHttps && https)
@@ -53,6 +105,7 @@ export const defineConfig = (overrides = {}) => {
53
105
  build: {
54
106
  cssCodeSplit: true,
55
107
  minify: isProduction,
108
+ outDir: distDir,
56
109
  rollupOptions: {
57
110
  // keep in sync with packages/web-runtime/src/container/application/index.ts
58
111
  external: [
@@ -77,21 +130,9 @@ export const defineConfig = (overrides = {}) => {
77
130
  },
78
131
  output: {
79
132
  format: 'amd',
80
- dir: distDir,
81
133
  chunkFileNames: join('js', 'chunks', '[name]-[hash].mjs'),
82
134
  entryFileNames: join('js', `[name]${isProduction ? '-[hash]' : ''}.js`)
83
- },
84
- plugins: [
85
- isServing &&
86
- serve({
87
- headers: {
88
- 'access-control-allow-origin': '*'
89
- },
90
- contentBase: distDir,
91
- ...(https && { https }),
92
- ...(port && { port })
93
- })
94
- ]
135
+ }
95
136
  }
96
137
  },
97
138
  plugins: [
@@ -99,7 +140,9 @@ export const defineConfig = (overrides = {}) => {
99
140
  // set to true when switching to esm
100
141
  customElement: false,
101
142
  ...(isTesting && { template: { compilerOptions: { whitespace: 'preserve' } } })
102
- })
143
+ }),
144
+ manifestPlugin(),
145
+ tailwindcss()
103
146
  ],
104
147
  test: {
105
148
  globals: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencloud-eu/extension-sdk",
3
- "version": "3.2.0",
3
+ "version": "4.1.0-alpha.1",
4
4
  "description": "OpenCloud Web Extension SDK",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "index.mjs",
@@ -14,11 +14,10 @@
14
14
  "directory": "packages/extension-sdk"
15
15
  },
16
16
  "dependencies": {
17
- "@vitejs/plugin-vue": "^6.0.0",
18
- "rollup-plugin-serve": "^3.0.0"
17
+ "@tailwindcss/vite": "^4.1.11",
18
+ "@vitejs/plugin-vue": "^6.0.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "vite": "^5 || ^6.0.0",
22
- "sass": "^1.79.5"
21
+ "vite": "^5 || ^6.0.0 || ^7.0.0"
23
22
  }
24
23
  }