@sb1/ffe-vite-less 1.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 SpareBank 1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @sb1/ffe-vite-less
2
+
3
+ En Vite-plugin som automatisk injiserer FFE LESS-importer i LESS-filene dine.
4
+
5
+ ## Installasjon
6
+
7
+ ```bash
8
+ npm install --save-dev @sb1/ffe-vite-less
9
+ # eller
10
+ yarn add -D @sb1/ffe-vite-less
11
+ ```
12
+
13
+ ## Bruk
14
+
15
+ Legg til pluginen i din `vite.config.ts`:
16
+
17
+ ```typescript
18
+ import { defineConfig } from 'vite';
19
+ import ffeLessPlugin from '@sb1/ffe-vite-less';
20
+
21
+ export default defineConfig({
22
+ plugins: [ffeLessPlugin()],
23
+ });
24
+ ```
25
+
26
+ ### Alternativer
27
+
28
+ Pluginen aksepterer følgende alternativer:
29
+
30
+ - `nodeModulesPath`: Egendefinert sti til node_modules-mappen. Hvis ikke angitt, vil standard node_modules-sti brukes.
31
+
32
+ ```typescript
33
+ ffeLessPlugin({
34
+ nodeModulesPath: '/egendefinert/sti/til/node_modules/@sb1',
35
+ });
36
+ ```
37
+
38
+ ## Hvordan det fungerer
39
+
40
+ Pluginen injiserer automatisk FFE LESS-importer i starten av LESS-filene dine. Den vil:
41
+
42
+ 1. Importere FFE core colors først
43
+ 2. Importere alle andre FFE LESS-filer som finnes i node_modules/@sb1
44
+ 3. Hoppe over filer som allerede inneholder FFE-importer
45
+ 4. Hoppe over ffe-core/less/variables.less for å unngå dupliserte importer
46
+
47
+ ## Lisens
48
+
49
+ MIT-lisens. Se LICENSE i README.md i hoved-FFE-repositoriet.
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface FfeLessPluginOptions {
3
+ nodeModulesPath?: string;
4
+ }
5
+ export declare function ffeLessPlugin(options?: FfeLessPluginOptions): Plugin;
package/lib/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import { resolve, dirname } from 'path';
2
+ import { glob } from 'glob';
3
+ import { existsSync } from 'fs';
4
+ async function collectFfeImports(nodeModulesPath) {
5
+ // Core imports that should be included first
6
+ const coreImports = ['@import "@sb1/ffe-core/less/ffe";'];
7
+ // Find all other LESS files
8
+ const lessFiles = await glob('**/less/*.less', {
9
+ cwd: resolve(nodeModulesPath, '@sb1'),
10
+ ignore: ['**/node_modules/**', '**/ffe-core/less/ffe.less'],
11
+ absolute: true,
12
+ });
13
+ // Create imports for component files
14
+ const componentImports = lessFiles.map(file => {
15
+ const relativePath = file.replace(`${nodeModulesPath}/`, '');
16
+ return `@import "${relativePath}";`;
17
+ });
18
+ return [...coreImports, ...componentImports].join('\n');
19
+ }
20
+ export function ffeLessPlugin(options = {}) {
21
+ let nodeModulesPath;
22
+ return {
23
+ name: 'ffe-vite-less',
24
+ enforce: 'pre',
25
+ configResolved(config) {
26
+ // Try to find node_modules in various locations
27
+ const possiblePaths = [
28
+ options.nodeModulesPath,
29
+ resolve(process.cwd(), 'node_modules'),
30
+ resolve(dirname(config.configFile || process.cwd()), 'node_modules'),
31
+ resolve(process.cwd(), '../../node_modules'),
32
+ ].filter((path) => typeof path === 'string');
33
+ for (const path of possiblePaths) {
34
+ if (existsSync(path)) {
35
+ nodeModulesPath = path;
36
+ break;
37
+ }
38
+ }
39
+ if (!nodeModulesPath) {
40
+ throw new Error('Could not find node_modules directory');
41
+ }
42
+ },
43
+ config(config) {
44
+ if (!nodeModulesPath) {
45
+ return {};
46
+ }
47
+ const sb1Path = resolve(nodeModulesPath, '@sb1');
48
+ return {
49
+ css: {
50
+ preprocessorOptions: {
51
+ less: {
52
+ javascriptEnabled: true,
53
+ paths: [nodeModulesPath],
54
+ alias: {
55
+ '@sb1': sb1Path,
56
+ },
57
+ },
58
+ },
59
+ },
60
+ resolve: {
61
+ alias: {
62
+ '@sb1': sb1Path,
63
+ },
64
+ },
65
+ };
66
+ },
67
+ async transform(code, id) {
68
+ if (!id.endsWith('.less')) {
69
+ return null;
70
+ }
71
+ // Skip if the file already has FFE imports
72
+ if (code.includes('@import "@sb1/ffe-')) {
73
+ return null;
74
+ }
75
+ const ffeImports = await collectFfeImports(nodeModulesPath);
76
+ // Inject imports at the beginning of the file
77
+ return {
78
+ code: `${ffeImports}\n\n${code}`,
79
+ map: null,
80
+ };
81
+ },
82
+ };
83
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@sb1/ffe-vite-less",
3
+ "version": "1.0.1",
4
+ "description": "Vite plugin for automatically injecting FFE LESS imports",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./lib/index.js",
11
+ "require": "./lib/index.js",
12
+ "types": "./lib/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "lib"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "clean": "rimraf lib"
21
+ },
22
+ "dependencies": {
23
+ "glob": "^10.3.10"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.11.0",
27
+ "rimraf": "^6.0.1",
28
+ "typescript": "^5.3.3",
29
+ "vite": "5.4.18"
30
+ },
31
+ "peerDependencies": {
32
+ "less": "^4.0.0",
33
+ "vite": "^6.0.0"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "gitHead": "6489cbcc9424062999c71693d1e37e3832e74802"
39
+ }