@dsfrkit/cli 0.1.0 → 0.1.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 (3) hide show
  1. package/LICENSE.md +9 -0
  2. package/dist/index.js +90 -2
  3. package/package.json +10 -10
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ Le contenu de ce dépôt est placé sous licence MIT License, à l'exception de la fonte Marianne.
2
+
3
+ The content of this repository is under MIT License, except for the Marianne font.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.js CHANGED
@@ -935,7 +935,59 @@ import prompts2 from "prompts";
935
935
  var __dirname3 = path3.dirname(fileURLToPath2(import.meta.url));
936
936
  async function init() {
937
937
  console.log(chalk3.bold.blue("\n\u{1F1EB}\u{1F1F7} Initialisation du projet DSFRKit\n"));
938
- const packageManager = await detectPackageManager();
938
+ const hasPackageJson = await fs3.pathExists("package.json");
939
+ let packageManager = "npm";
940
+ if (!hasPackageJson) {
941
+ console.log(chalk3.yellow("\u26A0\uFE0F Aucun d\xE9p\xF4t formel d\xE9tect\xE9 (package.json introuvable)."));
942
+ const createVite = await prompts2({
943
+ type: "confirm",
944
+ name: "value",
945
+ message: "Voulez-vous initialiser un nouveau projet React avec Vite maintenant ?",
946
+ initial: true
947
+ });
948
+ if (createVite.value) {
949
+ const pmPrompt = await prompts2({
950
+ type: "select",
951
+ name: "pm",
952
+ message: "Quel gestionnaire de paquets utiliser ?",
953
+ choices: [
954
+ { title: "npm", value: "npm" },
955
+ { title: "pnpm", value: "pnpm" },
956
+ { title: "yarn", value: "yarn" },
957
+ { title: "bun", value: "bun" }
958
+ ],
959
+ initial: 0
960
+ });
961
+ packageManager = pmPrompt.pm;
962
+ const viteSpinner = ora3("Cr\xE9ation du projet Vite...").start();
963
+ try {
964
+ const createCmd = packageManager === "npm" || packageManager === "bun" ? "create" : "create";
965
+ await execa2(packageManager, [
966
+ createCmd,
967
+ "vite@latest",
968
+ ".",
969
+ "--template",
970
+ "react-ts",
971
+ "--yes"
972
+ ]);
973
+ viteSpinner.succeed("Projet Vite cr\xE9\xE9 avec succ\xE8s");
974
+ const installSpinner = ora3("Installation des d\xE9pendances de base...").start();
975
+ await execa2(packageManager, ["install"]);
976
+ installSpinner.succeed("D\xE9pendances de base install\xE9es");
977
+ } catch (error) {
978
+ viteSpinner.fail("Erreur lors de la cr\xE9ation du projet Vite");
979
+ console.error(error);
980
+ process.exit(1);
981
+ }
982
+ } else {
983
+ console.log(
984
+ chalk3.yellow("Veuillez initialiser un projet (ex: npm init) avant de configurer DSFRKit.")
985
+ );
986
+ process.exit(1);
987
+ }
988
+ } else {
989
+ packageManager = await detectPackageManager();
990
+ }
939
991
  const response = await prompts2([
940
992
  {
941
993
  type: "text",
@@ -1107,6 +1159,7 @@ export default {
1107
1159
  content: [
1108
1160
  './index.html',
1109
1161
  './src/**/*.{js,ts,jsx,tsx}',
1162
+ './node_modules/@dsfrkit/react/dist/**/*.{js,mjs}',
1110
1163
  ],
1111
1164
  theme: {
1112
1165
  extend: {},
@@ -1116,11 +1169,46 @@ export default {
1116
1169
  `;
1117
1170
  if (await fs3.pathExists(configPath)) {
1118
1171
  console.log(chalk3.yellow("\n\u26A0\uFE0F tailwind.config.js existe d\xE9j\xE0"));
1119
- console.log(chalk3.dim("Ajoutez manuellement le preset :"));
1172
+ console.log(chalk3.dim("V\xE9rifiez que le preset et le content sont bien configur\xE9s :"));
1120
1173
  console.log(chalk3.dim(" presets: [dsfrPreset]"));
1174
+ console.log(chalk3.dim(" content: [..., './node_modules/@dsfrkit/react/dist/**/*.{js,mjs}']"));
1121
1175
  } else {
1122
1176
  await fs3.writeFile(configPath, configContent);
1123
1177
  }
1178
+ const cssPath = path3.join(process.cwd(), "src/index.css");
1179
+ const cssContent = `@import '@dsfrkit/tokens/theme.css';
1180
+ @tailwind base;
1181
+ @tailwind components;
1182
+ @tailwind utilities;
1183
+
1184
+ @layer base {
1185
+ * {
1186
+ @apply border-border;
1187
+ }
1188
+ body {
1189
+ @apply bg-background text-foreground font-marianne antialiased;
1190
+ }
1191
+ }
1192
+ `;
1193
+ if (!await fs3.pathExists(cssPath)) {
1194
+ const srcDir = path3.join(process.cwd(), "src");
1195
+ if (await fs3.pathExists(srcDir)) {
1196
+ await fs3.writeFile(cssPath, cssContent);
1197
+ console.log(chalk3.green("\u2713 index.css cr\xE9\xE9 avec les imports DSFRKit"));
1198
+ }
1199
+ } else {
1200
+ const existingCss = await fs3.readFile(cssPath, "utf-8");
1201
+ if (!existingCss.includes("@dsfrkit/tokens/theme.css")) {
1202
+ console.log(
1203
+ chalk3.yellow("\n\u26A0\uFE0F src/index.css existe d\xE9j\xE0 mais ne semble pas importer le th\xE8me DSFRKit.")
1204
+ );
1205
+ console.log(
1206
+ chalk3.dim(
1207
+ "Ajoutez cette ligne tout en haut de votre fichier :\n @import '@dsfrkit/tokens/theme.css';"
1208
+ )
1209
+ );
1210
+ }
1211
+ }
1124
1212
  }
1125
1213
 
1126
1214
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsfrkit/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI pour installer et copier les composants DSFR",
5
5
  "bin": {
6
6
  "dsfrkit": "./dist/index.js"
@@ -11,14 +11,6 @@
11
11
  "dist",
12
12
  "templates"
13
13
  ],
14
- "scripts": {
15
- "build": "tsup",
16
- "dev": "tsup --watch",
17
- "test": "vitest run",
18
- "test:watch": "vitest",
19
- "typecheck": "tsc --noEmit",
20
- "clean": "rm -rf dist"
21
- },
22
14
  "keywords": [
23
15
  "dsfr",
24
16
  "cli",
@@ -42,5 +34,13 @@
42
34
  "@types/prompts": "^2.4.9",
43
35
  "tsup": "^8.3.5",
44
36
  "typescript": "^5.7.2"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "dev": "tsup --watch",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "typecheck": "tsc --noEmit",
44
+ "clean": "rm -rf dist"
45
45
  }
46
- }
46
+ }