-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1005 from dnum-mi/develop
Develop
- Loading branch information
Showing
34 changed files
with
460 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Preset Autoimport pour le plugin unplugin-auto-import pour les composables de VueDsfr | ||
*/ | ||
export const vueDsfrAutoimportPreset = Object.freeze({ | ||
from: '@gouvminint/vue-dsfr', | ||
imports: Object.freeze([ | ||
'useScheme', | ||
'useTabs', | ||
]), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Component resolver pour le plgin unplugin-vue-components pour les composants VueDsfr | ||
* | ||
* @function | ||
* @param {string} componentName - Nom du composant à chercher | ||
* | ||
* @returns {{ name: string, from: string } | undefined} Objet de retour pour le plugin unplugin-vue-components | ||
*/ | ||
export const vueDsfrComponentResolver = (componentName) => { | ||
if (componentName.startsWith('Dsfr') || componentName === 'VIcon') { | ||
return { | ||
name: componentName, | ||
from: '@gouvminint/vue-dsfr', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env node | ||
|
||
import path from 'node:path' | ||
import process from 'node:process' | ||
|
||
import { Command } from 'commander' | ||
import chalk from 'chalk' | ||
|
||
import { createCustomCollectionFile } from './custom-icon-collections-creator.js' | ||
|
||
const program = new Command() | ||
|
||
program | ||
.option('-s, --source <filepath>', 'Chemin vers le fichier de tuples [IconifyJSON, string[]]') | ||
.option('-t, --target <filepath>', 'Chemin vers le fichier destination (src/icons.ts par défaut)') | ||
.parse(process.argv) | ||
|
||
const options = program.opts() | ||
|
||
if (options.source && options.target) { | ||
createCustomCollectionFile(path.resolve(process.cwd(), options.source), path.resolve(process.cwd(), options.target)) | ||
console.log(chalk.green('Les icônes ont été générées')) // eslint-disable-line no-console | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// @ts-check | ||
/* eslint-disable no-console */ | ||
import childProcess from 'node:child_process' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import process from 'node:process' | ||
import util from 'node:util' | ||
|
||
const execPromise = util.promisify(childProcess.exec) | ||
|
||
/** | ||
* Filtre les icônes d'une collection en fonction d'une liste de noms. | ||
* @function | ||
* | ||
* @param {string} sourcePath - Fichier source | ||
* @param {string} targetPath - Fichier destination | ||
* | ||
*/ | ||
export async function createCustomCollectionFile (sourcePath, targetPath) { | ||
/** | ||
* @type {[import('@iconify/vue').IconifyJSON, string[]][]} | ||
*/ | ||
const collectionsToFilter = await import(sourcePath).then(({ collectionsToFilter }) => collectionsToFilter) | ||
|
||
const collections = collectionsToFilter.map(tuple => filterIcons(...tuple)) | ||
|
||
const code = `import type { IconifyJSON } from '@iconify/vue' | ||
const collections: IconifyJSON[] = ${JSON.stringify(collections)} | ||
export default collections` | ||
|
||
await fs.writeFile(targetPath, code) | ||
|
||
await runShellCommand(`npx eslint ${path.resolve(process.cwd(), targetPath)} --fix`) | ||
} | ||
|
||
/** | ||
* Fonctions utilitaires | ||
*/ | ||
|
||
/** | ||
* Filtre les icônes d'une collection en fonction d'une liste de noms. | ||
* @function | ||
* | ||
* @param {import('@iconify/vue').IconifyJSON} collection - La collection d'icônes. | ||
* @param {string[]} iconNames - La liste des noms d'icônes à conserver. | ||
* | ||
* @returns {import('@iconify/vue').IconifyJSON} - Une nouvelle collection filtrée. | ||
*/ | ||
export function filterIcons (collection, iconNames) { | ||
const icons = Object.fromEntries(Object.entries(collection.icons).filter(([key]) => { | ||
return iconNames.includes(key) | ||
})) | ||
const { lastModified, aliases, provider, ...useful } = collection | ||
return { | ||
...useful, // prefix, width, height | ||
icons, | ||
} | ||
} | ||
|
||
/** | ||
* Lance une commande shell. | ||
* @function | ||
* | ||
* @param {string} command - La commande shell à lancer | ||
* | ||
* @returns {Promise<undefined>} - Une nouvelle collection filtrée. | ||
*/ | ||
export async function runShellCommand (command) { | ||
try { | ||
const { stdout, stderr } = await execPromise(command) | ||
if (stderr) { | ||
console.error('Erreur :', stderr) | ||
} | ||
console.log(stdout) | ||
} catch (error) { | ||
console.error('Erreur d’exécution :', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './autoimport-preset.js' | ||
export * from './component-resolver.js' | ||
export * from './custom-icon-collections-creator.js' |
Oops, something went wrong.