@libria/scaffold-plugin-ts-lib 0.0.1 → 0.0.3
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.
- package/.clean-publish.hash +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/template-files/package.json +2 -1
package/.clean-publish.hash
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
6de25407716887c132ae2e26a0bc59134f1d9e6978e5f321e586b4970104d577
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`child_process`),l=require(`path`);l=s(l);let u=require(`url`),d=require(`util`),f=require(`@libria/plugin-loader`),p=require(`@libria/scaffold-core`),m=require(`fs-extra`);m=s(m);const h=l.default.dirname((0,u.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),g=l.default.resolve(h,`..`,`template-files`),_=(0,d.promisify)(c.exec);var v=(0,f.definePlugin)({id:`libria:scaffold:ts-lib`,name:`ts-lib`,pluginType:p.SCAFFOLD_TEMPLATE_PLUGIN_TYPE,async create(e){return{api:{argument:`ts-lib`,getOptions:async e=>({packageName:{flags:`--package-name
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`child_process`),l=require(`path`);l=s(l);let u=require(`url`),d=require(`util`),f=require(`@libria/plugin-loader`),p=require(`@libria/scaffold-core`),m=require(`fs-extra`);m=s(m);const h=l.default.dirname((0,u.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),g=l.default.resolve(h,`..`,`template-files`),_=(0,d.promisify)(c.exec);var v=(0,f.definePlugin)({id:`libria:scaffold:ts-lib`,name:`ts-lib`,pluginType:p.SCAFFOLD_TEMPLATE_PLUGIN_TYPE,async create(e){return{api:{argument:`ts-lib`,getOptions:async e=>({packageName:{type:`string`,flags:`--package-name <value>`,description:`Package name:`,defaultValue:e.name},description:{type:`string`,flags:`--description <value>`,description:`Description:`},version:{type:`string`,flags:`--version <value>`,description:`Version:`,defaultValue:`0.0.0`,required:!0},author:{type:`string`,flags:`--author <value>`,description:`Author:`},githubRepo:{type:`string`,flags:`--github-repo <value>`,description:`GitHub repository (owner/repo):`},gitInit:{type:`boolean`,flags:`--git-init`,description:`Initialize git repository?`},packageManager:{type:`string`,flags:`--package-manager <value>`,description:`Package Manager:`,choices:[`npm`,`yarn`,`pnpm`],defaultValue:`npm`},install:{type:`boolean`,flags:`--install`,description:`Install dependencies?`}}),execute:async e=>{await y(e),await x(e)}}}}});async function y(e){let{name:t,dryRun:n,force:r}=e,i=l.default.resolve(process.cwd(),t);await m.default.pathExists(i)&&(r||(console.error(`Directory '${t}' already exists. Use --force to overwrite.`),process.exit(1)),n?console.log(`[dry-run] Would remove existing directory: ${i}`):(await m.default.remove(i),console.log(`Removed existing directory: ${i}`))),n?console.log(`[dry-run] Would create directory: ${i}`):(await m.default.ensureDir(i),console.log(`Created directory: ${i}`)),await b(g,i,await m.default.readdir(g,{withFileTypes:!0}),n),n||await(0,p.replacePlaceholders)(i,{"{PROJECT_NAME}":e.name,"{PACKAGE_NAME}":e.packageName,"{DESCRIPTION}":e.description,"{VERSION}":e.version,"{GITHUB_REPO}":e.githubRepo,"{AUTHOR}":e.author}),n?console.log(`
|
|
2
2
|
[dry-run] No files were actually created.`):console.log(`\nProject '${t}' created successfully!`)}async function b(e,t,n,r){let i={gitignore:`.gitignore`};for(let a of n){let n=l.default.join(e,a.name),o=i[a.name]??a.name,s=l.default.join(t,o);a.isDirectory()?(r?console.log(`[dry-run] Would create directory: ${s}`):await m.default.ensureDir(s),await b(n,s,await m.default.readdir(n,{withFileTypes:!0}),r)):a.isFile()&&(r?console.log(`[dry-run] Would copy: ${a.name}`):(await m.default.copy(n,s),console.log(`Copied: ${a.name}`)))}}async function x(e){let{name:t,dryRun:n,gitInit:r,install:i,packageManager:a}=e,o=l.default.resolve(process.cwd(),t);if(n){console.log(`
|
|
3
3
|
[dry-run] Skipping post-process steps.`);return}if(r)try{console.log(`Initializing git repository...`),await _(`git init`,{cwd:o}),console.log(`Git repository initialized.`)}catch(e){console.error(`Failed to initialize git repository:`,e.message)}if(i)try{console.log(`Installing dependencies (this may take a moment)...`),await _(`${a} install`,{cwd:o}),console.log(`Dependencies installed successfully.`)}catch(e){console.error(`Failed to install dependencies:`,e.message)}console.log(`
|
|
4
4
|
All done! Your project is ready.`),console.log(`\n cd ${t}`),i||console.log(` ${a} install`),console.log(` ${a} run build`),console.log(` ${a} test`)}module.exports=v;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__dirname","exec","SCAFFOLD_TEMPLATE_PLUGIN_TYPE","fs"],"sources":["../src/ts-lib.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { promisify } from 'util';\n\nimport { definePlugin, PluginContext } from '@libria/plugin-loader';\nimport {\n ExecuteOptions,\n replacePlaceholders,\n SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n ScaffoldTemplatePlugin,\n} from '@libria/scaffold-core';\nimport fs from 'fs-extra';\n\nimport { Options } from './types';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst FILES_DIR = path.resolve(__dirname, '..', 'template-files');\n\nconst execAsync = promisify(exec);\n\nexport default definePlugin<ScaffoldTemplatePlugin<Options>>({\n id: 'libria:scaffold:ts-lib',\n name: 'ts-lib',\n pluginType: SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n\n async create(_: PluginContext) {\n return {\n api: {\n argument: 'ts-lib',\n getOptions: async (initOptions): Promise<Options> => {\n return {\n packageName: {\n flags: '--package-name',\n description: 'Package name:',\n defaultValue: initOptions.name,\n },\n description: {\n flags: '--description',\n description: 'Description:',\n },\n version: {\n flags: '--version',\n description: 'Version:',\n defaultValue: '0.0.0',\n required: true,\n },\n author: {\n flags: '--author',\n description: 'Author:',\n },\n githubRepo: {\n flags: '--github-repo',\n description: 'GitHub repository (owner/repo):',\n },\n gitInit: {\n flags: '--git-init',\n description: 'Initialize git repository?',\n defaultValue: true,\n required: false,\n },\n packageManager: {\n flags: '--package-manager',\n description: 'Package Manager (npm/yarn/pnpm):',\n choices: ['npm', 'yarn', 'pnpm'],\n defaultValue: 'npm',\n },\n install: {\n flags: '--install',\n description: 'Install dependencies?',\n defaultValue: true,\n required: false,\n },\n };\n },\n execute: async options => {\n await generateProject(options);\n await postProcess(options);\n },\n },\n };\n },\n});\n\nasync function generateProject(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, force } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n // Check if target directory exists\n if (await fs.pathExists(targetDir)) {\n if (!force) {\n console.error(`Directory '${name}' already exists. Use --force to overwrite.`);\n process.exit(1);\n }\n if (dryRun) {\n console.log(`[dry-run] Would remove existing directory: ${targetDir}`);\n } else {\n await fs.remove(targetDir);\n console.log(`Removed existing directory: ${targetDir}`);\n }\n }\n\n // Create target directory\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetDir}`);\n } else {\n await fs.ensureDir(targetDir);\n console.log(`Created directory: ${targetDir}`);\n }\n\n // Copy all files from files directory to target\n const entries = await fs.readdir(FILES_DIR, { withFileTypes: true });\n await copyEntries(FILES_DIR, targetDir, entries, dryRun);\n\n if (!dryRun) {\n await replacePlaceholders(targetDir, {\n '{PROJECT_NAME}': options.name,\n '{PACKAGE_NAME}': options.packageName,\n '{DESCRIPTION}': options.description,\n '{VERSION}': options.version,\n '{GITHUB_REPO}': options.githubRepo,\n '{AUTHOR}': options.author,\n });\n }\n\n if (dryRun) {\n console.log('\\n[dry-run] No files were actually created.');\n } else {\n console.log(`\\nProject '${name}' created successfully!`);\n }\n}\n\nasync function copyEntries(\n sourceDir: string,\n targetDir: string,\n entries: fs.Dirent[],\n dryRun?: boolean\n): Promise<void> {\n // Files that need to be renamed when copying (npm strips dotfiles like .gitignore)\n const RENAME_FILES: Record<string, string> = {\n gitignore: '.gitignore',\n };\n\n for (const entry of entries) {\n const sourcePath = path.join(sourceDir, entry.name);\n const targetName = RENAME_FILES[entry.name] ?? entry.name;\n const targetPath = path.join(targetDir, targetName);\n\n if (entry.isDirectory()) {\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetPath}`);\n } else {\n await fs.ensureDir(targetPath);\n }\n // Recursively copy directory contents\n const subEntries = await fs.readdir(sourcePath, { withFileTypes: true });\n await copyEntries(sourcePath, targetPath, subEntries, dryRun);\n } else if (entry.isFile()) {\n if (dryRun) {\n console.log(`[dry-run] Would copy: ${entry.name}`);\n } else {\n await fs.copy(sourcePath, targetPath);\n console.log(`Copied: ${entry.name}`);\n }\n }\n }\n}\n\nasync function postProcess(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, gitInit, install, packageManager } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n if (dryRun) {\n console.log('\\n[dry-run] Skipping post-process steps.');\n return;\n }\n\n if (gitInit) {\n try {\n console.log('Initializing git repository...');\n await execAsync('git init', { cwd: targetDir });\n console.log('Git repository initialized.');\n } catch (error) {\n console.error('Failed to initialize git repository:', (error as Error).message);\n }\n }\n\n if (install) {\n try {\n console.log('Installing dependencies (this may take a moment)...');\n\n await execAsync(`${packageManager} install`, { cwd: targetDir });\n console.log('Dependencies installed successfully.');\n } catch (error) {\n console.error('Failed to install dependencies:', (error as Error).message);\n }\n }\n\n console.log('\\nAll done! Your project is ready.');\n console.log(`\\n cd ${name}`);\n if (!install) {\n console.log(` ${packageManager} install`);\n }\n console.log(` ${packageManager} run build`);\n console.log(` ${packageManager} test`);\n}\n"],"mappings":"gqBAgBA,MAAMA,EAAY,EAAA,QAAK,SAAA,EAAA,EAAA,eAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,KAAsC,CAAC,CACxD,EAAY,EAAA,QAAK,QAAQA,EAAW,KAAM,iBAAiB,CAE3D,GAAA,EAAA,EAAA,WAAsBC,EAAAA,KAAK,CAEjC,IAAA,GAAA,EAAA,EAAA,cAA6D,CACzD,GAAI,yBACJ,KAAM,SACN,WAAYC,EAAAA,8BAEZ,MAAM,OAAO,EAAkB,CAC3B,MAAO,CACH,IAAK,CACD,SAAU,SACV,WAAY,KAAO,KACR,CACH,YAAa,CACT,MAAO,iBACP,YAAa,gBACb,aAAc,EAAY,KAC7B,CACD,YAAa,CACT,MAAO,gBACP,YAAa,eAChB,CACD,QAAS,CACL,MAAO,YACP,YAAa,WACb,aAAc,QACd,SAAU,GACb,CACD,OAAQ,CACJ,MAAO,WACP,YAAa,UAChB,CACD,WAAY,CACR,MAAO,gBACP,YAAa,kCAChB,CACD,QAAS,CACL,MAAO,aACP,YAAa,6BACb,aAAc,GACd,SAAU,GACb,CACD,eAAgB,CAC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E","fs"],"sources":["../src/ts-lib.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { promisify } from 'util';\n\nimport { definePlugin, PluginContext } from '@libria/plugin-loader';\nimport {\n ExecuteOptions,\n replacePlaceholders,\n SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n ScaffoldTemplatePlugin,\n} from '@libria/scaffold-core';\nimport fs from 'fs-extra';\n\nimport { Options } from './types';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst FILES_DIR = path.resolve(__dirname, '..', 'template-files');\n\nconst execAsync = promisify(exec);\n\nexport default definePlugin<ScaffoldTemplatePlugin<Options>>({\n id: 'libria:scaffold:ts-lib',\n name: 'ts-lib',\n pluginType: SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n\n async create(_: PluginContext) {\n return {\n api: {\n argument: 'ts-lib',\n getOptions: async (initOptions): Promise<Options> => {\n return {\n packageName: {\n type: 'string',\n flags: '--package-name <value>',\n description: 'Package name:',\n defaultValue: initOptions.name,\n },\n description: {\n type: 'string',\n flags: '--description <value>',\n description: 'Description:',\n },\n version: {\n type: 'string',\n flags: '--version <value>',\n description: 'Version:',\n defaultValue: '0.0.0',\n required: true,\n },\n author: {\n type: 'string',\n flags: '--author <value>',\n description: 'Author:',\n },\n githubRepo: {\n type: 'string',\n flags: '--github-repo <value>',\n description: 'GitHub repository (owner/repo):',\n },\n gitInit: {\n type: 'boolean',\n flags: '--git-init',\n description: 'Initialize git repository?',\n },\n packageManager: {\n type: 'string',\n flags: '--package-manager <value>',\n description: 'Package Manager:',\n choices: ['npm', 'yarn', 'pnpm'],\n defaultValue: 'npm',\n },\n install: {\n type: 'boolean',\n flags: '--install',\n description: 'Install dependencies?',\n },\n };\n },\n execute: async options => {\n await generateProject(options);\n await postProcess(options);\n },\n },\n };\n },\n});\n\nasync function generateProject(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, force } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n // Check if target directory exists\n if (await fs.pathExists(targetDir)) {\n if (!force) {\n console.error(`Directory '${name}' already exists. Use --force to overwrite.`);\n process.exit(1);\n }\n if (dryRun) {\n console.log(`[dry-run] Would remove existing directory: ${targetDir}`);\n } else {\n await fs.remove(targetDir);\n console.log(`Removed existing directory: ${targetDir}`);\n }\n }\n\n // Create target directory\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetDir}`);\n } else {\n await fs.ensureDir(targetDir);\n console.log(`Created directory: ${targetDir}`);\n }\n\n // Copy all files from files directory to target\n const entries = await fs.readdir(FILES_DIR, { withFileTypes: true });\n await copyEntries(FILES_DIR, targetDir, entries, dryRun);\n\n if (!dryRun) {\n await replacePlaceholders(targetDir, {\n '{PROJECT_NAME}': options.name,\n '{PACKAGE_NAME}': options.packageName,\n '{DESCRIPTION}': options.description,\n '{VERSION}': options.version,\n '{GITHUB_REPO}': options.githubRepo,\n '{AUTHOR}': options.author,\n });\n }\n\n if (dryRun) {\n console.log('\\n[dry-run] No files were actually created.');\n } else {\n console.log(`\\nProject '${name}' created successfully!`);\n }\n}\n\nasync function copyEntries(\n sourceDir: string,\n targetDir: string,\n entries: fs.Dirent[],\n dryRun?: boolean\n): Promise<void> {\n // Files that need to be renamed when copying (npm strips dotfiles like .gitignore)\n const RENAME_FILES: Record<string, string> = {\n gitignore: '.gitignore',\n };\n\n for (const entry of entries) {\n const sourcePath = path.join(sourceDir, entry.name);\n const targetName = RENAME_FILES[entry.name] ?? entry.name;\n const targetPath = path.join(targetDir, targetName);\n\n if (entry.isDirectory()) {\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetPath}`);\n } else {\n await fs.ensureDir(targetPath);\n }\n // Recursively copy directory contents\n const subEntries = await fs.readdir(sourcePath, { withFileTypes: true });\n await copyEntries(sourcePath, targetPath, subEntries, dryRun);\n } else if (entry.isFile()) {\n if (dryRun) {\n console.log(`[dry-run] Would copy: ${entry.name}`);\n } else {\n await fs.copy(sourcePath, targetPath);\n console.log(`Copied: ${entry.name}`);\n }\n }\n }\n}\n\nasync function postProcess(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, gitInit, install, packageManager } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n if (dryRun) {\n console.log('\\n[dry-run] Skipping post-process steps.');\n return;\n }\n\n if (gitInit) {\n try {\n console.log('Initializing git repository...');\n await execAsync('git init', { cwd: targetDir });\n console.log('Git repository initialized.');\n } catch (error) {\n console.error('Failed to initialize git repository:', (error as Error).message);\n }\n }\n\n if (install) {\n try {\n console.log('Installing dependencies (this may take a moment)...');\n\n await execAsync(`${packageManager} install`, { cwd: targetDir });\n console.log('Dependencies installed successfully.');\n } catch (error) {\n console.error('Failed to install dependencies:', (error as Error).message);\n }\n }\n\n console.log('\\nAll done! Your project is ready.');\n console.log(`\\n cd ${name}`);\n if (!install) {\n console.log(` ${packageManager} install`);\n }\n console.log(` ${packageManager} run build`);\n console.log(` ${packageManager} test`);\n}\n"],"mappings":"gqBAgBA,MAAMA,EAAY,EAAA,QAAK,SAAA,EAAA,EAAA,eAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,KAAsC,CAAC,CACxD,EAAY,EAAA,QAAK,QAAQA,EAAW,KAAM,iBAAiB,CAE3D,GAAA,EAAA,EAAA,WAAsBC,EAAAA,KAAK,CAEjC,IAAA,GAAA,EAAA,EAAA,cAA6D,CACzD,GAAI,yBACJ,KAAM,SACN,WAAYC,EAAAA,8BAEZ,MAAM,OAAO,EAAkB,CAC3B,MAAO,CACH,IAAK,CACD,SAAU,SACV,WAAY,KAAO,KACR,CACH,YAAa,CACT,KAAM,SACN,MAAO,yBACP,YAAa,gBACb,aAAc,EAAY,KAC7B,CACD,YAAa,CACT,KAAM,SACN,MAAO,wBACP,YAAa,eAChB,CACD,QAAS,CACL,KAAM,SACN,MAAO,oBACP,YAAa,WACb,aAAc,QACd,SAAU,GACb,CACD,OAAQ,CACJ,KAAM,SACN,MAAO,mBACP,YAAa,UA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AY,CAC5C,QAAQ,IAAI,KAAK,EAAe,OAAO"}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,14 +3,14 @@ import { ScaffoldTemplatePlugin, ScaffoldTemplatePluginOption } from "@libria/sc
|
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
interface Options {
|
|
6
|
-
packageName: ScaffoldTemplatePluginOption<string>;
|
|
7
|
-
description: ScaffoldTemplatePluginOption<string>;
|
|
8
|
-
version: ScaffoldTemplatePluginOption<string>;
|
|
9
|
-
author: ScaffoldTemplatePluginOption<string>;
|
|
10
|
-
githubRepo: ScaffoldTemplatePluginOption<string>;
|
|
11
|
-
gitInit: ScaffoldTemplatePluginOption<boolean>;
|
|
12
|
-
install: ScaffoldTemplatePluginOption<boolean>;
|
|
13
|
-
packageManager: ScaffoldTemplatePluginOption<string>;
|
|
6
|
+
packageName: ScaffoldTemplatePluginOption<'string'>;
|
|
7
|
+
description: ScaffoldTemplatePluginOption<'string'>;
|
|
8
|
+
version: ScaffoldTemplatePluginOption<'string'>;
|
|
9
|
+
author: ScaffoldTemplatePluginOption<'string'>;
|
|
10
|
+
githubRepo: ScaffoldTemplatePluginOption<'string'>;
|
|
11
|
+
gitInit: ScaffoldTemplatePluginOption<'boolean'>;
|
|
12
|
+
install: ScaffoldTemplatePluginOption<'boolean'>;
|
|
13
|
+
packageManager: ScaffoldTemplatePluginOption<'string'>;
|
|
14
14
|
}
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/ts-lib.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -3,14 +3,14 @@ import { ScaffoldTemplatePlugin, ScaffoldTemplatePluginOption } from "@libria/sc
|
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
interface Options {
|
|
6
|
-
packageName: ScaffoldTemplatePluginOption<string>;
|
|
7
|
-
description: ScaffoldTemplatePluginOption<string>;
|
|
8
|
-
version: ScaffoldTemplatePluginOption<string>;
|
|
9
|
-
author: ScaffoldTemplatePluginOption<string>;
|
|
10
|
-
githubRepo: ScaffoldTemplatePluginOption<string>;
|
|
11
|
-
gitInit: ScaffoldTemplatePluginOption<boolean>;
|
|
12
|
-
install: ScaffoldTemplatePluginOption<boolean>;
|
|
13
|
-
packageManager: ScaffoldTemplatePluginOption<string>;
|
|
6
|
+
packageName: ScaffoldTemplatePluginOption<'string'>;
|
|
7
|
+
description: ScaffoldTemplatePluginOption<'string'>;
|
|
8
|
+
version: ScaffoldTemplatePluginOption<'string'>;
|
|
9
|
+
author: ScaffoldTemplatePluginOption<'string'>;
|
|
10
|
+
githubRepo: ScaffoldTemplatePluginOption<'string'>;
|
|
11
|
+
gitInit: ScaffoldTemplatePluginOption<'boolean'>;
|
|
12
|
+
install: ScaffoldTemplatePluginOption<'boolean'>;
|
|
13
|
+
packageManager: ScaffoldTemplatePluginOption<'string'>;
|
|
14
14
|
}
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/ts-lib.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{exec as e}from"child_process";import t from"path";import{fileURLToPath as n}from"url";import{promisify as r}from"util";import{definePlugin as i}from"@libria/plugin-loader";import{SCAFFOLD_TEMPLATE_PLUGIN_TYPE as a,replacePlaceholders as o}from"@libria/scaffold-core";import s from"fs-extra";const c=t.dirname(n(import.meta.url)),l=t.resolve(c,`..`,`template-files`),u=r(e);var d=i({id:`libria:scaffold:ts-lib`,name:`ts-lib`,pluginType:a,async create(e){return{api:{argument:`ts-lib`,getOptions:async e=>({packageName:{flags:`--package-name
|
|
1
|
+
import{exec as e}from"child_process";import t from"path";import{fileURLToPath as n}from"url";import{promisify as r}from"util";import{definePlugin as i}from"@libria/plugin-loader";import{SCAFFOLD_TEMPLATE_PLUGIN_TYPE as a,replacePlaceholders as o}from"@libria/scaffold-core";import s from"fs-extra";const c=t.dirname(n(import.meta.url)),l=t.resolve(c,`..`,`template-files`),u=r(e);var d=i({id:`libria:scaffold:ts-lib`,name:`ts-lib`,pluginType:a,async create(e){return{api:{argument:`ts-lib`,getOptions:async e=>({packageName:{type:`string`,flags:`--package-name <value>`,description:`Package name:`,defaultValue:e.name},description:{type:`string`,flags:`--description <value>`,description:`Description:`},version:{type:`string`,flags:`--version <value>`,description:`Version:`,defaultValue:`0.0.0`,required:!0},author:{type:`string`,flags:`--author <value>`,description:`Author:`},githubRepo:{type:`string`,flags:`--github-repo <value>`,description:`GitHub repository (owner/repo):`},gitInit:{type:`boolean`,flags:`--git-init`,description:`Initialize git repository?`},packageManager:{type:`string`,flags:`--package-manager <value>`,description:`Package Manager:`,choices:[`npm`,`yarn`,`pnpm`],defaultValue:`npm`},install:{type:`boolean`,flags:`--install`,description:`Install dependencies?`}}),execute:async e=>{await f(e),await m(e)}}}}});async function f(e){let{name:n,dryRun:r,force:i}=e,a=t.resolve(process.cwd(),n);await s.pathExists(a)&&(i||(console.error(`Directory '${n}' already exists. Use --force to overwrite.`),process.exit(1)),r?console.log(`[dry-run] Would remove existing directory: ${a}`):(await s.remove(a),console.log(`Removed existing directory: ${a}`))),r?console.log(`[dry-run] Would create directory: ${a}`):(await s.ensureDir(a),console.log(`Created directory: ${a}`)),await p(l,a,await s.readdir(l,{withFileTypes:!0}),r),r||await o(a,{"{PROJECT_NAME}":e.name,"{PACKAGE_NAME}":e.packageName,"{DESCRIPTION}":e.description,"{VERSION}":e.version,"{GITHUB_REPO}":e.githubRepo,"{AUTHOR}":e.author}),r?console.log(`
|
|
2
2
|
[dry-run] No files were actually created.`):console.log(`\nProject '${n}' created successfully!`)}async function p(e,n,r,i){let a={gitignore:`.gitignore`};for(let o of r){let r=t.join(e,o.name),c=a[o.name]??o.name,l=t.join(n,c);o.isDirectory()?(i?console.log(`[dry-run] Would create directory: ${l}`):await s.ensureDir(l),await p(r,l,await s.readdir(r,{withFileTypes:!0}),i)):o.isFile()&&(i?console.log(`[dry-run] Would copy: ${o.name}`):(await s.copy(r,l),console.log(`Copied: ${o.name}`)))}}async function m(e){let{name:n,dryRun:r,gitInit:i,install:a,packageManager:o}=e,s=t.resolve(process.cwd(),n);if(r){console.log(`
|
|
3
3
|
[dry-run] Skipping post-process steps.`);return}if(i)try{console.log(`Initializing git repository...`),await u(`git init`,{cwd:s}),console.log(`Git repository initialized.`)}catch(e){console.error(`Failed to initialize git repository:`,e.message)}if(a)try{console.log(`Installing dependencies (this may take a moment)...`),await u(`${o} install`,{cwd:s}),console.log(`Dependencies installed successfully.`)}catch(e){console.error(`Failed to install dependencies:`,e.message)}console.log(`
|
|
4
4
|
All done! Your project is ready.`),console.log(`\n cd ${n}`),a||console.log(` ${o} install`),console.log(` ${o} run build`),console.log(` ${o} test`)}export{d as default};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/ts-lib.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { promisify } from 'util';\n\nimport { definePlugin, PluginContext } from '@libria/plugin-loader';\nimport {\n ExecuteOptions,\n replacePlaceholders,\n SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n ScaffoldTemplatePlugin,\n} from '@libria/scaffold-core';\nimport fs from 'fs-extra';\n\nimport { Options } from './types';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst FILES_DIR = path.resolve(__dirname, '..', 'template-files');\n\nconst execAsync = promisify(exec);\n\nexport default definePlugin<ScaffoldTemplatePlugin<Options>>({\n id: 'libria:scaffold:ts-lib',\n name: 'ts-lib',\n pluginType: SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n\n async create(_: PluginContext) {\n return {\n api: {\n argument: 'ts-lib',\n getOptions: async (initOptions): Promise<Options> => {\n return {\n packageName: {\n flags: '--package-name',\n description: 'Package name:',\n defaultValue: initOptions.name,\n },\n description: {\n flags: '--description',\n description: 'Description:',\n },\n version: {\n flags: '--version',\n description: 'Version:',\n defaultValue: '0.0.0',\n required: true,\n },\n author: {\n flags: '--author',\n description: 'Author:',\n },\n githubRepo: {\n flags: '--github-repo',\n description: 'GitHub repository (owner/repo):',\n },\n gitInit: {\n flags: '--git-init',\n description: 'Initialize git repository?',\n defaultValue: true,\n required: false,\n },\n packageManager: {\n flags: '--package-manager',\n description: 'Package Manager (npm/yarn/pnpm):',\n choices: ['npm', 'yarn', 'pnpm'],\n defaultValue: 'npm',\n },\n install: {\n flags: '--install',\n description: 'Install dependencies?',\n defaultValue: true,\n required: false,\n },\n };\n },\n execute: async options => {\n await generateProject(options);\n await postProcess(options);\n },\n },\n };\n },\n});\n\nasync function generateProject(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, force } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n // Check if target directory exists\n if (await fs.pathExists(targetDir)) {\n if (!force) {\n console.error(`Directory '${name}' already exists. Use --force to overwrite.`);\n process.exit(1);\n }\n if (dryRun) {\n console.log(`[dry-run] Would remove existing directory: ${targetDir}`);\n } else {\n await fs.remove(targetDir);\n console.log(`Removed existing directory: ${targetDir}`);\n }\n }\n\n // Create target directory\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetDir}`);\n } else {\n await fs.ensureDir(targetDir);\n console.log(`Created directory: ${targetDir}`);\n }\n\n // Copy all files from files directory to target\n const entries = await fs.readdir(FILES_DIR, { withFileTypes: true });\n await copyEntries(FILES_DIR, targetDir, entries, dryRun);\n\n if (!dryRun) {\n await replacePlaceholders(targetDir, {\n '{PROJECT_NAME}': options.name,\n '{PACKAGE_NAME}': options.packageName,\n '{DESCRIPTION}': options.description,\n '{VERSION}': options.version,\n '{GITHUB_REPO}': options.githubRepo,\n '{AUTHOR}': options.author,\n });\n }\n\n if (dryRun) {\n console.log('\\n[dry-run] No files were actually created.');\n } else {\n console.log(`\\nProject '${name}' created successfully!`);\n }\n}\n\nasync function copyEntries(\n sourceDir: string,\n targetDir: string,\n entries: fs.Dirent[],\n dryRun?: boolean\n): Promise<void> {\n // Files that need to be renamed when copying (npm strips dotfiles like .gitignore)\n const RENAME_FILES: Record<string, string> = {\n gitignore: '.gitignore',\n };\n\n for (const entry of entries) {\n const sourcePath = path.join(sourceDir, entry.name);\n const targetName = RENAME_FILES[entry.name] ?? entry.name;\n const targetPath = path.join(targetDir, targetName);\n\n if (entry.isDirectory()) {\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetPath}`);\n } else {\n await fs.ensureDir(targetPath);\n }\n // Recursively copy directory contents\n const subEntries = await fs.readdir(sourcePath, { withFileTypes: true });\n await copyEntries(sourcePath, targetPath, subEntries, dryRun);\n } else if (entry.isFile()) {\n if (dryRun) {\n console.log(`[dry-run] Would copy: ${entry.name}`);\n } else {\n await fs.copy(sourcePath, targetPath);\n console.log(`Copied: ${entry.name}`);\n }\n }\n }\n}\n\nasync function postProcess(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, gitInit, install, packageManager } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n if (dryRun) {\n console.log('\\n[dry-run] Skipping post-process steps.');\n return;\n }\n\n if (gitInit) {\n try {\n console.log('Initializing git repository...');\n await execAsync('git init', { cwd: targetDir });\n console.log('Git repository initialized.');\n } catch (error) {\n console.error('Failed to initialize git repository:', (error as Error).message);\n }\n }\n\n if (install) {\n try {\n console.log('Installing dependencies (this may take a moment)...');\n\n await execAsync(`${packageManager} install`, { cwd: targetDir });\n console.log('Dependencies installed successfully.');\n } catch (error) {\n console.error('Failed to install dependencies:', (error as Error).message);\n }\n }\n\n console.log('\\nAll done! Your project is ready.');\n console.log(`\\n cd ${name}`);\n if (!install) {\n console.log(` ${packageManager} install`);\n }\n console.log(` ${packageManager} run build`);\n console.log(` ${packageManager} test`);\n}\n"],"mappings":"0SAgBA,MAAM,EAAY,EAAK,QAAQ,EAAc,OAAO,KAAK,IAAI,CAAC,CACxD,EAAY,EAAK,QAAQ,EAAW,KAAM,iBAAiB,CAE3D,EAAY,EAAU,EAAK,CAEjC,IAAA,EAAe,EA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CAChE,QAAQ,IAAI,uCAAuC,OAC9C,EAAO,CACZ,QAAQ,MAAM,kCAAoC,EAAgB,QAAQ,CAIlF,QAAQ,IAAI;kCAAqC,CACjD,QAAQ,IAAI,UAAU,IAAO,CACxB,GACD,QAAQ,IAAI,KAAK,EAAe,UAAU,CAE9C,QAAQ,IAAI,KAAK,EAAe,YAAY,CAC5C,QAAQ,IAAI,KAAK,EAAe,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/ts-lib.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { promisify } from 'util';\n\nimport { definePlugin, PluginContext } from '@libria/plugin-loader';\nimport {\n ExecuteOptions,\n replacePlaceholders,\n SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n ScaffoldTemplatePlugin,\n} from '@libria/scaffold-core';\nimport fs from 'fs-extra';\n\nimport { Options } from './types';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst FILES_DIR = path.resolve(__dirname, '..', 'template-files');\n\nconst execAsync = promisify(exec);\n\nexport default definePlugin<ScaffoldTemplatePlugin<Options>>({\n id: 'libria:scaffold:ts-lib',\n name: 'ts-lib',\n pluginType: SCAFFOLD_TEMPLATE_PLUGIN_TYPE,\n\n async create(_: PluginContext) {\n return {\n api: {\n argument: 'ts-lib',\n getOptions: async (initOptions): Promise<Options> => {\n return {\n packageName: {\n type: 'string',\n flags: '--package-name <value>',\n description: 'Package name:',\n defaultValue: initOptions.name,\n },\n description: {\n type: 'string',\n flags: '--description <value>',\n description: 'Description:',\n },\n version: {\n type: 'string',\n flags: '--version <value>',\n description: 'Version:',\n defaultValue: '0.0.0',\n required: true,\n },\n author: {\n type: 'string',\n flags: '--author <value>',\n description: 'Author:',\n },\n githubRepo: {\n type: 'string',\n flags: '--github-repo <value>',\n description: 'GitHub repository (owner/repo):',\n },\n gitInit: {\n type: 'boolean',\n flags: '--git-init',\n description: 'Initialize git repository?',\n },\n packageManager: {\n type: 'string',\n flags: '--package-manager <value>',\n description: 'Package Manager:',\n choices: ['npm', 'yarn', 'pnpm'],\n defaultValue: 'npm',\n },\n install: {\n type: 'boolean',\n flags: '--install',\n description: 'Install dependencies?',\n },\n };\n },\n execute: async options => {\n await generateProject(options);\n await postProcess(options);\n },\n },\n };\n },\n});\n\nasync function generateProject(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, force } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n // Check if target directory exists\n if (await fs.pathExists(targetDir)) {\n if (!force) {\n console.error(`Directory '${name}' already exists. Use --force to overwrite.`);\n process.exit(1);\n }\n if (dryRun) {\n console.log(`[dry-run] Would remove existing directory: ${targetDir}`);\n } else {\n await fs.remove(targetDir);\n console.log(`Removed existing directory: ${targetDir}`);\n }\n }\n\n // Create target directory\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetDir}`);\n } else {\n await fs.ensureDir(targetDir);\n console.log(`Created directory: ${targetDir}`);\n }\n\n // Copy all files from files directory to target\n const entries = await fs.readdir(FILES_DIR, { withFileTypes: true });\n await copyEntries(FILES_DIR, targetDir, entries, dryRun);\n\n if (!dryRun) {\n await replacePlaceholders(targetDir, {\n '{PROJECT_NAME}': options.name,\n '{PACKAGE_NAME}': options.packageName,\n '{DESCRIPTION}': options.description,\n '{VERSION}': options.version,\n '{GITHUB_REPO}': options.githubRepo,\n '{AUTHOR}': options.author,\n });\n }\n\n if (dryRun) {\n console.log('\\n[dry-run] No files were actually created.');\n } else {\n console.log(`\\nProject '${name}' created successfully!`);\n }\n}\n\nasync function copyEntries(\n sourceDir: string,\n targetDir: string,\n entries: fs.Dirent[],\n dryRun?: boolean\n): Promise<void> {\n // Files that need to be renamed when copying (npm strips dotfiles like .gitignore)\n const RENAME_FILES: Record<string, string> = {\n gitignore: '.gitignore',\n };\n\n for (const entry of entries) {\n const sourcePath = path.join(sourceDir, entry.name);\n const targetName = RENAME_FILES[entry.name] ?? entry.name;\n const targetPath = path.join(targetDir, targetName);\n\n if (entry.isDirectory()) {\n if (dryRun) {\n console.log(`[dry-run] Would create directory: ${targetPath}`);\n } else {\n await fs.ensureDir(targetPath);\n }\n // Recursively copy directory contents\n const subEntries = await fs.readdir(sourcePath, { withFileTypes: true });\n await copyEntries(sourcePath, targetPath, subEntries, dryRun);\n } else if (entry.isFile()) {\n if (dryRun) {\n console.log(`[dry-run] Would copy: ${entry.name}`);\n } else {\n await fs.copy(sourcePath, targetPath);\n console.log(`Copied: ${entry.name}`);\n }\n }\n }\n}\n\nasync function postProcess(options: ExecuteOptions<Options>): Promise<void> {\n const { name, dryRun, gitInit, install, packageManager } = options;\n const targetDir = path.resolve(process.cwd(), name);\n\n if (dryRun) {\n console.log('\\n[dry-run] Skipping post-process steps.');\n return;\n }\n\n if (gitInit) {\n try {\n console.log('Initializing git repository...');\n await execAsync('git init', { cwd: targetDir });\n console.log('Git repository initialized.');\n } catch (error) {\n console.error('Failed to initialize git repository:', (error as Error).message);\n }\n }\n\n if (install) {\n try {\n console.log('Installing dependencies (this may take a moment)...');\n\n await execAsync(`${packageManager} install`, { cwd: targetDir });\n console.log('Dependencies installed successfully.');\n } catch (error) {\n console.error('Failed to install dependencies:', (error as Error).message);\n }\n }\n\n console.log('\\nAll done! Your project is ready.');\n console.log(`\\n cd ${name}`);\n if (!install) {\n console.log(` ${packageManager} install`);\n }\n console.log(` ${packageManager} run build`);\n console.log(` ${packageManager} test`);\n}\n"],"mappings":"0SAgBA,MAAM,EAAY,EAAK,QAAQ,EAAc,OAAO,KAAK,IAAI,CAAC,CACxD,EAAY,EAAK,QAAQ,EAAW,KAAM,iBAAiB,CAE3D,EAAY,EAAU,EAAK,CAEjC,IAAA,EAAe,EAA8C,CACzD,GAAI,yBACJ,KAAM,SACN,WAAY,EAEZ,MAAM,OAAO,EAAkB,CAC3B,MAAO,CACH,IAAK,CACD,SAAU,SACV,WAAY,KAAO,KACR,CACH,YAAa,CACT,KAAM,SACN,MAAO,yBACP,YA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,QAAQ,IAAI,UAAU,IAAO,CACxB,GACD,QAAQ,IAAI,KAAK,EAAe,UAAU,CAE9C,QAAQ,IAAI,KAAK,EAAe,YAAY,CAC5C,QAAQ,IAAI,KAAK,EAAe,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libria/scaffold-plugin-ts-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Typescript library template for @libria/scaffold",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/LibriaForge/scaffold-starters#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@libria/plugin-loader": "^2.0.0
|
|
35
|
-
"@libria/scaffold-core": "^0.3.
|
|
34
|
+
"@libria/plugin-loader": "^2.0.0",
|
|
35
|
+
"@libria/scaffold-core": "^0.3.3",
|
|
36
36
|
"fs-extra": "^11.3.3"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "cross-env NODE_ENV=production tsdown",
|
|
21
|
+
"build": "npm run typecheck && cross-env NODE_ENV=production tsdown",
|
|
22
22
|
"build:dev": "tsdown",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
23
24
|
"test": "vitest",
|
|
24
25
|
"lint": "eslint . --ext .ts",
|
|
25
26
|
"lint:fix": "eslint . --ext .ts --fix",
|