New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-nucleus-app

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-nucleus-app - npm Package Compare versions

Comparing version 0.0.4-alpha.0 to 0.0.4-alpha.1

209

dist/index.js

@@ -1,8 +0,201 @@

import{Command as j}from"commander";import{Command as z}from"commander";import{z as w}from"zod";import s from"chalk";var t={error(...e){console.log(s.red(...e))},warn(...e){console.log(s.yellow(...e))},info(...e){console.log(s.cyan(...e))},success(...e){console.log(s.green(...e))},break(){console.log("")}};function d(e){typeof e=="string"&&(t.error(e),process.exit(1)),e instanceof Error&&(t.error(e.message),process.exit(1)),t.error("Something went wrong. Please try again."),process.exit(1)}import k from"path";import v from"fs-extra";function c(){let e=k.join("package.json");return v.readJSONSync(e)}var u=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var P=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/,y=e=>{let n=u(e),o=n.split("/"),f=o.findIndex(a=>a.startsWith("@")),r=o[o.length-1];return o.findIndex(a=>a.startsWith("@"))!==-1&&(r=o.slice(f).join("/")),n==="."||P.test(r??"")};import p from"path";var h=()=>{let e=process.env.npm_config_user_agent;return e?e.startsWith("yarn")?"yarn":e.startsWith("pnpm")?"pnpm":e.startsWith("bun")?"bun":"npm":"npm"};import*as m from"@clack/prompts";import{fileURLToPath as S}from"url";import i from"chalk";import A from"ora";import l from"fs-extra";var I=S(import.meta.url),_=p.dirname(I),$=p.join(_,"..");async function b(e){let n=h(),o=p.resolve(process.cwd(),e),f=p.join($,"template/base");t.info(`
Using: ${i.cyan.bold(n)}
`);let r=A(`Scaffolding in: ${o}...
`).start();if(l.existsSync(o))if(l.readdirSync(o).length===0)e!=="."&&r.info(`${i.cyan.bold(e)} exists but is empty, continuing...
`);else{r.stopAndPersist();let g=await m.select({message:`${i.redBright.bold("Warning:")} ${i.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,options:[{label:"Abort installation (recommended)",value:"abort"},{label:"Clear the directory and continue installation",value:"clear"}],initialValue:"abort"});g==="abort"&&(r.fail("Aborting installation..."),process.exit(1)),await m.confirm({message:"Are you sure you want to clear the directory?",initialValue:!1})||(r.fail("Aborting installation..."),process.exit(1)),g==="clear"&&(r.info(`Emptying ${i.cyan.bold(e)} and creating t3 app..
`),l.emptyDirSync(o))}r.start(),l.copySync(f,o);let a=e==="."?"App":i.cyan.bold(e);r.succeed(`${a} ${i.green("scaffolded successfully!")}
`)}var D=w.object({dir:w.string().refine(y,{message:"App name must consist of only lowercase alphanumeric characters, '-', and '_'"})}),x=new z().name("init").description("initialize a new project").argument("[dir]","directory to initialize the project").version(c().version,"-v, --version","Display the version number").action(async e=>{try{let n=D.parse({dir:e});t.info("Initializing a new project..."),await b(n.dir)}catch(n){d(n)}});process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function W(){let e=c(),n=new j().name("nucleus").description("cli to manage your scalable projects").version(e.version||"1.0.0","-v, --version","display the version number");n.addCommand(x),n.parse()}W();
//# sourceMappingURL=index.js.map
// src/index.ts
import { Command as Command2 } from "commander";
// src/commands/init.ts
import { Command } from "commander";
import { z } from "zod";
// src/utils/logger.ts
import chalk from "chalk";
var logger = {
error(...args) {
console.log(chalk.red(...args));
},
warn(...args) {
console.log(chalk.yellow(...args));
},
info(...args) {
console.log(chalk.cyan(...args));
},
success(...args) {
console.log(chalk.green(...args));
},
break() {
console.log("");
}
};
// src/utils/handle-error.ts
function handleError(error) {
if (typeof error === "string") {
logger.error(error);
process.exit(1);
}
if (error instanceof Error) {
logger.error(error.message);
process.exit(1);
}
logger.error("Something went wrong. Please try again.");
process.exit(1);
}
// src/utils/get-package-info.ts
import path from "path";
import fs from "fs-extra";
function getPackageInfo() {
const packageJsonPath = path.join("package.json");
return fs.readJSONSync(packageJsonPath);
}
// src/utils/remove-trailing-slash.ts
var removeTrailingSlash = (input) => {
if (input.length > 1 && input.endsWith("/")) {
input = input.slice(0, -1);
}
return input;
};
// src/utils/validate-app-name.ts
var validationRegExp = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
var validateAppName = (rawInput) => {
const input = removeTrailingSlash(rawInput);
const paths = input.split("/");
const indexOfDelimiter = paths.findIndex((p2) => p2.startsWith("@"));
let appName = paths[paths.length - 1];
if (paths.findIndex((p2) => p2.startsWith("@")) !== -1) {
appName = paths.slice(indexOfDelimiter).join("/");
}
return input === "." || validationRegExp.test(appName ?? "");
};
// src/utils/create-project.ts
import path2 from "path";
// src/utils/get-user-package-manager.ts
var getUserPkgManager = () => {
const userAgent = process.env.npm_config_user_agent;
if (userAgent) {
if (userAgent.startsWith("yarn")) {
return "yarn";
} else if (userAgent.startsWith("pnpm")) {
return "pnpm";
} else if (userAgent.startsWith("bun")) {
return "bun";
} else {
return "npm";
}
} else {
return "npm";
}
};
// src/utils/create-project.ts
import * as p from "@clack/prompts";
import { fileURLToPath } from "url";
import chalk2 from "chalk";
import ora from "ora";
import fs2 from "fs-extra";
var __filename = fileURLToPath(import.meta.url);
var distPath = path2.dirname(__filename);
var PKG_ROOT = path2.join(distPath, "..");
async function createProject(projectName) {
const pkgManager = getUserPkgManager();
const projectDir = path2.resolve(process.cwd(), projectName);
const srcDir = path2.join(PKG_ROOT, "template/base");
logger.info(`
Using: ${chalk2.cyan.bold(pkgManager)}
`);
const spinner = ora(`Scaffolding in: ${projectDir}...
`).start();
if (fs2.existsSync(projectDir)) {
if (fs2.readdirSync(projectDir).length === 0) {
if (projectName !== ".")
spinner.info(
`${chalk2.cyan.bold(projectName)} exists but is empty, continuing...
`
);
} else {
spinner.stopAndPersist();
const overwriteDir = await p.select({
message: `${chalk2.redBright.bold("Warning:")} ${chalk2.cyan.bold(
projectName
)} already exists and isn't empty. How would you like to proceed?`,
options: [
{
label: "Abort installation (recommended)",
value: "abort"
},
{
label: "Clear the directory and continue installation",
value: "clear"
}
],
initialValue: "abort"
});
if (overwriteDir === "abort") {
spinner.fail("Aborting installation...");
process.exit(1);
}
const confirmOverwriteDir = await p.confirm({
message: `Are you sure you want to clear the directory?`,
initialValue: false
});
if (!confirmOverwriteDir) {
spinner.fail("Aborting installation...");
process.exit(1);
}
if (overwriteDir === "clear") {
spinner.info(
`Emptying ${chalk2.cyan.bold(projectName)} and creating t3 app..
`
);
fs2.emptyDirSync(projectDir);
}
}
}
spinner.start();
fs2.copySync(srcDir, projectDir);
const scaffoldedName = projectName === "." ? "App" : chalk2.cyan.bold(projectName);
spinner.succeed(
`${scaffoldedName} ${chalk2.green("scaffolded successfully!")}
`
);
}
// src/commands/init.ts
var schema = z.object({
dir: z.string().refine(validateAppName, {
message: "App name must consist of only lowercase alphanumeric characters, '-', and '_'"
})
});
var defaultDir = "my-nucleus-app";
var init = new Command().name("init").description("initialize a new project").argument("[dir]", "directory to initialize the project").version(
getPackageInfo().version,
"-v, --version",
"Display the version number"
).action(async (args) => {
try {
const options = schema.parse({
dir: args || defaultDir
});
logger.info("Initializing a new project...");
await createProject(options.dir);
} catch (error) {
handleError(error);
}
});
// src/index.ts
process.on("SIGINT", () => process.exit(0));
process.on("SIGTERM", () => process.exit(0));
async function main() {
const packageInfo = getPackageInfo();
const program = new Command2().name("nucleus").description("cli to manage your scalable projects").version(
packageInfo.version || "1.0.0",
"-v, --version",
"display the version number"
);
program.addCommand(init);
program.parse();
}
main();

5

package.json
{
"name": "create-nucleus-app",
"version": "0.0.4-alpha.0",
"version": "0.0.4-alpha.1",
"description": "",

@@ -15,4 +15,3 @@ "type": "module",

"scripts": {
"dev": "node dist/index.mjs",
"build:watch": "tsup --watch",
"dev": "tsup --watch",
"build": "tsup",

@@ -19,0 +18,0 @@ "typecheck": "tsc --noEmit"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc