create-template-project 0.3.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +63 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -783,8 +783,7 @@ var getSpinner = (progress) => {
783
783
  const s = p.spinner();
784
784
  return {
785
785
  start: (msg) => progress ? s.start(msg) : void 0,
786
- stop: (msg) => progress ? s.stop(msg) : void 0,
787
- message: (msg) => progress ? s.message(msg) : void 0
786
+ stop: (msg) => progress ? s.stop(msg) : void 0
788
787
  };
789
788
  };
790
789
  var showNote = (msg, title, progress) => {
@@ -792,6 +791,15 @@ var showNote = (msg, title, progress) => {
792
791
  if (title) p.log.success(title);
793
792
  p.note(msg);
794
793
  };
794
+ var isFileRequired = (relativePath, type) => {
795
+ if (relativePath === "vitest.config.ts") return ![
796
+ "cli",
797
+ "web-vanilla",
798
+ "web-app",
799
+ "web-fullstack"
800
+ ].includes(type);
801
+ return true;
802
+ };
795
803
  var generateProject = async (opts) => {
796
804
  const { template: type, projectName, directory, update, overwrite, progress } = opts;
797
805
  const isProgress = progress !== false;
@@ -915,6 +923,18 @@ var generateProject = async (opts) => {
915
923
  });
916
924
  continue;
917
925
  }
926
+ if (!isFileRequired(relativePath, type)) {
927
+ if (isUpdate && await pathExists(targetPath)) {
928
+ actions.push({
929
+ type: "DELETE",
930
+ path: relativePath
931
+ });
932
+ pendingOperations.push(async () => {
933
+ await fs.rm(targetPath, { force: true });
934
+ });
935
+ }
936
+ continue;
937
+ }
918
938
  if (relativePath === "_oxlint.config.ts") {
919
939
  relativePath = "oxlint.config.ts";
920
940
  targetPath = path.join(projectDir, relativePath);
@@ -961,6 +981,18 @@ var generateProject = async (opts) => {
961
981
  });
962
982
  continue;
963
983
  }
984
+ if (!isFileRequired(file.path, type)) {
985
+ if (isUpdate && await pathExists(targetPath)) {
986
+ actions.push({
987
+ type: "DELETE",
988
+ path: file.path
989
+ });
990
+ pendingOperations.push(async () => {
991
+ await fs.rm(targetPath, { force: true });
992
+ });
993
+ }
994
+ continue;
995
+ }
964
996
  let content = typeof file.content === "function" ? file.content() : file.content;
965
997
  content = processContent(file.path, content, opts, addedDeps);
966
998
  const exists = await pathExists(targetPath);
@@ -997,41 +1029,47 @@ var generateProject = async (opts) => {
997
1029
  if (pm === "pnpm" && finalPkg.workspaces) {
998
1030
  debug$1("Creating pnpm-workspace.yaml");
999
1031
  const workspaceYaml = `packages:\n${finalPkg.workspaces.map((w) => ` - '${w}'`).join("\n")}\n`;
1000
- pendingOperations.push(async () => {
1001
- await fs.writeFile(path.join(projectDir, "pnpm-workspace.yaml"), workspaceYaml);
1002
- });
1032
+ const workspacePath = path.join(projectDir, "pnpm-workspace.yaml");
1033
+ const workspaceExists = await pathExists(workspacePath);
1034
+ let workspaceChanged = true;
1035
+ if (workspaceExists) workspaceChanged = (await fs.readFile(workspacePath, "utf8")).trim() !== workspaceYaml.trim();
1036
+ if (workspaceChanged) {
1037
+ actions.push({
1038
+ type: workspaceExists ? "MODIFY" : "ADD",
1039
+ path: "pnpm-workspace.yaml"
1040
+ });
1041
+ pendingOperations.push(async () => {
1042
+ await fs.writeFile(workspacePath, workspaceYaml);
1043
+ });
1044
+ }
1003
1045
  delete finalPkg.workspaces;
1004
1046
  for (const key of Object.keys(finalPkg.scripts)) {
1005
1047
  const value = finalPkg.scripts[key];
1006
1048
  if (typeof value === "string" && value.includes("--workspaces")) finalPkg.scripts[key] = value.replace(" run ", " -r run ").replace(" --workspaces", "");
1007
1049
  }
1008
1050
  }
1009
- if (type === "cli" || type === "web-vanilla" || type === "web-app" || type === "web-fullstack") {
1010
- const fullPath = path.join(projectDir, "vitest.config.ts");
1011
- pendingOperations.push(async () => {
1012
- await fs.rm(fullPath, { force: true });
1051
+ const newPkgContent = JSON.stringify(finalPkg, null, " ");
1052
+ let pkgChanged = true;
1053
+ if (isUpdate && await pathExists(pkgPath)) pkgChanged = (await fs.readFile(pkgPath, "utf8")).trim() !== newPkgContent.trim();
1054
+ if (pkgChanged) {
1055
+ if (isUpdate) actions.push({
1056
+ type: "MODIFY",
1057
+ path: "package.json"
1013
1058
  });
1014
- if (isUpdate && await pathExists(fullPath)) actions.push({
1015
- type: "DELETE",
1016
- path: "vitest.config.ts"
1059
+ else actions.push({
1060
+ type: "ADD",
1061
+ path: "package.json"
1062
+ });
1063
+ pendingOperations.push(async () => {
1064
+ debug$1("Writing final consolidated package.json to: %s", pkgPath);
1065
+ await fs.writeFile(pkgPath, newPkgContent);
1017
1066
  });
1018
1067
  }
1019
- if (isUpdate) actions.push({
1020
- type: "MODIFY",
1021
- path: "package.json"
1022
- });
1023
- else actions.push({
1024
- type: "ADD",
1025
- path: "package.json"
1026
- });
1027
- pendingOperations.push(async () => {
1028
- debug$1("Writing final consolidated package.json to: %s", pkgPath);
1029
- await fs.writeFile(pkgPath, JSON.stringify(finalPkg, null, " "));
1030
- });
1031
1068
  if (isUpdate && actions.length > 0 && process.env.NODE_ENV !== "test") {
1032
1069
  const summary = actions.filter((a) => a.type !== "SKIP").map((a) => ` ${a.type.padEnd(8)} ${a.path}`).join("\n");
1033
1070
  if (summary) {
1034
- p.note(summary, "Planned changes:");
1071
+ const relativeProjectDir = path.relative(process.cwd(), projectDir) || ".";
1072
+ p.note(summary, `Planned changes in ${relativeProjectDir}:`);
1035
1073
  const confirm = await p.confirm({
1036
1074
  message: "Do you want to apply these changes?",
1037
1075
  initialValue: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-template-project",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Dieter Oberkofler",