socle-generateur 0.0.0-stage → 0.1.0
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/generer.js +118 -0
- package/index.js +100 -0
- package/package.json +38 -4
- package/template/base/.vscode/extensions.json +3 -0
- package/template/base/README.md +30 -0
- package/template/base/_gitignore +6 -0
- package/template/base/index.html +13 -0
- package/template/base/public/favicon.svg +10 -0
- package/template/base/src/App.vue +25 -0
- package/template/base/src/components/FormulaireExemple.vue +38 -0
- package/template/base/src/env.d.ts +1 -0
- package/template/base/src/main.ts +5 -0
- package/template/base/src/style.css +12 -0
- package/template/base/tsconfig.json +17 -0
- package/template/base/vite.config.ts +11 -0
- package/template/table/src/components/TableauExemple.vue +73 -0
- package/versions.js +15 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marc DUREN
|
|
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
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# socle-generateur
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Crée un nouveau projet **Vite + Vue 3 + Tailwind CSS v4 + [socle-ui](https://github.com/marcduren/socle-ui)**, déjà configuré, avec en option les tableaux [socle-ui-table](https://github.com/marcduren/socle-ui-table).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx socle-generateur mon-app
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Sans argument, le générateur pose ses questions dans le terminal : nom du projet, tableaux, installation des dépendances, dépôt Git.
|
|
10
|
+
|
|
11
|
+
## Options
|
|
12
|
+
|
|
13
|
+
| Option | Effet |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `[dossier]` | Dossier du projet, créé s'il n'existe pas. Il doit être vide (un `.git` seul est accepté). Le nom du paquet en est dérivé. |
|
|
16
|
+
| `--table` / `--no-table` | Ajoute (ou non) socle-ui-table : dépendance, import CSS et exemple de tableau. |
|
|
17
|
+
| `--install` / `--no-install` | Lance (ou non) l'installation des dépendances, avec le gestionnaire qui a lancé la commande (npm, pnpm, yarn…). |
|
|
18
|
+
| `--git` / `--no-git` | Initialise (ou non) un dépôt Git, fichiers ajoutés à l'index. |
|
|
19
|
+
| `-y`, `--yes` | Aucune question : les options absentes prennent leur valeur par défaut (`mon-app`, sans tableaux, installation, Git). |
|
|
20
|
+
| `-h`, `--help` | Aide. |
|
|
21
|
+
| `-v`, `--version` | Version du générateur. |
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx socle-generateur mon-app --table # avec les tableaux
|
|
25
|
+
npx socle-generateur mon-app -y --no-install # sans question, sans installation
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Projet généré
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
mon-app/
|
|
32
|
+
├── index.html
|
|
33
|
+
├── package.json socle-ui (+ socle-ui-table), vue, vite, tailwindcss, vue-tsc
|
|
34
|
+
├── vite.config.ts plugins vue() et tailwindcss(), resolve.dedupe: ['vue']
|
|
35
|
+
├── tsconfig.json moduleResolution Bundler, strict, noUncheckedIndexedAccess
|
|
36
|
+
├── public/favicon.svg
|
|
37
|
+
└── src/
|
|
38
|
+
├── main.ts
|
|
39
|
+
├── style.css @import "tailwindcss" puis "socle-ui/tailwind.css" (+ "socle-ui-table/tailwind.css")
|
|
40
|
+
├── App.vue
|
|
41
|
+
└── components/
|
|
42
|
+
├── FormulaireExemple.vue
|
|
43
|
+
└── TableauExemple.vue (avec --table)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
La configuration suit les guides d'intégration de [socle-ui](https://github.com/marcduren/socle-ui/blob/master/INTEGRATION.md) et de [socle-ui-table](https://github.com/marcduren/socle-ui-table/blob/master/INTEGRATION.md). Le projet passe `npm run build` (vérification des types comprise) dès sa création.
|
|
47
|
+
|
|
48
|
+
## Développement
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
index.js CLI : arguments, questions, git, installation
|
|
52
|
+
generer.js génération : copie des modèles, package.json
|
|
53
|
+
versions.js versions écrites dans le package.json généré
|
|
54
|
+
template/base fichiers de tout projet
|
|
55
|
+
template/table fichiers ajoutés avec --table
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Dans les modèles :
|
|
59
|
+
|
|
60
|
+
- `__TITRE__` est remplacé par le nom du dossier, `__NOM__` par le nom du paquet ;
|
|
61
|
+
- une ligne terminée par `// @table`, `/* @table */` ou `<!-- @table -->` n'est gardée qu'avec les tableaux, marqueur retiré ; `@sans-table` fait l'inverse ;
|
|
62
|
+
- `_gitignore` devient `.gitignore` (npm retire les `.gitignore` des paquets publiés).
|
|
63
|
+
|
|
64
|
+
À chaque nouvelle version de socle-ui ou de socle-ui-table, mettez à jour `versions.js`.
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm test # tests (node --test)
|
|
68
|
+
node index.js /tmp/essai --table -y # essai local
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Nécessite Node.js ≥ 20.16.
|
|
72
|
+
|
|
73
|
+
## Licence
|
|
74
|
+
|
|
75
|
+
MIT
|
package/generer.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { versions } from './versions.js'
|
|
5
|
+
|
|
6
|
+
const racineModeles = join(dirname(fileURLToPath(import.meta.url)), 'template')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Marqueur de ligne conditionnelle, en fin de ligne, dans la syntaxe de commentaire du fichier :
|
|
10
|
+
* `// @table`, `/* @table *\/`, `<!-- @table -->` (ligne gardée seulement avec les tableaux)
|
|
11
|
+
* ou `@sans-table` (ligne gardée seulement sans eux).
|
|
12
|
+
*/
|
|
13
|
+
const marqueur = /\s*(?:\/\/|\/\*|<!--)\s*@(table|sans-table)\s*(?:\*\/|-->)?\s*$/
|
|
14
|
+
|
|
15
|
+
/** Fichiers que npm renomme ou retire à la publication : on les stocke préfixés de `_`. */
|
|
16
|
+
const renommages = { _gitignore: '.gitignore' }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Transforme un nom de dossier en nom de paquet npm valide.
|
|
20
|
+
* @param {string} nom
|
|
21
|
+
*/
|
|
22
|
+
export function nomDePaquet(nom) {
|
|
23
|
+
return (
|
|
24
|
+
nom
|
|
25
|
+
.trim()
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.normalize('NFD')
|
|
28
|
+
.replace(/[̀-ͯ]/g, '')
|
|
29
|
+
.replace(/\s+/g, '-')
|
|
30
|
+
.replace(/^[._]+/, '')
|
|
31
|
+
.replace(/[^a-z0-9\-._~]+/g, '-')
|
|
32
|
+
.replace(/-+/g, '-')
|
|
33
|
+
.replace(/^-|-$/g, '') || 'mon-app'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Applique les marqueurs conditionnels et les remplacements à un fichier texte.
|
|
39
|
+
* @param {string} texte
|
|
40
|
+
* @param {{ nom: string, titre: string, table: boolean }} options
|
|
41
|
+
*/
|
|
42
|
+
export function transformer(texte, { nom, titre, table }) {
|
|
43
|
+
const lignes = []
|
|
44
|
+
for (const ligne of texte.split('\n')) {
|
|
45
|
+
const m = ligne.match(marqueur)
|
|
46
|
+
if (!m) {
|
|
47
|
+
lignes.push(ligne)
|
|
48
|
+
} else if ((m[1] === 'table') === table) {
|
|
49
|
+
lignes.push(ligne.slice(0, m.index))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return lignes.join('\n').replaceAll('__NOM__', nom).replaceAll('__TITRE__', titre)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Le dossier peut-il accueillir le projet (absent, ou vide à part `.git`) ? */
|
|
56
|
+
export function dossierUtilisable(dossier) {
|
|
57
|
+
if (!existsSync(dossier)) return true
|
|
58
|
+
if (!statSync(dossier).isDirectory()) return false
|
|
59
|
+
return readdirSync(dossier).every((f) => f === '.git')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function copier(source, cible, options) {
|
|
63
|
+
mkdirSync(cible, { recursive: true })
|
|
64
|
+
for (const entree of readdirSync(source, { withFileTypes: true })) {
|
|
65
|
+
const de = join(source, entree.name)
|
|
66
|
+
const vers = join(cible, renommages[entree.name] ?? entree.name)
|
|
67
|
+
if (entree.isDirectory()) {
|
|
68
|
+
copier(de, vers, options)
|
|
69
|
+
} else if (/\.(svg|png|ico|jpe?g|webp|woff2?)$/i.test(entree.name)) {
|
|
70
|
+
writeFileSync(vers, readFileSync(de))
|
|
71
|
+
} else {
|
|
72
|
+
writeFileSync(vers, transformer(readFileSync(de, 'utf8'), options))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Contenu du package.json du projet généré. */
|
|
78
|
+
export function packageJson({ nom, table }) {
|
|
79
|
+
const dependances = { 'socle-ui': versions['socle-ui'] }
|
|
80
|
+
if (table) dependances['socle-ui-table'] = versions['socle-ui-table']
|
|
81
|
+
dependances.vue = versions.vue
|
|
82
|
+
return {
|
|
83
|
+
name: nom,
|
|
84
|
+
private: true,
|
|
85
|
+
version: '0.0.0',
|
|
86
|
+
type: 'module',
|
|
87
|
+
scripts: {
|
|
88
|
+
dev: 'vite',
|
|
89
|
+
build: 'vue-tsc --noEmit && vite build',
|
|
90
|
+
preview: 'vite preview',
|
|
91
|
+
typecheck: 'vue-tsc --noEmit',
|
|
92
|
+
},
|
|
93
|
+
dependencies: dependances,
|
|
94
|
+
devDependencies: Object.fromEntries(
|
|
95
|
+
['@tailwindcss/vite', '@vitejs/plugin-vue', 'tailwindcss', 'typescript', 'vite', 'vue-tsc'].map((p) => [p, versions[p]]),
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Crée le projet dans `dossier`.
|
|
102
|
+
* @param {{ dossier: string, table: boolean }} options
|
|
103
|
+
* @returns {{ dossier: string, nom: string }}
|
|
104
|
+
*/
|
|
105
|
+
export function genererProjet({ dossier, table }) {
|
|
106
|
+
const cible = resolve(dossier)
|
|
107
|
+
if (!dossierUtilisable(cible)) {
|
|
108
|
+
throw new Error(`Le dossier ${cible} existe déjà et n'est pas vide.`)
|
|
109
|
+
}
|
|
110
|
+
const titre = basename(cible)
|
|
111
|
+
const options = { nom: nomDePaquet(titre), titre, table }
|
|
112
|
+
|
|
113
|
+
copier(join(racineModeles, 'base'), cible, options)
|
|
114
|
+
if (table) copier(join(racineModeles, 'table'), cible, options)
|
|
115
|
+
writeFileSync(join(cible, 'package.json'), JSON.stringify(packageJson(options), null, 2) + '\n')
|
|
116
|
+
|
|
117
|
+
return { dossier: cible, nom: options.nom }
|
|
118
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { relative } from 'node:path'
|
|
5
|
+
import { stdin, stdout } from 'node:process'
|
|
6
|
+
import { createInterface } from 'node:readline/promises'
|
|
7
|
+
import { parseArgs, styleText } from 'node:util'
|
|
8
|
+
import { dossierUtilisable, genererProjet } from './generer.js'
|
|
9
|
+
|
|
10
|
+
const aide = `Utilisation : socle-generateur [dossier] [options]
|
|
11
|
+
|
|
12
|
+
Crée un projet Vite + Vue 3 + Tailwind CSS v4 + socle-ui.
|
|
13
|
+
|
|
14
|
+
Options :
|
|
15
|
+
--table / --no-table Ajoute (ou non) les tableaux socle-ui-table
|
|
16
|
+
--install / --no-install Installe (ou non) les dépendances
|
|
17
|
+
--git / --no-git Initialise (ou non) un dépôt Git
|
|
18
|
+
-y, --yes Sans question : réponses par défaut (dossier mon-app, sans tableaux, installation, Git)
|
|
19
|
+
-h, --help Affiche cette aide
|
|
20
|
+
-v, --version Affiche la version
|
|
21
|
+
|
|
22
|
+
Sans option, les questions sont posées dans le terminal.`
|
|
23
|
+
|
|
24
|
+
const { values, positionals } = parseArgs({
|
|
25
|
+
allowPositionals: true,
|
|
26
|
+
allowNegative: true,
|
|
27
|
+
options: {
|
|
28
|
+
table: { type: 'boolean' },
|
|
29
|
+
install: { type: 'boolean' },
|
|
30
|
+
git: { type: 'boolean' },
|
|
31
|
+
yes: { type: 'boolean', short: 'y' },
|
|
32
|
+
help: { type: 'boolean', short: 'h' },
|
|
33
|
+
version: { type: 'boolean', short: 'v' },
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
if (values.help) {
|
|
38
|
+
console.log(aide)
|
|
39
|
+
process.exit(0)
|
|
40
|
+
}
|
|
41
|
+
if (values.version) {
|
|
42
|
+
console.log(JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version)
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Gestionnaire de paquets qui a lancé la commande (npx, pnpm dlx…), npm par défaut. */
|
|
47
|
+
const gestionnaire = (process.env.npm_config_user_agent ?? '').split('/')[0] || 'npm'
|
|
48
|
+
const gras = (t) => styleText('bold', t)
|
|
49
|
+
const interactif = stdin.isTTY && !values.yes
|
|
50
|
+
|
|
51
|
+
let rl
|
|
52
|
+
async function demander(question, defaut) {
|
|
53
|
+
rl ??= createInterface({ input: stdin, output: stdout })
|
|
54
|
+
const reponse = (await rl.question(`${question} ${styleText('dim', `(${defaut})`)} `)).trim()
|
|
55
|
+
return reponse || defaut
|
|
56
|
+
}
|
|
57
|
+
async function confirmer(question, defaut) {
|
|
58
|
+
const reponse = await demander(question, defaut ? 'O/n' : 'o/N')
|
|
59
|
+
if (reponse === 'O/n' || reponse === 'o/N') return defaut
|
|
60
|
+
return /^(o|oui|y|yes)$/i.test(reponse)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let dossier = positionals[0]
|
|
64
|
+
while (!dossier || !dossierUtilisable(dossier)) {
|
|
65
|
+
if (dossier) console.error(styleText('red', `Le dossier « ${dossier} » existe déjà et n'est pas vide.`))
|
|
66
|
+
if (!interactif) process.exit(1)
|
|
67
|
+
dossier = await demander('Nom du projet :', 'mon-app')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const table = values.table ?? (interactif ? await confirmer('Ajouter les tableaux (socle-ui-table) ?', false) : false)
|
|
71
|
+
const installer = values.install ?? (interactif ? await confirmer(`Installer les dépendances (${gestionnaire} install) ?`, true) : true)
|
|
72
|
+
const git = values.git ?? (interactif ? await confirmer('Initialiser un dépôt Git ?', true) : true)
|
|
73
|
+
rl?.close()
|
|
74
|
+
|
|
75
|
+
const { dossier: cible } = genererProjet({ dossier, table })
|
|
76
|
+
console.log(`\nProjet créé dans ${gras(cible)}${table ? ', avec socle-ui-table' : ''}.`)
|
|
77
|
+
|
|
78
|
+
function lancer(commande, args) {
|
|
79
|
+
const r = spawnSync(commande, args, { cwd: cible, stdio: 'inherit', shell: process.platform === 'win32' })
|
|
80
|
+
return r.status === 0
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (git) {
|
|
84
|
+
const ok = lancer('git', ['init', '--quiet']) && lancer('git', ['add', '-A'])
|
|
85
|
+
if (!ok) console.warn(styleText('yellow', 'Git n’a pas pu être initialisé : à faire à la main.'))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let installe = false
|
|
89
|
+
if (installer) {
|
|
90
|
+
console.log(`\nInstallation des dépendances (${gestionnaire} install)…\n`)
|
|
91
|
+
installe = lancer(gestionnaire, ['install'])
|
|
92
|
+
if (!installe) console.warn(styleText('yellow', `\nL’installation a échoué : relancez « ${gestionnaire} install » dans le dossier.`))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const chemin = relative(process.cwd(), cible) || '.'
|
|
96
|
+
const run = gestionnaire === 'npm' ? 'npm run' : gestionnaire
|
|
97
|
+
console.log(`\nPour démarrer :\n`)
|
|
98
|
+
if (chemin !== '.') console.log(` cd ${chemin.includes(' ') ? `"${chemin}"` : chemin}`)
|
|
99
|
+
if (!installe) console.log(` ${gestionnaire} install`)
|
|
100
|
+
console.log(` ${run} dev\n`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "socle-generateur",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Crée un projet Vite + Vue 3 + Tailwind CSS v4 + socle-ui, avec en option les tableaux socle-ui-table.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Marc DUREN",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/marcduren/socle-generateur.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/marcduren/socle-generateur#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/marcduren/socle-generateur/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"socle-generateur": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"generer.js",
|
|
22
|
+
"versions.js",
|
|
23
|
+
"template",
|
|
24
|
+
"CHANGELOG.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20.16"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"socle-ui",
|
|
34
|
+
"vue",
|
|
35
|
+
"vite",
|
|
36
|
+
"tailwindcss",
|
|
37
|
+
"scaffold",
|
|
38
|
+
"generator"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# __TITRE__
|
|
2
|
+
|
|
3
|
+
Application Vite + Vue 3 + Tailwind CSS v4, avec les composants [socle-ui](https://github.com/marcduren/socle-ui). <!-- @sans-table -->
|
|
4
|
+
Application Vite + Vue 3 + Tailwind CSS v4, avec les composants [socle-ui](https://github.com/marcduren/socle-ui) <!-- @table -->
|
|
5
|
+
et les tableaux [socle-ui-table](https://github.com/marcduren/socle-ui-table). <!-- @table -->
|
|
6
|
+
|
|
7
|
+
## Commandes
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install # dépendances
|
|
11
|
+
npm run dev # serveur de développement
|
|
12
|
+
npm run build # vérification des types (vue-tsc) + build de production
|
|
13
|
+
npm run preview # aperçu du build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Organisation
|
|
17
|
+
|
|
18
|
+
| Fichier | Rôle |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `src/style.css` | Feuille principale : Tailwind, socle-ui, et la redéfinition des tokens `--socle-*` |
|
|
21
|
+
| `src/App.vue` | Page d'accueil |
|
|
22
|
+
| `src/components/FormulaireExemple.vue` | Exemple de formulaire (champ, liste, date, dialogue) |
|
|
23
|
+
| `src/components/TableauExemple.vue` | Exemple de tableau trié, filtré, avec total et export CSV | <!-- @table -->
|
|
24
|
+
|
|
25
|
+
Les exemples peuvent être supprimés sans rien changer d'autre.
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
- [socle-ui](https://github.com/marcduren/socle-ui) : composants et [guide d'intégration](https://github.com/marcduren/socle-ui/blob/master/INTEGRATION.md)
|
|
30
|
+
- [socle-ui-table](https://github.com/marcduren/socle-ui-table) : tableaux et fonctions `sortRows()`, `filterRows()`, `sumColumn()`, `downloadCsv()` <!-- @table -->
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="fr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>__TITRE__</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body class="bg-socle-surface-muted text-socle-text antialiased">
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="socle-ui">
|
|
2
|
+
<style>
|
|
3
|
+
.n { fill: #1e293b; }
|
|
4
|
+
@media (prefers-color-scheme: dark) { .n { fill: #f8fafc; } }
|
|
5
|
+
</style>
|
|
6
|
+
<!-- Logo socle-ui, « Strates » : trois couches en gradins ; la plus haute (accent) évoque le top layer. -->
|
|
7
|
+
<rect x="22" y="8" width="20" height="13" rx="3" fill="#3b82f6"/>
|
|
8
|
+
<rect class="n" x="14" y="25" width="36" height="13" rx="3" opacity=".55"/>
|
|
9
|
+
<rect class="n" x="6" y="42" width="52" height="14" rx="3"/>
|
|
10
|
+
</svg>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import FormulaireExemple from './components/FormulaireExemple.vue'
|
|
3
|
+
import TableauExemple from './components/TableauExemple.vue' // @table
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<main class="mx-auto flex max-w-4xl flex-col gap-8 px-6 py-10">
|
|
8
|
+
<header>
|
|
9
|
+
<h1 class="text-2xl font-semibold">__TITRE__</h1>
|
|
10
|
+
<p class="mt-1 text-socle-text-muted">
|
|
11
|
+
Projet Vite + Vue 3 + Tailwind CSS v4 + socle-ui. Modifiez <code>src/App.vue</code> pour commencer.
|
|
12
|
+
</p>
|
|
13
|
+
</header>
|
|
14
|
+
|
|
15
|
+
<section class="rounded-socle-lg bg-socle-surface p-6 shadow-sm">
|
|
16
|
+
<h2 class="mb-4 text-lg font-semibold">Formulaire</h2>
|
|
17
|
+
<FormulaireExemple />
|
|
18
|
+
</section>
|
|
19
|
+
<!-- @table -->
|
|
20
|
+
<section class="rounded-socle-lg bg-socle-surface p-6 shadow-sm"> <!-- @table -->
|
|
21
|
+
<h2 class="mb-4 text-lg font-semibold">Tableau</h2> <!-- @table -->
|
|
22
|
+
<TableauExemple /> <!-- @table -->
|
|
23
|
+
</section> <!-- @table -->
|
|
24
|
+
</main>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { SocleDatePicker, SocleDialog, SocleInput, SocleSelect, type SelectOption } from 'socle-ui'
|
|
4
|
+
|
|
5
|
+
const nom = ref('')
|
|
6
|
+
const pays = ref<string | null>(null)
|
|
7
|
+
const date = ref<string | null>(null)
|
|
8
|
+
const erreur = ref('')
|
|
9
|
+
const ouvert = ref(false)
|
|
10
|
+
|
|
11
|
+
const listePays: SelectOption<string>[] = [
|
|
12
|
+
{ value: 'fr', label: 'France' },
|
|
13
|
+
{ value: 'be', label: 'Belgique' },
|
|
14
|
+
{ value: 'ch', label: 'Suisse' },
|
|
15
|
+
{ value: 'ca', label: 'Canada' },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
function envoyer() {
|
|
19
|
+
// La validation est à la charge de l'application : les composants affichent l'erreur.
|
|
20
|
+
erreur.value = nom.value ? '' : 'Le nom est obligatoire.'
|
|
21
|
+
if (!erreur.value) ouvert.value = true
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<form class="flex max-w-md flex-col gap-4" novalidate @submit.prevent="envoyer">
|
|
27
|
+
<SocleInput v-model.trim="nom" label="Nom" required :error="erreur" />
|
|
28
|
+
<SocleSelect v-model="pays" label="Pays" :options="listePays" hint="Facultatif" />
|
|
29
|
+
<SocleDatePicker v-model="date" label="Date de livraison" />
|
|
30
|
+
<div>
|
|
31
|
+
<button class="socle-button-primary">Valider</button>
|
|
32
|
+
</div>
|
|
33
|
+
</form>
|
|
34
|
+
|
|
35
|
+
<SocleDialog v-model="ouvert" title="Confirmation">
|
|
36
|
+
<p>Merci {{ nom }}, le formulaire est envoyé.</p>
|
|
37
|
+
</SocleDialog>
|
|
38
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
@import "socle-ui/tailwind.css";
|
|
3
|
+
@import "socle-ui-table/tailwind.css"; /* @table */
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Tokens de socle-ui, à redéfinir pour adapter les composants à l'application.
|
|
7
|
+
* La liste complète est dans le README de socle-ui, section « Personnalisation ».
|
|
8
|
+
*/
|
|
9
|
+
:root {
|
|
10
|
+
/* --socle-color-accent: var(--color-indigo-600); */
|
|
11
|
+
/* --socle-radius: 0.25rem; */
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noUncheckedIndexedAccess": true,
|
|
9
|
+
"jsx": "preserve",
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"types": ["vite/client"]
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts", "src/**/*.vue"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [vue(), tailwindcss()],
|
|
7
|
+
resolve: {
|
|
8
|
+
// Une seule copie de Vue, même si socle-ui est installé par lien symbolique (npm install ../socle-ui).
|
|
9
|
+
dedupe: ['vue'],
|
|
10
|
+
},
|
|
11
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { SocleInput } from 'socle-ui'
|
|
4
|
+
import {
|
|
5
|
+
SocleCell,
|
|
6
|
+
SocleRow,
|
|
7
|
+
SocleTable,
|
|
8
|
+
downloadCsv,
|
|
9
|
+
filterRows,
|
|
10
|
+
sortRows,
|
|
11
|
+
sumColumn,
|
|
12
|
+
type TableColumn,
|
|
13
|
+
type TableSort,
|
|
14
|
+
} from 'socle-ui-table'
|
|
15
|
+
|
|
16
|
+
interface Commande {
|
|
17
|
+
id: number
|
|
18
|
+
ref: string
|
|
19
|
+
client: string
|
|
20
|
+
date: string
|
|
21
|
+
montant: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const commandes = ref<Commande[]>([
|
|
25
|
+
{ id: 1, ref: 'CMD-001', client: 'Dupont SARL', date: '2026-11-03', montant: 1250.5 },
|
|
26
|
+
{ id: 2, ref: 'CMD-002', client: 'Crèche Les Lilas', date: '2026-11-08', montant: 320 },
|
|
27
|
+
{ id: 3, ref: 'CMD-003', client: 'Martin & fils', date: '2026-11-15', montant: 4780 },
|
|
28
|
+
{ id: 4, ref: 'CMD-004', client: 'Atelier Bernard', date: '2026-11-21', montant: 98.9 },
|
|
29
|
+
{ id: 5, ref: 'CMD-005', client: 'Dupont SARL', date: '2026-11-26', montant: 2015 },
|
|
30
|
+
])
|
|
31
|
+
|
|
32
|
+
const euros = new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' })
|
|
33
|
+
const jour = new Intl.DateTimeFormat('fr-FR')
|
|
34
|
+
|
|
35
|
+
const colonnes: TableColumn<Commande>[] = [
|
|
36
|
+
{ name: 'ref', label: 'Référence', sortable: true, width: 130 },
|
|
37
|
+
{ name: 'client', label: 'Client', sortable: true, width: 220 },
|
|
38
|
+
{ name: 'date', label: 'Date', type: 'date', sortable: true, width: 120 },
|
|
39
|
+
{ name: 'montant', label: 'Montant', type: 'number', sortable: true, width: 140, searchText: (c) => euros.format(c.montant) },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const tri = ref<TableSort | null>(null)
|
|
43
|
+
const recherche = ref('')
|
|
44
|
+
|
|
45
|
+
// Filtrer d'abord, puis trier.
|
|
46
|
+
const filtrees = computed(() => filterRows(commandes.value, colonnes, recherche.value))
|
|
47
|
+
const lignes = computed(() => sortRows(filtrees.value, colonnes, tri.value))
|
|
48
|
+
const total = computed(() => sumColumn(filtrees.value, colonnes, 'montant'))
|
|
49
|
+
|
|
50
|
+
const exporter = () => downloadCsv(lignes.value, colonnes, 'commandes.csv')
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<div class="flex flex-col gap-4">
|
|
55
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
56
|
+
<SocleInput v-model="recherche" class="max-w-xs" label="Rechercher" type="search" />
|
|
57
|
+
<button type="button" class="socle-button" @click="exporter">Exporter en CSV</button>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<SocleTable v-model:sort="tri" :columns="colonnes" caption="Commandes" storage-key="__NOM__:commandes" striped>
|
|
61
|
+
<SocleRow v-for="c in lignes" :key="c.id">
|
|
62
|
+
<SocleCell header>{{ c.ref }}</SocleCell>
|
|
63
|
+
<SocleCell>{{ c.client }}</SocleCell>
|
|
64
|
+
<SocleCell>{{ jour.format(new Date(c.date)) }}</SocleCell>
|
|
65
|
+
<SocleCell>{{ euros.format(c.montant) }}</SocleCell>
|
|
66
|
+
</SocleRow>
|
|
67
|
+
|
|
68
|
+
<template #empty>Aucune commande ne correspond.</template>
|
|
69
|
+
</SocleTable>
|
|
70
|
+
|
|
71
|
+
<p class="text-right font-medium">Total : {{ euros.format(total) }}</p>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
package/versions.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versions écrites dans le package.json des projets générés.
|
|
3
|
+
* À mettre à jour à chaque nouvelle version de socle-ui ou de socle-ui-table.
|
|
4
|
+
*/
|
|
5
|
+
export const versions = {
|
|
6
|
+
'socle-ui': '^0.10.0',
|
|
7
|
+
'socle-ui-table': '^0.3.0',
|
|
8
|
+
vue: '^3.5.0',
|
|
9
|
+
'@tailwindcss/vite': '^4.3.0',
|
|
10
|
+
'@vitejs/plugin-vue': '^6.0.0',
|
|
11
|
+
tailwindcss: '^4.3.0',
|
|
12
|
+
typescript: '~5.9.3',
|
|
13
|
+
vite: '^8.0.0',
|
|
14
|
+
'vue-tsc': '^3.3.0',
|
|
15
|
+
}
|