@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.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 { parseNi, run } from "@antfu/ni"; | ||
| var install_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Install", | ||
| description: "Install dependencies from README.json", | ||
| version: "0.1.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); | ||
| debs.forEach((item) => { | ||
| if (item) | ||
| dependencies.add(item); | ||
| }); | ||
| } | ||
| if (projectData.packageJson.devDependencies) { | ||
| const debs = Object.keys(projectData.packageJson.devDependencies); | ||
| debs.forEach((item) => { | ||
| if (item) | ||
| devDependencies.add(item); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (dependencies.size) { | ||
| await run(parseNi, [...dependencies.values(), ...args]).then(() => { | ||
| consola.success("Dependencies installed", dependencies.values()); | ||
| }); | ||
| } | ||
| if (devDependencies.size) { | ||
| await run(parseNi, [...devDependencies.values(), "-D", ...args]).then(() => { | ||
| consola.success("Dev dependencies installed", devDependencies.values()); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| consola.log(error); | ||
| } | ||
| } | ||
| }); | ||
| 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 | ||
| }; |
+6
-2
@@ -1,2 +0,3 @@ | ||
| import { PergelConfig, DefineDownloadOptions } from './types.js'; | ||
| import * as c12 from 'c12'; | ||
| import { PergelConfig, DefineDownloadOptions, ResolvedPergelConfig } from './types.js'; | ||
@@ -7,3 +8,6 @@ declare function definePergel(config: PergelConfig): PergelConfig; | ||
| }) => Promise<void>; | ||
| declare function definePergelLoadConfig(input?: { | ||
| cwd?: string; | ||
| }): Promise<c12.ResolvedConfig<ResolvedPergelConfig, c12.ConfigLayerMeta>>; | ||
| export { defineDownload, definePergel }; | ||
| export { defineDownload, definePergel, definePergelLoadConfig }; |
+5
-3
| import { | ||
| defineDownload, | ||
| definePergel | ||
| } from "./chunk-G4ICTAII.js"; | ||
| definePergel, | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
| export { | ||
| defineDownload, | ||
| definePergel | ||
| definePergel, | ||
| definePergelLoadConfig | ||
| }; |
+2
-1
@@ -1,2 +0,3 @@ | ||
| export { definePergel } from './core.js'; | ||
| export { definePergel, definePergelLoadConfig } from './core.js'; | ||
| import 'c12'; | ||
| import './types.js'; | ||
@@ -3,0 +4,0 @@ |
+9
-18
| import { | ||
| definePergel | ||
| } from "./chunk-G4ICTAII.js"; | ||
| definePergel, | ||
| definePergelLoadConfig | ||
| } from "./chunk-ZFO3AWCZ.js"; | ||
@@ -12,3 +13,3 @@ // src/index.ts | ||
| type: "module", | ||
| version: "0.5.3", | ||
| version: "0.6.0", | ||
| packageManager: "pnpm@8.10.0", | ||
@@ -53,12 +54,2 @@ description: "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.", | ||
| types: "./dist/index.d.ts", | ||
| typesVersions: { | ||
| "*": { | ||
| "*": [ | ||
| "./dist/*" | ||
| ], | ||
| "types/*": [ | ||
| "./dist/types.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
| bin: { | ||
@@ -98,4 +89,3 @@ pergel: "bin/pergel.mjs" | ||
| picocolors: "^1.0.0", | ||
| shelljs: "^0.8.5", | ||
| yaml: "^2.3.4" | ||
| shelljs: "^0.8.5" | ||
| }, | ||
@@ -132,5 +122,5 @@ devDependencies: { | ||
| init: () => import("./init-AL3HDDW6.js").then((m) => m.default), | ||
| install: () => import("./install-RXMICQVQ.js").then((m) => m.default), | ||
| module: () => import("./module-GBDIH6BW.js").then((m) => m.default), | ||
| download: () => import("./download-NFLEWXQT.js").then((m) => m.default) | ||
| install: () => import("./install-DVILQPC3.js").then((m) => m.default), | ||
| module: () => import("./module-5VMCAOPO.js").then((m) => m.default), | ||
| download: () => import("./download-4FGI6T2M.js").then((m) => m.default) | ||
| }, | ||
@@ -145,3 +135,4 @@ run({ args }) { | ||
| definePergel, | ||
| definePergelLoadConfig, | ||
| runMain | ||
| }; |
+2
-2
@@ -59,3 +59,3 @@ interface Pergel { | ||
| } | ||
| interface PergelYaml { | ||
| interface PergelReadme { | ||
| [moduleName: string]: { | ||
@@ -173,2 +173,2 @@ [projectName: string]: { | ||
| export type { DefineDownloadOptions, DefinePergel, Pergel, PergelConfig, PergelYaml, ResolvedPergelConfig }; | ||
| export type { DefineDownloadOptions, DefinePergel, Pergel, PergelConfig, PergelReadme, ResolvedPergelConfig }; |
+2
-13
| { | ||
| "name": "@pergel/cli", | ||
| "type": "module", | ||
| "version": "0.5.3", | ||
| "version": "0.6.0", | ||
| "packageManager": "pnpm@8.10.0", | ||
@@ -44,12 +44,2 @@ "description": "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.", | ||
| "types": "./dist/index.d.ts", | ||
| "typesVersions": { | ||
| "*": { | ||
| "*": [ | ||
| "./dist/*" | ||
| ], | ||
| "types/*": [ | ||
| "./dist/types.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
| "bin": { | ||
@@ -78,4 +68,3 @@ "pergel": "bin/pergel.mjs" | ||
| "picocolors": "^1.0.0", | ||
| "shelljs": "^0.8.5", | ||
| "yaml": "^2.3.4" | ||
| "shelljs": "^0.8.5" | ||
| }, | ||
@@ -82,0 +71,0 @@ "devDependencies": { |
| // 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"; | ||
| // 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; | ||
| } | ||
| export { | ||
| definePergel, | ||
| defineDownload | ||
| }; |
| import { | ||
| defineDownload | ||
| } from "./chunk-G4ICTAII.js"; | ||
| // src/commands/download.ts | ||
| import { join, resolve } from "node:path"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { defineCommand } from "citty"; | ||
| import { loadConfig } from "c12"; | ||
| 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 loadConfig({ | ||
| cwd: process.cwd(), | ||
| configFile: "pergel.config.ts", | ||
| defaultConfig: { | ||
| dir: { | ||
| pergel: "pergel", | ||
| template: "pergel/templates" | ||
| }, | ||
| filePath: { | ||
| nuxtConfig: "nuxt.config.ts" | ||
| } | ||
| } | ||
| }); | ||
| 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.templates[template]) { | ||
| logger.error(`No template found for ${template}`); | ||
| return; | ||
| } | ||
| const _template = jsonData.templates[template]; | ||
| if (_template) { | ||
| logger.info(`Downloading template: ${template} ...`); | ||
| const data2 = defineDownload({ | ||
| file: _template.file, | ||
| folder: _template.folder, | ||
| branch: _template.branch, | ||
| tempOutput: ".tempPergel", | ||
| projectName | ||
| }); | ||
| await data2({ | ||
| cwd: process.cwd() | ||
| }); | ||
| logger.success(`Downloaded template: ${template}`); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| download_default as default | ||
| }; |
| // src/commands/install.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { loadConfig } from "c12"; | ||
| import { consola } from "consola"; | ||
| import { parse } from "yaml"; | ||
| import { parseNi, run } from "@antfu/ni"; | ||
| var install_default = defineCommand({ | ||
| meta: { | ||
| name: "Pergel Install", | ||
| description: "Install dependencies from README.yaml", | ||
| version: "0.0.1" | ||
| }, | ||
| async run() { | ||
| const args = process.argv.slice(2).filter((arg) => arg !== "install" && arg !== "pergel"); | ||
| try { | ||
| const file = await loadConfig({ | ||
| cwd: process.cwd(), | ||
| configFile: "pergel.config.ts", | ||
| defaultConfig: { | ||
| dir: { | ||
| pergel: "pergel", | ||
| template: "pergel/templates", | ||
| server: "server" | ||
| }, | ||
| filePath: { | ||
| nuxtConfig: "nuxt.config.ts" | ||
| } | ||
| }, | ||
| rcFile: false, | ||
| jitiOptions: { | ||
| interopDefault: true, | ||
| esmResolve: true | ||
| } | ||
| }); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(join(file.config.dir?.pergel, "README.yaml"))).toString(); | ||
| const json = parse(readmeString); | ||
| const selectProject = json; | ||
| const dependencies = /* @__PURE__ */ new Set(); | ||
| const devDependencies = /* @__PURE__ */ new Set(); | ||
| for (const [_moduleName, moduleData] of Object.entries(selectProject)) { | ||
| 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 deps = projectData.packageJson.dependencies.split(",").map((item) => item.trim()); | ||
| deps.forEach((item) => { | ||
| if (item) | ||
| dependencies.add(item); | ||
| }); | ||
| } | ||
| if (projectData.packageJson.devDependencies) { | ||
| const deps = projectData.packageJson.devDependencies.split(",").map((item) => item.trim()); | ||
| deps.forEach((item) => { | ||
| if (item) | ||
| devDependencies.add(item); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (dependencies.size) { | ||
| await run(parseNi, [...dependencies.values(), ...args]).then(() => { | ||
| consola.success("Dependencies installed", dependencies.values()); | ||
| }); | ||
| } | ||
| if (devDependencies.size) { | ||
| await run(parseNi, [...devDependencies.values(), "-D", ...args]).then(() => { | ||
| consola.success("Dev dependencies installed", devDependencies.values()); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| consola.log(error); | ||
| } | ||
| } | ||
| }); | ||
| export { | ||
| install_default as default | ||
| }; |
| // src/commands/module.ts | ||
| import { readFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { defineCommand } from "citty"; | ||
| import { loadConfig } from "c12"; | ||
| import { consola } from "consola"; | ||
| import { parse } from "yaml"; | ||
| 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 loadConfig({ | ||
| cwd: process.cwd(), | ||
| configFile: "pergel.config.ts", | ||
| defaultConfig: { | ||
| dir: { | ||
| pergel: "pergel", | ||
| template: "pergel/templates" | ||
| }, | ||
| filePath: { | ||
| nuxtConfig: "nuxt.config.ts" | ||
| } | ||
| } | ||
| }); | ||
| if (!file.config) { | ||
| consola.error("No config file found"); | ||
| return; | ||
| } | ||
| const readmeString = readFileSync(resolve(file.config.dir.pergel, "README.yaml")).toString(); | ||
| const json = parse(readmeString); | ||
| const project = json[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 | ||
| }; |
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
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
10
-9.09%51781
-1.22%1380
-1.85%2
100%- Removed
- Removed