@pergel/cli
Advanced tools
| // src/core.ts | ||
| import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { dirname, join as join2, resolve } from "node:path"; | ||
| import { downloadTemplate } from "giget"; | ||
| // ../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs | ||
| function isPlainObject(value) { | ||
| if (value === null || typeof value !== "object") { | ||
| return false; | ||
| } | ||
| const prototype = Object.getPrototypeOf(value); | ||
| if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) { | ||
| return false; | ||
| } | ||
| if (Symbol.iterator in value) { | ||
| return false; | ||
| } | ||
| if (Symbol.toStringTag in value) { | ||
| return Object.prototype.toString.call(value) === "[object Module]"; | ||
| } | ||
| return true; | ||
| } | ||
| function _defu(baseObject, defaults, namespace = ".", merger) { | ||
| if (!isPlainObject(defaults)) { | ||
| return _defu(baseObject, {}, namespace, merger); | ||
| } | ||
| const object = Object.assign({}, defaults); | ||
| for (const key in baseObject) { | ||
| if (key === "__proto__" || key === "constructor") { | ||
| continue; | ||
| } | ||
| const value = baseObject[key]; | ||
| if (value === null || value === void 0) { | ||
| continue; | ||
| } | ||
| if (merger && merger(object, key, value, namespace)) { | ||
| continue; | ||
| } | ||
| if (Array.isArray(value) && Array.isArray(object[key])) { | ||
| object[key] = [...value, ...object[key]]; | ||
| } else if (isPlainObject(value) && isPlainObject(object[key])) { | ||
| object[key] = _defu( | ||
| value, | ||
| object[key], | ||
| (namespace ? `${namespace}.` : "") + key.toString(), | ||
| merger | ||
| ); | ||
| } else { | ||
| object[key] = value; | ||
| } | ||
| } | ||
| return object; | ||
| } | ||
| function createDefu(merger) { | ||
| return (...arguments_) => ( | ||
| // eslint-disable-next-line unicorn/no-array-reduce | ||
| arguments_.reduce((p, c) => _defu(p, c, "", merger), {}) | ||
| ); | ||
| } | ||
| var defu = createDefu(); | ||
| var defuFn = createDefu((object, key, currentValue) => { | ||
| if (object[key] !== void 0 && typeof currentValue === "function") { | ||
| object[key] = currentValue(object[key]); | ||
| return true; | ||
| } | ||
| }); | ||
| var defuArrayFn = createDefu((object, key, currentValue) => { | ||
| if (Array.isArray(object[key]) && typeof currentValue === "function") { | ||
| object[key] = currentValue(object[key]); | ||
| return true; | ||
| } | ||
| }); | ||
| // src/core.ts | ||
| import { consola } from "consola"; | ||
| import { filename } from "pathe/utils"; | ||
| import { extname } from "pathe"; | ||
| import { loadConfig } from "c12"; | ||
| // src/scan.ts | ||
| import { globby } from "globby"; | ||
| import { join, relative } from "pathe"; | ||
| var GLOB_SCAN_PATTERN = "**/*"; | ||
| async function scanDir(pergel, dir, folderName) { | ||
| const fileNames = await globby(join(folderName ?? "", GLOB_SCAN_PATTERN), { | ||
| cwd: dir, | ||
| dot: true, | ||
| ignore: pergel.options.ignore, | ||
| absolute: true | ||
| }); | ||
| return fileNames.map((fullPath) => { | ||
| return { | ||
| fullPath, | ||
| path: relative(join(dir, folderName ?? ""), fullPath) | ||
| }; | ||
| }).sort((a, b) => a.path.localeCompare(b.path)); | ||
| } | ||
| async function scanFiles(pergel, folderName) { | ||
| const files = await Promise.all( | ||
| pergel.options.scanDirs.map((dir) => scanDir(pergel, dir, folderName)) | ||
| ).then((r) => r.flat()); | ||
| return files; | ||
| } | ||
| async function scanAnyFiles(pergel, folderName) { | ||
| const files = await scanFiles(pergel, folderName); | ||
| return files.map((f) => f.fullPath); | ||
| } | ||
| // src/core.ts | ||
| var logger = consola.create({ | ||
| defaults: { | ||
| tag: "pergel:download" | ||
| } | ||
| }); | ||
| function definePergel(config) { | ||
| return config; | ||
| } | ||
| function defineDownload(options) { | ||
| async function setup(data) { | ||
| const { cwd } = data; | ||
| const githubRepo = "github:oku-ui/pergel"; | ||
| const projectName = options.projectName; | ||
| const firstLetterProjectName = projectName.charAt(0).toUpperCase() + projectName.slice(1); | ||
| options = defu(options, { | ||
| tempOutput: ".tempPergel", | ||
| branch: "main" | ||
| }); | ||
| if (options.file?.dir) { | ||
| const { dir } = await downloadTemplate(join2(githubRepo, `${options.file.dir}#${options.branch}`), { | ||
| dir: options.tempOutput, | ||
| cwd, | ||
| force: true | ||
| }); | ||
| for (const file of options.file.path) { | ||
| const output = resolve(join2(cwd, file.outputFileName)); | ||
| const _dirname = dirname(output); | ||
| if (!existsSync(output)) { | ||
| if (!existsSync(_dirname)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(dir, file.fileName), "utf-8"); | ||
| if (file.replace?.from && file.replace?.to) | ||
| readFile.replace(file.replace?.from, file.replace?.to); | ||
| readFile = readFile.replace(`/changeName/g`, projectName).replace(`/ChangeName/g`, firstLetterProjectName); | ||
| writeFileSync( | ||
| resolve(output), | ||
| readFile | ||
| ); | ||
| } else if (file.forceClean) { | ||
| rmSync(output, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| if (!existsSync(_dirname)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(dir, file.fileName), "utf-8"); | ||
| if (file.replace?.from && file.replace?.to) | ||
| readFile.replace(file.replace?.from, file.replace?.to); | ||
| readFile = readFile.replace(`/changeName/g`, projectName).replace(`/ChangeName/g`, firstLetterProjectName); | ||
| writeFileSync( | ||
| resolve(output), | ||
| readFile | ||
| ); | ||
| } | ||
| logger.success(`Downloaded template file: ${output}`); | ||
| } | ||
| } | ||
| if (options.folder && options.folder.length) { | ||
| for (const folder of options.folder) { | ||
| const { dir } = await downloadTemplate(join2(githubRepo, `${folder.dir}#${options.branch}`), { | ||
| dir: options.tempOutput, | ||
| cwd, | ||
| force: true, | ||
| forceClean: folder.forceClean !== false | ||
| }); | ||
| if (!existsSync(resolve(folder.output))) { | ||
| mkdirSync(resolve(folder.output), { | ||
| recursive: true | ||
| }); | ||
| } | ||
| const scanDir2 = await scanAnyFiles({ | ||
| options: { | ||
| scanDirs: [folder.dir] | ||
| } | ||
| }, dir); | ||
| if (scanDir2.length > 0) { | ||
| for (const file of scanDir2) { | ||
| const _output = join2(folder.output, file.replace(dir, "")); | ||
| const _dirname = dirname(_output); | ||
| const _file = filename(_output) + extname(_output); | ||
| if (!existsSync(_output)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(file), "utf-8"); | ||
| if (folder.replace?.from !== "changeName") | ||
| readFile.replace(folder.replace?.from || "changeName", folder.replace?.to || projectName); | ||
| readFile = readFile.replace(/changeName/g, projectName).replace(/ChangeName/g, firstLetterProjectName); | ||
| writeFileSync( | ||
| join2(_output), | ||
| readFile | ||
| ); | ||
| logger.success(`Downloaded template folder: ${_file}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| rmSync(options.tempOutput, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| } | ||
| return setup; | ||
| } | ||
| async function definePergelLoadConfig(input) { | ||
| const file = await loadConfig({ | ||
| cwd: input?.cwd ?? process.cwd(), | ||
| configFile: "pergel.config", | ||
| defaultConfig: { | ||
| dir: { | ||
| pergel: "pergel", | ||
| template: "pergel/templates", | ||
| server: "server" | ||
| }, | ||
| filePath: { | ||
| nuxtConfig: "nuxt.config.ts" | ||
| } | ||
| } | ||
| }); | ||
| return file; | ||
| } | ||
| export { | ||
| definePergel, | ||
| defineDownload, | ||
| definePergelLoadConfig | ||
| }; |
| import { | ||
| defineDownload, | ||
| definePergelLoadConfig | ||
| } from "./chunk-H36PPSPN.js"; | ||
| // src/commands/download.ts | ||
| import { join, resolve } from "node:path"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { defineCommand } from "citty"; | ||
| import consola from "consola"; | ||
| var logger = consola.create({ | ||
| defaults: { | ||
| tag: "pergel:download" | ||
| } | ||
| }); | ||
| var download_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Download", | ||
| description: "Download Nuxt Template", | ||
| version: "0.0.1" | ||
| }, | ||
| args: { | ||
| jsonFile: { | ||
| alias: "j", | ||
| description: "Download file" | ||
| }, | ||
| template: { | ||
| alias: "t", | ||
| description: "Download file" | ||
| }, | ||
| projectName: { | ||
| alias: "p", | ||
| description: "Project name" | ||
| } | ||
| }, | ||
| async run({ args }) { | ||
| const template = args.template; | ||
| const jsonFile = args.jsonFile; | ||
| const projectName = args.projectName; | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| logger.error("No config file found"); | ||
| return; | ||
| } | ||
| const templateDir = resolve(file.config.dir.template); | ||
| const data = readFileSync(join(templateDir, `${jsonFile}.json`), "utf-8"); | ||
| if (!data) { | ||
| logger.error(`No file found for ${file}`); | ||
| return; | ||
| } | ||
| const jsonData = JSON.parse(data); | ||
| if (!jsonData) { | ||
| logger.error(`No data found for ${file}`); | ||
| return; | ||
| } | ||
| if (!jsonData) { | ||
| logger.error(`No template found for ${template}`); | ||
| return; | ||
| } | ||
| if (jsonData) { | ||
| logger.info(`Downloading template: ${template} ...`); | ||
| const data2 = defineDownload({ | ||
| file: jsonData.file, | ||
| folder: jsonData.folder, | ||
| branch: jsonData.branch, | ||
| tempOutput: ".tempPergel", | ||
| projectName | ||
| }); | ||
| await data2({ | ||
| cwd: process.cwd() | ||
| }); | ||
| logger.success(`Downloaded template: ${template}`); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| download_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-H36PPSPN.js"; | ||
| // src/commands/install.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { consola } from "consola"; | ||
| import { parseNa, parseNi, run } from "@antfu/ni"; | ||
| var install_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Install", | ||
| description: "Install dependencies from README.json", | ||
| version: "0.2.0" | ||
| }, | ||
| async run() { | ||
| const args = process.argv.slice(2).filter((arg) => arg !== "install" && arg !== "pergel"); | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(join(file.config.dir?.pergel, "README.json")), "utf-8"); | ||
| const jsonData = JSON.parse(readmeString); | ||
| const dependencies = /* @__PURE__ */ new Set(); | ||
| const devDependencies = /* @__PURE__ */ new Set(); | ||
| for (const [_moduleName, moduleData] of Object.entries(jsonData)) { | ||
| if (!moduleData) | ||
| continue; | ||
| for (const [_projectName, projectData] of Object.entries(moduleData)) { | ||
| if (!projectData) { | ||
| consola.error(`No project data found for ${_projectName}`); | ||
| continue; | ||
| } | ||
| if (projectData.packageJson) { | ||
| if (projectData.packageJson.dependencies) { | ||
| const debs = Object.keys(projectData.packageJson.dependencies); | ||
| if (debs.length) { | ||
| for (const item of debs) { | ||
| if (item) | ||
| dependencies.add(`${item}@${projectData.packageJson.dependencies[item]}`); | ||
| } | ||
| } | ||
| } | ||
| if (projectData.packageJson.devDependencies) { | ||
| const debs = Object.keys(projectData.packageJson.devDependencies); | ||
| if (debs.length) { | ||
| for (const item of debs) { | ||
| if (item) | ||
| devDependencies.add(`${item}@${projectData.packageJson.devDependencies[item]}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (dependencies.size) { | ||
| await run(parseNi, [...dependencies.values(), ...args]).then(() => { | ||
| consola.success("Dependencies installed", dependencies.values()); | ||
| }).catch((res) => { | ||
| consola.error(res); | ||
| }); | ||
| } | ||
| if (devDependencies.size) { | ||
| await run(parseNi, [...devDependencies.values(), "-D", ...args]).then(() => { | ||
| consola.success("Dev dependencies installed", devDependencies.values()); | ||
| }).catch((res) => { | ||
| consola.error(res); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| consola.info("Please run `pergel init` to create a config folder. After that, you can run `pergel install` to install dependencies."); | ||
| const confirm = await consola.prompt("Would you like to run `pergel init` now?", { | ||
| type: "confirm" | ||
| }); | ||
| if (confirm) { | ||
| await run(parseNa, ["pergel", "init"], { programmatic: true }).then(async () => { | ||
| consola.success("Config folder created"); | ||
| await run(parseNa, ["nuxt", "prepare"], { programmatic: true }).then(() => { | ||
| consola.success("Nuxt prepared"); | ||
| }); | ||
| }).catch(() => { | ||
| consola.error("Failed to create config folder"); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| install_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-H36PPSPN.js"; | ||
| // src/commands/module.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { consola } from "consola"; | ||
| import { parseNa, run } from "@antfu/ni"; | ||
| var module_default = defineCommand({ | ||
| meta: { | ||
| name: "Module Command", | ||
| description: "Module Command", | ||
| version: "0.0.0" | ||
| }, | ||
| args: { | ||
| project: { | ||
| type: "string", | ||
| description: "Name of the project", | ||
| alias: "p" | ||
| }, | ||
| module: { | ||
| type: "string", | ||
| description: "Name of the module", | ||
| alias: "m" | ||
| }, | ||
| script: { | ||
| type: "string", | ||
| description: "Name of the script", | ||
| alias: "s" | ||
| } | ||
| }, | ||
| async run({ args }) { | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(file.config.dir.pergel, "README.json")).toString(); | ||
| const project = JSON.parse(readmeString)[args.project ?? ""]?.[args.module ?? ""]; | ||
| const script = project?.scripts ?? {}; | ||
| if (Object.keys(script).length === 0) | ||
| consola.error("No script found"); | ||
| const selectedScript = script[args.script ?? ""]; | ||
| if (!selectedScript) | ||
| consola.error("No script found"); | ||
| try { | ||
| await run(async (agent, args2, ctx) => { | ||
| const command = await parseNa(agent, args2, ctx); | ||
| return command ? command.replace(/"/g, "") : void 0; | ||
| }, [selectedScript], { programmatic: true }).then(() => { | ||
| consola.success("Script executed successfully"); | ||
| }).catch((error) => { | ||
| consola.error(error); | ||
| }); | ||
| } catch (error) { | ||
| consola.error(error); | ||
| } | ||
| } catch (error) { | ||
| consola.log(error); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| module_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-H36PPSPN.js"; | ||
| // src/commands/select.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { execSync } from "node:child_process"; | ||
| import { intro, select } from "@clack/prompts"; | ||
| import { defineCommand } from "citty"; | ||
| import consola from "consola"; | ||
| var select_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Upgrade", | ||
| description: "Upgrade Pergel CLI", | ||
| version: "0.0.1" | ||
| }, | ||
| async run() { | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| intro("Oku Pergel Select CLI"); | ||
| const readmeString = readFileSync(resolve(join(file.config.dir?.pergel, "README.json")), "utf-8"); | ||
| const jsonData = JSON.parse(readmeString); | ||
| const projectNames = Object.keys(jsonData).filter((i) => { | ||
| const project = jsonData[i]; | ||
| if (!project) | ||
| return false; | ||
| for (const key in project) { | ||
| if (project[key].cli) | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| if (!projectNames.length) { | ||
| consola.error("No projects found"); | ||
| return; | ||
| } | ||
| const selectedProject = await select({ | ||
| message: "Select a project", | ||
| options: projectNames.map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| const selectedProjectData = jsonData[selectedProject]; | ||
| const cliModules = Object.keys(selectedProjectData).filter((i) => { | ||
| const cli = selectedProjectData[i].cli; | ||
| if (cli) | ||
| return true; | ||
| return false; | ||
| }); | ||
| const selectedModule = await select({ | ||
| message: "Select a module", | ||
| options: cliModules.map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| if (selectedModule) { | ||
| const selectedCli = await select({ | ||
| message: "Select a cli command", | ||
| options: Object.keys(selectedProjectData[selectedModule].cli).map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| const cliData = selectedProjectData[selectedModule].cli[selectedCli]; | ||
| if (cliData) { | ||
| consola.info(`Running ${cliData}`); | ||
| execSync( | ||
| cliData, | ||
| { | ||
| stdio: "inherit" | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| consola.error(error); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| select_default as default | ||
| }; |
+1
-1
@@ -5,3 +5,3 @@ import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| } from "./chunk-H36PPSPN.js"; | ||
| export { | ||
@@ -8,0 +8,0 @@ defineDownload, |
+6
-6
| import { | ||
| definePergel, | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| } from "./chunk-H36PPSPN.js"; | ||
@@ -13,3 +13,3 @@ // src/index.ts | ||
| type: "module", | ||
| version: "0.8.0", | ||
| version: "0.8.1", | ||
| packageManager: "pnpm@8.10.0", | ||
@@ -136,6 +136,6 @@ description: "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.", | ||
| init: () => import("./init-2VY6IQN5.js").then((m) => m.default), | ||
| install: () => import("./install-5M5AKLZQ.js").then((m) => m.default), | ||
| module: () => import("./module-5VMCAOPO.js").then((m) => m.default), | ||
| download: () => import("./download-4FGI6T2M.js").then((m) => m.default), | ||
| select: () => import("./select-23J2FHOD.js").then((m) => m.default) | ||
| install: () => import("./install-BFB3G2IX.js").then((m) => m.default), | ||
| module: () => import("./module-F4LOQBLJ.js").then((m) => m.default), | ||
| download: () => import("./download-TXZWEWUB.js").then((m) => m.default), | ||
| select: () => import("./select-JZE7F6LA.js").then((m) => m.default) | ||
| }, | ||
@@ -142,0 +142,0 @@ run({ args }) { |
+1
-1
| { | ||
| "name": "@pergel/cli", | ||
| "type": "module", | ||
| "version": "0.8.0", | ||
| "version": "0.8.1", | ||
| "packageManager": "pnpm@8.10.0", | ||
@@ -6,0 +6,0 @@ "description": "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.", |
| // src/core.ts | ||
| import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { dirname, join as join2, resolve } from "node:path"; | ||
| import { downloadTemplate } from "giget"; | ||
| // ../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs | ||
| function isPlainObject(value) { | ||
| if (value === null || typeof value !== "object") { | ||
| return false; | ||
| } | ||
| const prototype = Object.getPrototypeOf(value); | ||
| if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) { | ||
| return false; | ||
| } | ||
| if (Symbol.iterator in value) { | ||
| return false; | ||
| } | ||
| if (Symbol.toStringTag in value) { | ||
| return Object.prototype.toString.call(value) === "[object Module]"; | ||
| } | ||
| return true; | ||
| } | ||
| function _defu(baseObject, defaults, namespace = ".", merger) { | ||
| if (!isPlainObject(defaults)) { | ||
| return _defu(baseObject, {}, namespace, merger); | ||
| } | ||
| const object = Object.assign({}, defaults); | ||
| for (const key in baseObject) { | ||
| if (key === "__proto__" || key === "constructor") { | ||
| continue; | ||
| } | ||
| const value = baseObject[key]; | ||
| if (value === null || value === void 0) { | ||
| continue; | ||
| } | ||
| if (merger && merger(object, key, value, namespace)) { | ||
| continue; | ||
| } | ||
| if (Array.isArray(value) && Array.isArray(object[key])) { | ||
| object[key] = [...value, ...object[key]]; | ||
| } else if (isPlainObject(value) && isPlainObject(object[key])) { | ||
| object[key] = _defu( | ||
| value, | ||
| object[key], | ||
| (namespace ? `${namespace}.` : "") + key.toString(), | ||
| merger | ||
| ); | ||
| } else { | ||
| object[key] = value; | ||
| } | ||
| } | ||
| return object; | ||
| } | ||
| function createDefu(merger) { | ||
| return (...arguments_) => ( | ||
| // eslint-disable-next-line unicorn/no-array-reduce | ||
| arguments_.reduce((p, c) => _defu(p, c, "", merger), {}) | ||
| ); | ||
| } | ||
| var defu = createDefu(); | ||
| var defuFn = createDefu((object, key, currentValue) => { | ||
| if (object[key] !== void 0 && typeof currentValue === "function") { | ||
| object[key] = currentValue(object[key]); | ||
| return true; | ||
| } | ||
| }); | ||
| var defuArrayFn = createDefu((object, key, currentValue) => { | ||
| if (Array.isArray(object[key]) && typeof currentValue === "function") { | ||
| object[key] = currentValue(object[key]); | ||
| return true; | ||
| } | ||
| }); | ||
| // src/core.ts | ||
| import { consola } from "consola"; | ||
| import { filename } from "pathe/utils"; | ||
| import { extname } from "pathe"; | ||
| import { loadConfig } from "c12"; | ||
| // src/scan.ts | ||
| import { globby } from "globby"; | ||
| import { join, relative } from "pathe"; | ||
| var GLOB_SCAN_PATTERN = "**/*"; | ||
| async function scanDir(pergel, dir, folderName) { | ||
| const fileNames = await globby(join(folderName ?? "", GLOB_SCAN_PATTERN), { | ||
| cwd: dir, | ||
| dot: true, | ||
| ignore: pergel.options.ignore, | ||
| absolute: true | ||
| }); | ||
| return fileNames.map((fullPath) => { | ||
| return { | ||
| fullPath, | ||
| path: relative(join(dir, folderName ?? ""), fullPath) | ||
| }; | ||
| }).sort((a, b) => a.path.localeCompare(b.path)); | ||
| } | ||
| async function scanFiles(pergel, folderName) { | ||
| const files = await Promise.all( | ||
| pergel.options.scanDirs.map((dir) => scanDir(pergel, dir, folderName)) | ||
| ).then((r) => r.flat()); | ||
| return files; | ||
| } | ||
| async function scanAnyFiles(pergel, folderName) { | ||
| const files = await scanFiles(pergel, folderName); | ||
| return files.map((f) => f.fullPath); | ||
| } | ||
| // src/core.ts | ||
| var logger = consola.create({ | ||
| defaults: { | ||
| tag: "pergel:download" | ||
| } | ||
| }); | ||
| function definePergel(config) { | ||
| return config; | ||
| } | ||
| function defineDownload(options) { | ||
| async function setup(data) { | ||
| const { cwd } = data; | ||
| const githubRepo = "github:oku-ui/pergel"; | ||
| const projectName = options.projectName; | ||
| const firstLetterProjectName = projectName.charAt(0).toUpperCase() + projectName.slice(1); | ||
| options = defu(options, { | ||
| tempOutput: ".tempPergel", | ||
| branch: "main" | ||
| }); | ||
| if (options.file?.dir) { | ||
| const { dir } = await downloadTemplate(join2(githubRepo, `${options.file.dir}#${options.branch}`), { | ||
| dir: options.tempOutput, | ||
| cwd, | ||
| force: true | ||
| }); | ||
| for (const file of options.file.path) { | ||
| const output = resolve(join2(cwd, file.outputFileName)); | ||
| const _dirname = dirname(output); | ||
| if (!existsSync(output)) { | ||
| if (!existsSync(_dirname)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(dir, file.fileName), "utf-8"); | ||
| if (file.replace?.from && file.replace?.to) | ||
| readFile.replace(file.replace?.from, file.replace?.to); | ||
| readFile = readFile.replace(`/changeName/g`, projectName).replace(`/ChangeName/g`, firstLetterProjectName); | ||
| writeFileSync( | ||
| resolve(output), | ||
| readFile | ||
| ); | ||
| } else if (file.forceClean) { | ||
| rmSync(output, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| if (!existsSync(_dirname)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(dir, file.fileName), "utf-8"); | ||
| if (file.replace?.from && file.replace?.to) | ||
| readFile.replace(file.replace?.from, file.replace?.to); | ||
| readFile = readFile.replace(`/changeName/g`, projectName).replace(`/ChangeName/g`, firstLetterProjectName); | ||
| writeFileSync( | ||
| resolve(output), | ||
| readFile | ||
| ); | ||
| } | ||
| logger.success(`Downloaded template file: ${output}`); | ||
| } | ||
| } | ||
| if (options.folder && options.folder.length) { | ||
| for (const folder of options.folder) { | ||
| const { dir } = await downloadTemplate(join2(githubRepo, `${folder.dir}#${options.branch}`), { | ||
| dir: options.tempOutput, | ||
| cwd, | ||
| force: true, | ||
| forceClean: folder.forceClean !== false | ||
| }); | ||
| if (!existsSync(resolve(folder.output))) { | ||
| mkdirSync(resolve(folder.output), { | ||
| recursive: true | ||
| }); | ||
| } | ||
| const scanDir2 = await scanAnyFiles({ | ||
| options: { | ||
| scanDirs: [folder.dir] | ||
| } | ||
| }, dir); | ||
| if (scanDir2.length > 0) { | ||
| for (const file of scanDir2) { | ||
| const _output = join2(folder.output, file.replace(dir, "")); | ||
| const _dirname = dirname(_output); | ||
| const _file = filename(_output) + extname(_output); | ||
| if (!existsSync(_output)) { | ||
| mkdirSync(_dirname, { | ||
| recursive: true | ||
| }); | ||
| } | ||
| let readFile = readFileSync(join2(file), "utf-8"); | ||
| if (folder.replace?.from !== "changeName") | ||
| readFile.replace(folder.replace?.from || "changeName", folder.replace?.to || projectName); | ||
| readFile = readFile.replace(/changeName/g, projectName).replace(/ChangeName/g, firstLetterProjectName); | ||
| writeFileSync( | ||
| join2(_output), | ||
| readFile | ||
| ); | ||
| logger.success(`Downloaded template folder: ${_file}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| rmSync(options.tempOutput, { | ||
| recursive: true, | ||
| force: true | ||
| }); | ||
| } | ||
| return setup; | ||
| } | ||
| async function definePergelLoadConfig(input) { | ||
| const file = await loadConfig({ | ||
| cwd: input?.cwd ?? process.cwd(), | ||
| configFile: "pergel.config.ts", | ||
| defaultConfig: { | ||
| dir: { | ||
| pergel: "pergel", | ||
| template: "pergel/templates", | ||
| server: "server" | ||
| }, | ||
| filePath: { | ||
| nuxtConfig: "nuxt.config.ts" | ||
| } | ||
| } | ||
| }); | ||
| return file; | ||
| } | ||
| export { | ||
| definePergel, | ||
| defineDownload, | ||
| definePergelLoadConfig | ||
| }; |
| import { | ||
| defineDownload, | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| // src/commands/download.ts | ||
| import { join, resolve } from "node:path"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { defineCommand } from "citty"; | ||
| import consola from "consola"; | ||
| var logger = consola.create({ | ||
| defaults: { | ||
| tag: "pergel:download" | ||
| } | ||
| }); | ||
| var download_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Download", | ||
| description: "Download Nuxt Template", | ||
| version: "0.0.1" | ||
| }, | ||
| args: { | ||
| jsonFile: { | ||
| alias: "j", | ||
| description: "Download file" | ||
| }, | ||
| template: { | ||
| alias: "t", | ||
| description: "Download file" | ||
| }, | ||
| projectName: { | ||
| alias: "p", | ||
| description: "Project name" | ||
| } | ||
| }, | ||
| async run({ args }) { | ||
| const template = args.template; | ||
| const jsonFile = args.jsonFile; | ||
| const projectName = args.projectName; | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| logger.error("No config file found"); | ||
| return; | ||
| } | ||
| const templateDir = resolve(file.config.dir.template); | ||
| const data = readFileSync(join(templateDir, `${jsonFile}.json`), "utf-8"); | ||
| if (!data) { | ||
| logger.error(`No file found for ${file}`); | ||
| return; | ||
| } | ||
| const jsonData = JSON.parse(data); | ||
| if (!jsonData) { | ||
| logger.error(`No data found for ${file}`); | ||
| return; | ||
| } | ||
| if (!jsonData) { | ||
| logger.error(`No template found for ${template}`); | ||
| return; | ||
| } | ||
| if (jsonData) { | ||
| logger.info(`Downloading template: ${template} ...`); | ||
| const data2 = defineDownload({ | ||
| file: jsonData.file, | ||
| folder: jsonData.folder, | ||
| branch: jsonData.branch, | ||
| tempOutput: ".tempPergel", | ||
| projectName | ||
| }); | ||
| await data2({ | ||
| cwd: process.cwd() | ||
| }); | ||
| logger.success(`Downloaded template: ${template}`); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| download_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| // src/commands/install.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { consola } from "consola"; | ||
| import { parseNa, parseNi, run } from "@antfu/ni"; | ||
| var install_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Install", | ||
| description: "Install dependencies from README.json", | ||
| version: "0.2.0" | ||
| }, | ||
| async run() { | ||
| const args = process.argv.slice(2).filter((arg) => arg !== "install" && arg !== "pergel"); | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(join(file.config.dir?.pergel, "README.json")), "utf-8"); | ||
| const jsonData = JSON.parse(readmeString); | ||
| const dependencies = /* @__PURE__ */ new Set(); | ||
| const devDependencies = /* @__PURE__ */ new Set(); | ||
| for (const [_moduleName, moduleData] of Object.entries(jsonData)) { | ||
| if (!moduleData) | ||
| continue; | ||
| for (const [_projectName, projectData] of Object.entries(moduleData)) { | ||
| if (!projectData) { | ||
| consola.error(`No project data found for ${_projectName}`); | ||
| continue; | ||
| } | ||
| if (projectData.packageJson) { | ||
| if (projectData.packageJson.dependencies) { | ||
| const debs = Object.keys(projectData.packageJson.dependencies); | ||
| if (debs.length) { | ||
| for (const item of debs) { | ||
| if (item) | ||
| dependencies.add(`${item}@${projectData.packageJson.dependencies[item]}`); | ||
| } | ||
| } | ||
| } | ||
| if (projectData.packageJson.devDependencies) { | ||
| const debs = Object.keys(projectData.packageJson.devDependencies); | ||
| if (debs.length) { | ||
| for (const item of debs) { | ||
| if (item) | ||
| devDependencies.add(`${item}@${projectData.packageJson.devDependencies[item]}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (dependencies.size) { | ||
| await run(parseNi, [...dependencies.values(), ...args]).then(() => { | ||
| consola.success("Dependencies installed", dependencies.values()); | ||
| }).catch((res) => { | ||
| consola.error(res); | ||
| }); | ||
| } | ||
| if (devDependencies.size) { | ||
| await run(parseNi, [...devDependencies.values(), "-D", ...args]).then(() => { | ||
| consola.success("Dev dependencies installed", devDependencies.values()); | ||
| }).catch((res) => { | ||
| consola.error(res); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| consola.info("Please run `pergel init` to create a config folder. After that, you can run `pergel install` to install dependencies."); | ||
| const confirm = await consola.prompt("Would you like to run `pergel init` now?", { | ||
| type: "confirm" | ||
| }); | ||
| if (confirm) { | ||
| await run(parseNa, ["pergel", "init"], { programmatic: true }).then(async () => { | ||
| consola.success("Config folder created"); | ||
| await run(parseNa, ["nuxt", "prepare"], { programmatic: true }).then(() => { | ||
| consola.success("Nuxt prepared"); | ||
| }); | ||
| }).catch(() => { | ||
| consola.error("Failed to create config folder"); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| install_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| // src/commands/module.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { consola } from "consola"; | ||
| import { parseNa, run } from "@antfu/ni"; | ||
| var module_default = defineCommand({ | ||
| meta: { | ||
| name: "Module Command", | ||
| description: "Module Command", | ||
| version: "0.0.0" | ||
| }, | ||
| args: { | ||
| project: { | ||
| type: "string", | ||
| description: "Name of the project", | ||
| alias: "p" | ||
| }, | ||
| module: { | ||
| type: "string", | ||
| description: "Name of the module", | ||
| alias: "m" | ||
| }, | ||
| script: { | ||
| type: "string", | ||
| description: "Name of the script", | ||
| alias: "s" | ||
| } | ||
| }, | ||
| async run({ args }) { | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(file.config.dir.pergel, "README.json")).toString(); | ||
| const project = JSON.parse(readmeString)[args.project ?? ""]?.[args.module ?? ""]; | ||
| const script = project?.scripts ?? {}; | ||
| if (Object.keys(script).length === 0) | ||
| consola.error("No script found"); | ||
| const selectedScript = script[args.script ?? ""]; | ||
| if (!selectedScript) | ||
| consola.error("No script found"); | ||
| try { | ||
| await run(async (agent, args2, ctx) => { | ||
| const command = await parseNa(agent, args2, ctx); | ||
| return command ? command.replace(/"/g, "") : void 0; | ||
| }, [selectedScript], { programmatic: true }).then(() => { | ||
| consola.success("Script executed successfully"); | ||
| }).catch((error) => { | ||
| consola.error(error); | ||
| }); | ||
| } catch (error) { | ||
| consola.error(error); | ||
| } | ||
| } catch (error) { | ||
| consola.log(error); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| module_default as default | ||
| }; |
| import { | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| // src/commands/select.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { execSync } from "node:child_process"; | ||
| import { intro, select } from "@clack/prompts"; | ||
| import { defineCommand } from "citty"; | ||
| import consola from "consola"; | ||
| var select_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Upgrade", | ||
| description: "Upgrade Pergel CLI", | ||
| version: "0.0.1" | ||
| }, | ||
| async run() { | ||
| try { | ||
| const file = await definePergelLoadConfig(); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| intro("Oku Pergel Select CLI"); | ||
| const readmeString = readFileSync(resolve(join(file.config.dir?.pergel, "README.json")), "utf-8"); | ||
| const jsonData = JSON.parse(readmeString); | ||
| const projectNames = Object.keys(jsonData).filter((i) => { | ||
| const project = jsonData[i]; | ||
| if (!project) | ||
| return false; | ||
| for (const key in project) { | ||
| if (project[key].cli) | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| if (!projectNames.length) { | ||
| consola.error("No projects found"); | ||
| return; | ||
| } | ||
| const selectedProject = await select({ | ||
| message: "Select a project", | ||
| options: projectNames.map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| const selectedProjectData = jsonData[selectedProject]; | ||
| const cliModules = Object.keys(selectedProjectData).filter((i) => { | ||
| const cli = selectedProjectData[i].cli; | ||
| if (cli) | ||
| return true; | ||
| return false; | ||
| }); | ||
| const selectedModule = await select({ | ||
| message: "Select a module", | ||
| options: cliModules.map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| if (selectedModule) { | ||
| const selectedCli = await select({ | ||
| message: "Select a cli command", | ||
| options: Object.keys(selectedProjectData[selectedModule].cli).map((i) => ({ | ||
| label: i, | ||
| value: i | ||
| })) | ||
| }); | ||
| const cliData = selectedProjectData[selectedModule].cli[selectedCli]; | ||
| if (cliData) { | ||
| consola.info(`Running ${cliData}`); | ||
| execSync( | ||
| cliData, | ||
| { | ||
| stdio: "inherit" | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| consola.error(error); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| select_default as default | ||
| }; |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
1
-50%56563
-0.01%