@qwikdev/create-roadplan
Advanced tools
Comparing version 0.0.0 to 0.0.1
#! /usr/bin/env node | ||
import { cancel, confirm, intro, isCancel, log, outro, text } from "@clack/prompts"; | ||
import { cancel, confirm, intro, isCancel, log, outro, spinner, text } from "@clack/prompts"; | ||
import { exec, spawn } from "child_process"; | ||
import { cpSync, existsSync, mkdirSync } from "fs"; | ||
import { gray } from 'kleur/colors'; | ||
import path from "path"; | ||
import { gray, red } from 'kleur/colors'; | ||
import fs from 'node:fs'; | ||
import os from 'node:os'; | ||
import { join } from 'node:path'; | ||
import path, { resolve } from "path"; | ||
import { fileURLToPath } from "url"; | ||
@@ -11,2 +14,50 @@ import detectPackageManager from 'which-pm-runs'; | ||
const __dirname = path.dirname(__filename); | ||
export function resolveRelativeDir(dir) { | ||
// check if the outDir start with home ~ | ||
if (dir.startsWith('~/')) { | ||
return resolve(os.homedir(), dir); | ||
} | ||
else { | ||
return resolve(process.cwd(), dir); | ||
} | ||
} | ||
export function runCommand(cmd, args, cwd) { | ||
let child; | ||
const install = new Promise((resolve) => { | ||
try { | ||
child = spawn(cmd, args, { | ||
cwd, | ||
stdio: 'ignore', | ||
}); | ||
child.on('error', (e) => { | ||
if (e) { | ||
if (e.message) { | ||
log.error(red(String(e.message)) + `\n\n`); | ||
} | ||
else { | ||
log.error(red(String(e)) + `\n\n`); | ||
} | ||
} | ||
resolve(false); | ||
}); | ||
child.on('close', (code) => { | ||
if (code === 0) { | ||
resolve(true); | ||
} | ||
else { | ||
resolve(false); | ||
} | ||
}); | ||
} | ||
catch (e) { | ||
resolve(false); | ||
} | ||
}); | ||
const abort = async () => { | ||
if (child) { | ||
child.kill('SIGINT'); | ||
} | ||
}; | ||
return { abort, install }; | ||
} | ||
export const isPackageManagerInstalled = (packageManager) => { | ||
@@ -75,2 +126,3 @@ return new Promise((resolve) => { | ||
cpSync(templatePath, projectNameAnswer, { recursive: true }); | ||
const outDir = resolveRelativeDir(projectNameAnswer.trim()); | ||
const runDepInstallAnswer = await confirm({ | ||
@@ -84,4 +136,31 @@ message: `Would you like to install ${packageManager} dependencies?`, | ||
} | ||
const gitInitAnswer = await confirm({ | ||
message: `Initialize a new git repository?`, | ||
initialValue: true, | ||
}); | ||
log.step("Installing dependencies..."); | ||
await installDependencies(packageManager, projectNameAnswer); | ||
const s = spinner(); | ||
if (gitInitAnswer) { | ||
if (fs.existsSync(join(outDir, '.git'))) { | ||
log.info(`Git has already been initialized before. Skipping...`); | ||
} | ||
else { | ||
s.start('Git initializing...'); | ||
try { | ||
const res = []; | ||
res.push(await runCommand('git', ['init'], outDir).install); | ||
res.push(await runCommand('git', ['add', '-A'], outDir).install); | ||
res.push(await runCommand('git', ['commit', '-m', 'Initial commit ⚡️'], outDir).install); | ||
if (res.some((r) => r === false)) { | ||
throw ''; | ||
} | ||
s.stop('Git initialized 🎲'); | ||
} | ||
catch (e) { | ||
s.stop('Git failed to initialize'); | ||
log.error(red(`Git failed to initialize. You can do this manually by running: git init`)); | ||
} | ||
} | ||
} | ||
outro("RoadPlan starter creation completed successfully!"); | ||
@@ -88,0 +167,0 @@ } |
{ | ||
"name": "@qwikdev/create-roadplan", | ||
"description": "Interactive CLI for create RoadPlan starter", | ||
"version": "0.0.0", | ||
"description": "Interactive CLI for create a Qwik documentation starter", | ||
"version": "0.0.1", | ||
"author": "QwikDev", | ||
"license": "MIT", | ||
"homepage": "https://roadplan.pages.dev/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/QwikDev/RoadPlan.git", | ||
"directory": "packages/create-roadplan" | ||
}, | ||
"bugs": "https://github.com/QwikDev/RoadPlan/issues", | ||
"keywords": [ | ||
"qwik", | ||
"docs", | ||
"CLI", | ||
"generator", | ||
"starters", | ||
"template" | ||
], | ||
"type": "module", | ||
@@ -6,0 +23,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
0
100
1
1
27
2
4
1122635
62
1446