create-jant 0.3.10 → 0.3.11

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 +88 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,13 +2,14 @@
2
2
  import { program } from "commander";
3
3
  import * as p from "@clack/prompts";
4
4
  import chalk from "chalk";
5
+ import { execSync } from "child_process";
5
6
  import crypto from "crypto";
6
7
  import fs from "fs-extra";
7
8
  import path from "path";
8
9
  import { fileURLToPath } from "url";
9
10
  var __filename = fileURLToPath(import.meta.url);
10
11
  var __dirname = path.dirname(__filename);
11
- var CORE_VERSION = "0.3.10";
12
+ var CORE_VERSION = "0.3.11";
12
13
  var TEMPLATE_DIR = fs.existsSync(path.resolve(__dirname, "../template")) ? path.resolve(__dirname, "../template") : path.resolve(__dirname, "../../../templates/jant-site");
13
14
  function isValidProjectName(name) {
14
15
  return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(name);
@@ -19,6 +20,34 @@ function toValidProjectName(name) {
19
20
  function generateAuthSecret() {
20
21
  return crypto.randomBytes(32).toString("base64");
21
22
  }
23
+ function detectPackageManager() {
24
+ const userAgent = process.env.npm_config_user_agent;
25
+ if (userAgent) {
26
+ const name = userAgent.split("/")[0];
27
+ if (name === "pnpm" || name === "yarn" || name === "npm") {
28
+ return name;
29
+ }
30
+ }
31
+ for (const pm of ["pnpm", "yarn", "npm"]) {
32
+ try {
33
+ execSync(`${pm} --version`, { stdio: "ignore" });
34
+ return pm;
35
+ } catch {
36
+ }
37
+ }
38
+ return "npm";
39
+ }
40
+ function formatRunCmd(pm, script) {
41
+ return pm === "npm" ? `npm run ${script}` : `${pm} ${script}`;
42
+ }
43
+ function runCommand(cmd, cwd) {
44
+ try {
45
+ execSync(cmd, { stdio: "ignore", cwd });
46
+ return true;
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
22
51
  function processMarkers(content, vars) {
23
52
  content = content.replace(
24
53
  /\s*(?:\/\/|#)\s*@create-jant:\s*@remove-start[\s\S]*?(?:\/\/|#)\s*@create-jant:\s*@remove-end\n?/g,
@@ -41,7 +70,7 @@ function processMarkers(content, vars) {
41
70
  return content;
42
71
  }
43
72
  async function copyTemplate(config) {
44
- const { projectName, targetDir } = config;
73
+ const { projectName, targetDir, packageManager } = config;
45
74
  await fs.copy(TEMPLATE_DIR, targetDir, {
46
75
  filter: (src) => {
47
76
  const basename = path.basename(src);
@@ -51,6 +80,10 @@ async function copyTemplate(config) {
51
80
  if (basename === ".swc") return false;
52
81
  if (basename === ".dev.vars") return false;
53
82
  if (basename === "pnpm-lock.yaml") return false;
83
+ if (basename === "yarn.lock") return false;
84
+ if (basename === "package-lock.json") return false;
85
+ if (basename === "bun.lockb") return false;
86
+ if (basename === "pnpm-workspace.yaml") return false;
54
87
  if (basename === "dist") return false;
55
88
  if (basename === "wrangler.demo.toml") return false;
56
89
  if (basename === "reset-demo.sql") return false;
@@ -82,6 +115,19 @@ async function copyTemplate(config) {
82
115
  if (pkg.dependencies?.["@jant/core"] === "workspace:*") {
83
116
  pkg.dependencies["@jant/core"] = `^${CORE_VERSION}`;
84
117
  }
118
+ if (packageManager !== "pnpm") {
119
+ delete pkg.packageManager;
120
+ if (pkg.scripts) {
121
+ for (const [key, value] of Object.entries(pkg.scripts)) {
122
+ if (typeof value === "string") {
123
+ pkg.scripts[key] = value.replace(
124
+ /pnpm (\S+)/g,
125
+ (_, script) => formatRunCmd(packageManager, script)
126
+ );
127
+ }
128
+ }
129
+ }
130
+ }
85
131
  await fs.writeJson(pkgPath, pkg, { spaces: 2 });
86
132
  }
87
133
  const wranglerPath = path.join(targetDir, "wrangler.toml");
@@ -126,11 +172,17 @@ S3_SECRET_ACCESS_KEY=
126
172
  content = processMarkers(content, {});
127
173
  await fs.writeFile(viteConfigPath, content, "utf-8");
128
174
  }
175
+ if (packageManager === "pnpm") {
176
+ const wsSource = path.join(TEMPLATE_DIR, "pnpm-workspace.yaml");
177
+ if (await fs.pathExists(wsSource)) {
178
+ await fs.copy(wsSource, path.join(targetDir, "pnpm-workspace.yaml"));
179
+ }
180
+ }
129
181
  }
130
182
  async function main() {
131
183
  console.log();
132
184
  p.intro(chalk.bgCyan.black(" create-jant "));
133
- program.name("create-jant").description("Create a new Jant project").argument("[project-name]", "Name of the project").option("-y, --yes", "Skip prompts and use defaults").option("--s3", "Use S3-compatible storage instead of Cloudflare R2").parse();
185
+ program.name("create-jant").description("Create a new Jant project").argument("[project-name]", "Name of the project").option("-y, --yes", "Skip prompts and use defaults").option("--s3", "Use S3-compatible storage instead of Cloudflare R2").option("--no-install", "Skip dependency installation").option("--no-git", "Skip git initialization").parse();
134
186
  const args = program.args;
135
187
  const opts = program.opts();
136
188
  let projectName;
@@ -186,9 +238,13 @@ async function main() {
186
238
  await fs.emptyDir(targetDir);
187
239
  }
188
240
  }
241
+ const packageManager = detectPackageManager();
189
242
  const config = {
190
243
  projectName,
191
244
  targetDir,
245
+ packageManager,
246
+ install: opts.install,
247
+ git: opts.git,
192
248
  s3: opts.s3
193
249
  };
194
250
  const spinner2 = p.spinner();
@@ -201,11 +257,36 @@ async function main() {
201
257
  p.log.error(error instanceof Error ? error.message : String(error));
202
258
  process.exit(1);
203
259
  }
260
+ let installOk = false;
261
+ if (config.install) {
262
+ spinner2.start("Installing dependencies...");
263
+ installOk = runCommand(`${packageManager} install`, targetDir);
264
+ if (installOk) {
265
+ spinner2.stop("Dependencies installed.");
266
+ } else {
267
+ spinner2.stop(
268
+ chalk.yellow(
269
+ `Failed to install dependencies. Run ${chalk.bold(`${packageManager} install`)} manually.`
270
+ )
271
+ );
272
+ }
273
+ }
274
+ if (config.git) {
275
+ spinner2.start("Initializing git repository...");
276
+ const gitOk = runCommand("git init", targetDir) && runCommand("git add -A", targetDir) && runCommand('git commit -m "Initial commit"', targetDir);
277
+ if (gitOk) {
278
+ spinner2.stop("Git repository initialized.");
279
+ } else {
280
+ spinner2.stop("Skipped git initialization.");
281
+ }
282
+ }
283
+ const steps = [`cd ${projectName}`];
284
+ if (!config.install || !installOk) {
285
+ steps.push(`${packageManager} install`);
286
+ }
287
+ steps.push(formatRunCmd(packageManager, "dev"));
204
288
  console.log();
205
- p.note(
206
- [`cd ${projectName}`, "pnpm install", "pnpm dev"].join("\n"),
207
- "Next steps"
208
- );
289
+ p.note(steps.join("\n"), "Next steps");
209
290
  p.outro(chalk.green("Happy coding!"));
210
291
  }
211
292
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jant",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "Create a new Jant project",
5
5
  "type": "module",
6
6
  "bin": {