@aenode/cli 0.0.37 → 0.0.40

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.
@@ -1,3 +1,13 @@
1
1
  import type { Command } from 'commander';
2
+ export type RenameParams = {
3
+ target: string;
4
+ recursive: boolean;
5
+ extentions?: string[];
6
+ before?: string;
7
+ after?: string;
8
+ undo?: boolean;
9
+ placeholders?: string[];
10
+ values?: string[];
11
+ };
2
12
  export declare function rename(program: Command): void;
3
13
  //# sourceMappingURL=rename.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../../src/commands/rename/rename.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,QAyDtC"}
1
+ {"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../../src/commands/rename/rename.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,QAgHtC"}
@@ -2,14 +2,15 @@ import { rename as fsRename, readdir } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
4
  export function rename(program) {
5
- program.command('rename').description('Rename multiple files based on file extention').option('-e,--extention <extentions...>', 'Include the files with the extention only').option('-t,--target <string>', 'Target working directory', cwd()).option('-p,--prefix <string>', 'Prefix to add the file name').option('-s,--suffix <string>', 'Suffix to add the file name').option('-u,--undo', 'Undo the operation').option('-r,--recursive', 'Include sub directories').action(async ({ target, extention, prefix, suffix, recursive, undo })=>{
5
+ program.command('rename').description('Rename multiple files based on file extentions').option('-e,--extentions <extentionss...>', 'Include the files with the extentions only').option('-t,--target <string>', 'Target working directory', cwd()).option('-p,--placeholders <placeholders...>', 'List of placeholders to replace by value').option('-v,--values <values...>', 'List of values to be replaced by placeholder').option('-b,--before <string>', 'Prefix to add the file name').option('-a,--after <string>', 'Suffix to add the file name').option('-u,--undo', 'Undo the operation').option('-r,--recursive', 'Include sub directories', false).action(async (options)=>{
6
+ const { target, extentions, before, after, recursive, undo, placeholders, values } = options;
6
7
  const dridents = await readdir(target, {
7
8
  recursive,
8
9
  withFileTypes: true
9
10
  });
10
11
  const files = dridents.filter((e)=>e.isFile()).filter((e)=>{
11
- if (extention) {
12
- return extention.some((ex)=>e.name.endsWith(ex));
12
+ if (extentions) {
13
+ return extentions.some((ex)=>e.name.endsWith(ex));
13
14
  }
14
15
  return true;
15
16
  });
@@ -18,18 +19,36 @@ export function rename(program) {
18
19
  const oldFileName = f.name;
19
20
  let newFileName = oldFileName;
20
21
  if (undo) {
21
- if (prefix) {
22
- newFileName = newFileName.replace(new RegExp(`^${prefix}`), '');
22
+ if (before) {
23
+ newFileName = newFileName.replace(new RegExp(`^${before}`), '');
23
24
  }
24
- if (suffix) {
25
- newFileName = newFileName.replace(new RegExp(`${suffix}$`), '');
25
+ if (after) {
26
+ newFileName = newFileName.replace(new RegExp(`${after}$`), '');
27
+ }
28
+ if (placeholders && values) {
29
+ if (placeholders.length > 0 && placeholders.length === values.length) {
30
+ for(let i = 0; i < placeholders.length; i++){
31
+ newFileName = newFileName.replace(new RegExp(`${values[i]}`, 'g'), placeholders[i]);
32
+ }
33
+ } else {
34
+ throw new Error('Placeholders length does not match the values legnth');
35
+ }
26
36
  }
27
37
  } else {
28
- if (prefix) {
29
- newFileName = prefix + newFileName;
38
+ if (before) {
39
+ newFileName = before + newFileName;
40
+ }
41
+ if (after) {
42
+ newFileName = newFileName + after;
30
43
  }
31
- if (suffix) {
32
- newFileName = newFileName + suffix;
44
+ if (placeholders && values) {
45
+ if (placeholders.length > 0 && placeholders.length === values.length) {
46
+ for(let i = 0; i < placeholders.length; i++){
47
+ newFileName = newFileName.replace(new RegExp(`${placeholders[i]}`, 'g'), values[i]);
48
+ }
49
+ } else {
50
+ throw new Error('Placeholders length does not match the values legnth');
51
+ }
33
52
  }
34
53
  }
35
54
  if (newFileName !== oldFileName) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/rename/rename.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport { rename as fsRename, readdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { cwd } from 'node:process';\n\nexport function rename(program: Command) {\n program\n .command('rename')\n .description('Rename multiple files based on file extention')\n .option(\n '-e,--extention <extentions...>',\n 'Include the files with the extention only',\n )\n .option('-t,--target <string>', 'Target working directory', cwd())\n .option('-p,--prefix <string>', 'Prefix to add the file name')\n .option('-s,--suffix <string>', 'Suffix to add the file name')\n .option('-u,--undo', 'Undo the operation')\n .option('-r,--recursive', 'Include sub directories')\n .action(async ({ target, extention, prefix, suffix, recursive, undo }) => {\n const dridents = await readdir(target, {\n recursive,\n withFileTypes: true,\n });\n\n const files = dridents\n .filter((e) => e.isFile())\n .filter((e) => {\n if (extention) {\n return extention.some((ex: string) => e.name.endsWith(ex));\n }\n return true;\n });\n\n for (const f of files) {\n const oldPath = join(f.parentPath, f.name);\n const oldFileName = f.name;\n\n let newFileName = oldFileName;\n\n if (undo) {\n if (prefix) {\n newFileName = newFileName.replace(new RegExp(`^${prefix}`), '');\n }\n\n if (suffix) {\n newFileName = newFileName.replace(new RegExp(`${suffix}$`), '');\n }\n } else {\n if (prefix) {\n newFileName = prefix + newFileName;\n }\n\n if (suffix) {\n newFileName = newFileName + suffix;\n }\n }\n\n if (newFileName !== oldFileName) {\n await fsRename(oldPath, join(f.parentPath, newFileName));\n }\n }\n });\n}\n"],"names":["rename","fsRename","readdir","join","cwd","program","command","description","option","action","target","extention","prefix","suffix","recursive","undo","dridents","withFileTypes","files","filter","e","isFile","some","ex","name","endsWith","f","oldPath","parentPath","oldFileName","newFileName","replace","RegExp"],"mappings":"AACA,SAASA,UAAUC,QAAQ,EAAEC,OAAO,QAAQ,mBAAmB;AAC/D,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,GAAG,QAAQ,eAAe;AAEnC,OAAO,SAASJ,OAAOK,OAAgB;IACrCA,QACGC,OAAO,CAAC,UACRC,WAAW,CAAC,iDACZC,MAAM,CACL,kCACA,6CAEDA,MAAM,CAAC,wBAAwB,4BAA4BJ,OAC3DI,MAAM,CAAC,wBAAwB,+BAC/BA,MAAM,CAAC,wBAAwB,+BAC/BA,MAAM,CAAC,aAAa,sBACpBA,MAAM,CAAC,kBAAkB,2BACzBC,MAAM,CAAC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAE;QACnE,MAAMC,WAAW,MAAMd,QAAQQ,QAAQ;YACrCI;YACAG,eAAe;QACjB;QAEA,MAAMC,QAAQF,SACXG,MAAM,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtBF,MAAM,CAAC,CAACC;YACP,IAAIT,WAAW;gBACb,OAAOA,UAAUW,IAAI,CAAC,CAACC,KAAeH,EAAEI,IAAI,CAACC,QAAQ,CAACF;YACxD;YACA,OAAO;QACT;QAEF,KAAK,MAAMG,KAAKR,MAAO;YACrB,MAAMS,UAAUxB,KAAKuB,EAAEE,UAAU,EAAEF,EAAEF,IAAI;YACzC,MAAMK,cAAcH,EAAEF,IAAI;YAE1B,IAAIM,cAAcD;YAElB,IAAId,MAAM;gBACR,IAAIH,QAAQ;oBACVkB,cAAcA,YAAYC,OAAO,CAAC,IAAIC,OAAO,CAAC,CAAC,EAAEpB,QAAQ,GAAG;gBAC9D;gBAEA,IAAIC,QAAQ;oBACViB,cAAcA,YAAYC,OAAO,CAAC,IAAIC,OAAO,GAAGnB,OAAO,CAAC,CAAC,GAAG;gBAC9D;YACF,OAAO;gBACL,IAAID,QAAQ;oBACVkB,cAAclB,SAASkB;gBACzB;gBAEA,IAAIjB,QAAQ;oBACViB,cAAcA,cAAcjB;gBAC9B;YACF;YAEA,IAAIiB,gBAAgBD,aAAa;gBAC/B,MAAM5B,SAAS0B,SAASxB,KAAKuB,EAAEE,UAAU,EAAEE;YAC7C;QACF;IACF;AACJ"}
1
+ {"version":3,"sources":["../../../src/commands/rename/rename.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport { rename as fsRename, readdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { cwd } from 'node:process';\n\nexport type RenameParams = {\n target: string;\n recursive: boolean;\n extentions?: string[];\n before?: string;\n after?: string;\n undo?: boolean;\n placeholders?: string[];\n values?: string[];\n};\n\nexport function rename(program: Command) {\n program\n .command('rename')\n .description('Rename multiple files based on file extentions')\n .option(\n '-e,--extentions <extentionss...>',\n 'Include the files with the extentions only',\n )\n .option('-t,--target <string>', 'Target working directory', cwd())\n .option(\n '-p,--placeholders <placeholders...>',\n 'List of placeholders to replace by value',\n )\n .option(\n '-v,--values <values...>',\n 'List of values to be replaced by placeholder',\n )\n .option('-b,--before <string>', 'Prefix to add the file name')\n .option('-a,--after <string>', 'Suffix to add the file name')\n .option('-u,--undo', 'Undo the operation')\n .option('-r,--recursive', 'Include sub directories', false)\n .action(async (options: RenameParams) => {\n const {\n target,\n extentions,\n before,\n after,\n recursive,\n undo,\n placeholders,\n values,\n } = options;\n\n const dridents = await readdir(target, {\n recursive,\n withFileTypes: true,\n });\n\n const files = dridents\n .filter((e) => e.isFile())\n .filter((e) => {\n if (extentions) {\n return extentions.some((ex: string) => e.name.endsWith(ex));\n }\n return true;\n });\n\n for (const f of files) {\n const oldPath = join(f.parentPath, f.name);\n const oldFileName = f.name;\n\n let newFileName = oldFileName;\n\n if (undo) {\n if (before) {\n newFileName = newFileName.replace(new RegExp(`^${before}`), '');\n }\n\n if (after) {\n newFileName = newFileName.replace(new RegExp(`${after}$`), '');\n }\n\n if (placeholders && values) {\n if (\n placeholders.length > 0 &&\n placeholders.length === values.length\n ) {\n for (let i = 0; i < placeholders.length; i++) {\n newFileName = newFileName.replace(\n new RegExp(`${values[i]}`, 'g'),\n placeholders[i],\n );\n }\n } else {\n throw new Error(\n 'Placeholders length does not match the values legnth',\n );\n }\n }\n } else {\n if (before) {\n newFileName = before + newFileName;\n }\n\n if (after) {\n newFileName = newFileName + after;\n }\n\n if (placeholders && values) {\n if (\n placeholders.length > 0 &&\n placeholders.length === values.length\n ) {\n for (let i = 0; i < placeholders.length; i++) {\n newFileName = newFileName.replace(\n new RegExp(`${placeholders[i]}`, 'g'),\n values[i],\n );\n }\n } else {\n throw new Error(\n 'Placeholders length does not match the values legnth',\n );\n }\n }\n }\n\n if (newFileName !== oldFileName) {\n await fsRename(oldPath, join(f.parentPath, newFileName));\n }\n }\n });\n}\n"],"names":["rename","fsRename","readdir","join","cwd","program","command","description","option","action","options","target","extentions","before","after","recursive","undo","placeholders","values","dridents","withFileTypes","files","filter","e","isFile","some","ex","name","endsWith","f","oldPath","parentPath","oldFileName","newFileName","replace","RegExp","length","i","Error"],"mappings":"AACA,SAASA,UAAUC,QAAQ,EAAEC,OAAO,QAAQ,mBAAmB;AAC/D,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,GAAG,QAAQ,eAAe;AAanC,OAAO,SAASJ,OAAOK,OAAgB;IACrCA,QACGC,OAAO,CAAC,UACRC,WAAW,CAAC,kDACZC,MAAM,CACL,oCACA,8CAEDA,MAAM,CAAC,wBAAwB,4BAA4BJ,OAC3DI,MAAM,CACL,uCACA,4CAEDA,MAAM,CACL,2BACA,gDAEDA,MAAM,CAAC,wBAAwB,+BAC/BA,MAAM,CAAC,uBAAuB,+BAC9BA,MAAM,CAAC,aAAa,sBACpBA,MAAM,CAAC,kBAAkB,2BAA2B,OACpDC,MAAM,CAAC,OAAOC;QACb,MAAM,EACJC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,KAAK,EACLC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,MAAM,EACP,GAAGR;QAEJ,MAAMS,WAAW,MAAMjB,QAAQS,QAAQ;YACrCI;YACAK,eAAe;QACjB;QAEA,MAAMC,QAAQF,SACXG,MAAM,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtBF,MAAM,CAAC,CAACC;YACP,IAAIX,YAAY;gBACd,OAAOA,WAAWa,IAAI,CAAC,CAACC,KAAeH,EAAEI,IAAI,CAACC,QAAQ,CAACF;YACzD;YACA,OAAO;QACT;QAEF,KAAK,MAAMG,KAAKR,MAAO;YACrB,MAAMS,UAAU3B,KAAK0B,EAAEE,UAAU,EAAEF,EAAEF,IAAI;YACzC,MAAMK,cAAcH,EAAEF,IAAI;YAE1B,IAAIM,cAAcD;YAElB,IAAIhB,MAAM;gBACR,IAAIH,QAAQ;oBACVoB,cAAcA,YAAYC,OAAO,CAAC,IAAIC,OAAO,CAAC,CAAC,EAAEtB,QAAQ,GAAG;gBAC9D;gBAEA,IAAIC,OAAO;oBACTmB,cAAcA,YAAYC,OAAO,CAAC,IAAIC,OAAO,GAAGrB,MAAM,CAAC,CAAC,GAAG;gBAC7D;gBAEA,IAAIG,gBAAgBC,QAAQ;oBAC1B,IACED,aAAamB,MAAM,GAAG,KACtBnB,aAAamB,MAAM,KAAKlB,OAAOkB,MAAM,EACrC;wBACA,IAAK,IAAIC,IAAI,GAAGA,IAAIpB,aAAamB,MAAM,EAAEC,IAAK;4BAC5CJ,cAAcA,YAAYC,OAAO,CAC/B,IAAIC,OAAO,GAAGjB,MAAM,CAACmB,EAAE,EAAE,EAAE,MAC3BpB,YAAY,CAACoB,EAAE;wBAEnB;oBACF,OAAO;wBACL,MAAM,IAAIC,MACR;oBAEJ;gBACF;YACF,OAAO;gBACL,IAAIzB,QAAQ;oBACVoB,cAAcpB,SAASoB;gBACzB;gBAEA,IAAInB,OAAO;oBACTmB,cAAcA,cAAcnB;gBAC9B;gBAEA,IAAIG,gBAAgBC,QAAQ;oBAC1B,IACED,aAAamB,MAAM,GAAG,KACtBnB,aAAamB,MAAM,KAAKlB,OAAOkB,MAAM,EACrC;wBACA,IAAK,IAAIC,IAAI,GAAGA,IAAIpB,aAAamB,MAAM,EAAEC,IAAK;4BAC5CJ,cAAcA,YAAYC,OAAO,CAC/B,IAAIC,OAAO,GAAGlB,YAAY,CAACoB,EAAE,EAAE,EAAE,MACjCnB,MAAM,CAACmB,EAAE;wBAEb;oBACF,OAAO;wBACL,MAAM,IAAIC,MACR;oBAEJ;gBACF;YACF;YAEA,IAAIL,gBAAgBD,aAAa;gBAC/B,MAAM/B,SAAS6B,SAAS3B,KAAK0B,EAAEE,UAAU,EAAEE;YAC7C;QACF;IACF;AACJ"}
@@ -2,7 +2,7 @@ import { readdir, readFile, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
4
  export function replace(program) {
5
- program.command('replace').description('Replace multiple files content based file extentions').option('-e,--extention <extentions...>', 'Include the files with the extention only').option('-t,--target <string>', 'Target working directory', cwd()).option('-p,--placeholders <placeholders...>', 'placeholders').option('-v,--values <values...>', 'New values').option('-r,--recursive', 'Include sub directories').action(async ({ extention, target, placeholders, values, recursive })=>{
5
+ program.command('replace').description('Replace multiple files content based file extentions').option('-e,--extention <extentions...>', 'Include the files with the extention only').requiredOption('-p,--placeholders <placeholders...>', 'placeholders').requiredOption('-t,--target <string>', 'Target working directory', cwd()).requiredOption('-v,--values <values...>', 'New values').option('-r,--recursive', 'Include sub directories').action(async ({ extention, target, placeholders, values, recursive })=>{
6
6
  const dridents = await readdir(target, {
7
7
  recursive,
8
8
  withFileTypes: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/replace/replace.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport { readdir, readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { cwd } from 'node:process';\n\nexport function replace(program: Command) {\n program\n .command('replace')\n .description('Replace multiple files content based file extentions')\n .option(\n '-e,--extention <extentions...>',\n 'Include the files with the extention only',\n )\n .option('-t,--target <string>', 'Target working directory', cwd())\n .option('-p,--placeholders <placeholders...>', 'placeholders')\n .option('-v,--values <values...>', 'New values')\n .option('-r,--recursive', 'Include sub directories')\n .action(async ({ extention, target, placeholders, values, recursive }) => {\n const dridents = await readdir(target, {\n recursive,\n withFileTypes: true,\n });\n\n const files = dridents\n .filter((e) => e.isFile())\n .filter((e) => {\n if (extention) {\n return e.name.endsWith(extention);\n }\n return true;\n });\n\n for (const f of files) {\n const filePath = join(f.parentPath, f.name);\n let fileContent = await readFile(filePath, { encoding: 'utf-8' });\n\n for (const [index, placeholder] of placeholders.entries()) {\n if (!values[index]) {\n throw new Error(\n `Value is not provided for ${placeholder} at index ${index}`,\n );\n }\n fileContent = fileContent.replace(\n new RegExp(placeholder, 'g'),\n values[index],\n );\n }\n\n await writeFile(filePath, fileContent);\n }\n });\n}\n"],"names":["readdir","readFile","writeFile","join","cwd","replace","program","command","description","option","action","extention","target","placeholders","values","recursive","dridents","withFileTypes","files","filter","e","isFile","name","endsWith","f","filePath","parentPath","fileContent","encoding","index","placeholder","entries","Error","RegExp"],"mappings":"AACA,SAASA,OAAO,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,mBAAmB;AAChE,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,GAAG,QAAQ,eAAe;AAEnC,OAAO,SAASC,QAAQC,OAAgB;IACtCA,QACGC,OAAO,CAAC,WACRC,WAAW,CAAC,wDACZC,MAAM,CACL,kCACA,6CAEDA,MAAM,CAAC,wBAAwB,4BAA4BL,OAC3DK,MAAM,CAAC,uCAAuC,gBAC9CA,MAAM,CAAC,2BAA2B,cAClCA,MAAM,CAAC,kBAAkB,2BACzBC,MAAM,CAAC,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAEC,YAAY,EAAEC,MAAM,EAAEC,SAAS,EAAE;QACnE,MAAMC,WAAW,MAAMhB,QAAQY,QAAQ;YACrCG;YACAE,eAAe;QACjB;QAEA,MAAMC,QAAQF,SACXG,MAAM,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtBF,MAAM,CAAC,CAACC;YACP,IAAIT,WAAW;gBACb,OAAOS,EAAEE,IAAI,CAACC,QAAQ,CAACZ;YACzB;YACA,OAAO;QACT;QAEF,KAAK,MAAMa,KAAKN,MAAO;YACrB,MAAMO,WAAWtB,KAAKqB,EAAEE,UAAU,EAAEF,EAAEF,IAAI;YAC1C,IAAIK,cAAc,MAAM1B,SAASwB,UAAU;gBAAEG,UAAU;YAAQ;YAE/D,KAAK,MAAM,CAACC,OAAOC,YAAY,IAAIjB,aAAakB,OAAO,GAAI;gBACzD,IAAI,CAACjB,MAAM,CAACe,MAAM,EAAE;oBAClB,MAAM,IAAIG,MACR,CAAC,0BAA0B,EAAEF,YAAY,UAAU,EAAED,OAAO;gBAEhE;gBACAF,cAAcA,YAAYtB,OAAO,CAC/B,IAAI4B,OAAOH,aAAa,MACxBhB,MAAM,CAACe,MAAM;YAEjB;YAEA,MAAM3B,UAAUuB,UAAUE;QAC5B;IACF;AACJ"}
1
+ {"version":3,"sources":["../../../src/commands/replace/replace.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport { readdir, readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { cwd } from 'node:process';\n\nexport function replace(program: Command) {\n program\n .command('replace')\n .description('Replace multiple files content based file extentions')\n .option(\n '-e,--extention <extentions...>',\n 'Include the files with the extention only',\n )\n .requiredOption('-p,--placeholders <placeholders...>', 'placeholders')\n .requiredOption('-t,--target <string>', 'Target working directory', cwd())\n .requiredOption('-v,--values <values...>', 'New values')\n .option('-r,--recursive', 'Include sub directories')\n .action(async ({ extention, target, placeholders, values, recursive }) => {\n const dridents = await readdir(target, {\n recursive,\n withFileTypes: true,\n });\n\n const files = dridents\n .filter((e) => e.isFile())\n .filter((e) => {\n if (extention) {\n return e.name.endsWith(extention);\n }\n return true;\n });\n\n for (const f of files) {\n const filePath = join(f.parentPath, f.name);\n let fileContent = await readFile(filePath, { encoding: 'utf-8' });\n\n for (const [index, placeholder] of placeholders.entries()) {\n if (!values[index]) {\n throw new Error(\n `Value is not provided for ${placeholder} at index ${index}`,\n );\n }\n fileContent = fileContent.replace(\n new RegExp(placeholder, 'g'),\n values[index],\n );\n }\n\n await writeFile(filePath, fileContent);\n }\n });\n}\n"],"names":["readdir","readFile","writeFile","join","cwd","replace","program","command","description","option","requiredOption","action","extention","target","placeholders","values","recursive","dridents","withFileTypes","files","filter","e","isFile","name","endsWith","f","filePath","parentPath","fileContent","encoding","index","placeholder","entries","Error","RegExp"],"mappings":"AACA,SAASA,OAAO,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,mBAAmB;AAChE,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,GAAG,QAAQ,eAAe;AAEnC,OAAO,SAASC,QAAQC,OAAgB;IACtCA,QACGC,OAAO,CAAC,WACRC,WAAW,CAAC,wDACZC,MAAM,CACL,kCACA,6CAEDC,cAAc,CAAC,uCAAuC,gBACtDA,cAAc,CAAC,wBAAwB,4BAA4BN,OACnEM,cAAc,CAAC,2BAA2B,cAC1CD,MAAM,CAAC,kBAAkB,2BACzBE,MAAM,CAAC,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAEC,YAAY,EAAEC,MAAM,EAAEC,SAAS,EAAE;QACnE,MAAMC,WAAW,MAAMjB,QAAQa,QAAQ;YACrCG;YACAE,eAAe;QACjB;QAEA,MAAMC,QAAQF,SACXG,MAAM,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtBF,MAAM,CAAC,CAACC;YACP,IAAIT,WAAW;gBACb,OAAOS,EAAEE,IAAI,CAACC,QAAQ,CAACZ;YACzB;YACA,OAAO;QACT;QAEF,KAAK,MAAMa,KAAKN,MAAO;YACrB,MAAMO,WAAWvB,KAAKsB,EAAEE,UAAU,EAAEF,EAAEF,IAAI;YAC1C,IAAIK,cAAc,MAAM3B,SAASyB,UAAU;gBAAEG,UAAU;YAAQ;YAE/D,KAAK,MAAM,CAACC,OAAOC,YAAY,IAAIjB,aAAakB,OAAO,GAAI;gBACzD,IAAI,CAACjB,MAAM,CAACe,MAAM,EAAE;oBAClB,MAAM,IAAIG,MACR,CAAC,0BAA0B,EAAEF,YAAY,UAAU,EAAED,OAAO;gBAEhE;gBACAF,cAAcA,YAAYvB,OAAO,CAC/B,IAAI6B,OAAOH,aAAa,MACxBhB,MAAM,CAACe,MAAM;YAEjB;YAEA,MAAM5B,UAAUwB,UAAUE;QAC5B;IACF;AACJ"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from 'commander';
2
+ export declare function template(program: Command): void;
3
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/commands/template/template.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,QAuDxC"}
@@ -0,0 +1,39 @@
1
+ import { names } from '@aenode/names';
2
+ import { readdir, readFile, rename, writeFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { cwd } from 'node:process';
5
+ export function template(program) {
6
+ program.command('template').description('Templatify the project files (ts,js, md, and json)').requiredOption('-n,--name <string...>', 'Resource name').action(async ({ name })=>{
7
+ const dridents = await readdir(cwd(), {
8
+ recursive: true,
9
+ withFileTypes: true
10
+ });
11
+ const files = dridents.filter((e)=>e.isFile()).filter((e)=>{
12
+ return /\.(ts|js|md|json)$/.test(e.name);
13
+ });
14
+ for (const f of files){
15
+ const oldPath = join(f.parentPath, f.name);
16
+ const oldFileName = f.name;
17
+ const oldFileContent = await readFile(oldPath, {
18
+ encoding: 'utf-8'
19
+ });
20
+ let newFileName = oldFileName;
21
+ let newFileContent = oldFileContent;
22
+ const resourceNames = name.map((e)=>names(e));
23
+ for (const resourceName of resourceNames){
24
+ newFileName = newFileName.replaceAll(new RegExp(`${resourceName.fileName}`, 'g'), '__fileName__');
25
+ newFileContent = newFileContent.replace(new RegExp(`/${resourceName.fileName}`, 'g'), '/<%- fileName %>');
26
+ newFileContent = newFileContent.replace(new RegExp(`${resourceName.propertyName}`, 'g'), '<%- propertyName %>');
27
+ newFileContent = newFileContent.replace(new RegExp(`${resourceName.className}`, 'g'), '<%- className %>');
28
+ }
29
+ newFileName = newFileName + '.template';
30
+ const newFilePath = join(f.parentPath, newFileName);
31
+ await rename(oldPath, newFilePath);
32
+ await writeFile(newFilePath, newFileContent, {
33
+ encoding: 'utf-8'
34
+ });
35
+ }
36
+ });
37
+ }
38
+
39
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/template/template.ts"],"sourcesContent":["import { names } from '@aenode/names';\nimport type { Command } from 'commander';\nimport { readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { cwd } from 'node:process';\n\nexport function template(program: Command) {\n program\n .command('template')\n .description('Templatify the project files (ts,js, md, and json)')\n .requiredOption('-n,--name <string...>', 'Resource name')\n .action(async ({ name }) => {\n const dridents = await readdir(cwd(), {\n recursive: true,\n withFileTypes: true,\n });\n\n const files = dridents\n .filter((e) => e.isFile())\n .filter((e) => {\n return /\\.(ts|js|md|json)$/.test(e.name);\n });\n\n for (const f of files) {\n const oldPath = join(f.parentPath, f.name);\n const oldFileName = f.name;\n const oldFileContent = await readFile(oldPath, { encoding: 'utf-8' });\n\n let newFileName = oldFileName;\n let newFileContent = oldFileContent;\n const resourceNames = (name as string[]).map((e: string) => names(e));\n\n for (const resourceName of resourceNames) {\n newFileName = newFileName.replaceAll(\n new RegExp(`${resourceName.fileName}`, 'g'),\n '__fileName__',\n );\n\n newFileContent = newFileContent.replace(\n new RegExp(`/${resourceName.fileName}`, 'g'),\n '/<%- fileName %>',\n );\n\n newFileContent = newFileContent.replace(\n new RegExp(`${resourceName.propertyName}`, 'g'),\n '<%- propertyName %>',\n );\n newFileContent = newFileContent.replace(\n new RegExp(`${resourceName.className}`, 'g'),\n '<%- className %>',\n );\n }\n\n newFileName = newFileName + '.template';\n const newFilePath = join(f.parentPath, newFileName);\n\n await rename(oldPath, newFilePath);\n\n await writeFile(newFilePath, newFileContent, { encoding: 'utf-8' });\n }\n });\n}\n"],"names":["names","readdir","readFile","rename","writeFile","join","cwd","template","program","command","description","requiredOption","action","name","dridents","recursive","withFileTypes","files","filter","e","isFile","test","f","oldPath","parentPath","oldFileName","oldFileContent","encoding","newFileName","newFileContent","resourceNames","map","resourceName","replaceAll","RegExp","fileName","replace","propertyName","className","newFilePath"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAgB;AAEtC,SAASC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,mBAAmB;AACxE,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,GAAG,QAAQ,eAAe;AAEnC,OAAO,SAASC,SAASC,OAAgB;IACvCA,QACGC,OAAO,CAAC,YACRC,WAAW,CAAC,sDACZC,cAAc,CAAC,yBAAyB,iBACxCC,MAAM,CAAC,OAAO,EAAEC,IAAI,EAAE;QACrB,MAAMC,WAAW,MAAMb,QAAQK,OAAO;YACpCS,WAAW;YACXC,eAAe;QACjB;QAEA,MAAMC,QAAQH,SACXI,MAAM,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtBF,MAAM,CAAC,CAACC;YACP,OAAO,qBAAqBE,IAAI,CAACF,EAAEN,IAAI;QACzC;QAEF,KAAK,MAAMS,KAAKL,MAAO;YACrB,MAAMM,UAAUlB,KAAKiB,EAAEE,UAAU,EAAEF,EAAET,IAAI;YACzC,MAAMY,cAAcH,EAAET,IAAI;YAC1B,MAAMa,iBAAiB,MAAMxB,SAASqB,SAAS;gBAAEI,UAAU;YAAQ;YAEnE,IAAIC,cAAcH;YAClB,IAAII,iBAAiBH;YACrB,MAAMI,gBAAgB,AAACjB,KAAkBkB,GAAG,CAAC,CAACZ,IAAcnB,MAAMmB;YAElE,KAAK,MAAMa,gBAAgBF,cAAe;gBACxCF,cAAcA,YAAYK,UAAU,CAClC,IAAIC,OAAO,GAAGF,aAAaG,QAAQ,EAAE,EAAE,MACvC;gBAGFN,iBAAiBA,eAAeO,OAAO,CACrC,IAAIF,OAAO,CAAC,CAAC,EAAEF,aAAaG,QAAQ,EAAE,EAAE,MACxC;gBAGFN,iBAAiBA,eAAeO,OAAO,CACrC,IAAIF,OAAO,GAAGF,aAAaK,YAAY,EAAE,EAAE,MAC3C;gBAEFR,iBAAiBA,eAAeO,OAAO,CACrC,IAAIF,OAAO,GAAGF,aAAaM,SAAS,EAAE,EAAE,MACxC;YAEJ;YAEAV,cAAcA,cAAc;YAC5B,MAAMW,cAAclC,KAAKiB,EAAEE,UAAU,EAAEI;YAEvC,MAAMzB,OAAOoB,SAASgB;YAEtB,MAAMnC,UAAUmC,aAAaV,gBAAgB;gBAAEF,UAAU;YAAQ;QACnE;IACF;AACJ"}
package/dist/main.js CHANGED
@@ -4,6 +4,7 @@ import { history } from './commands/history/history.js';
4
4
  import { merge } from './commands/merge/merge.js';
5
5
  import { rename } from './commands/rename/rename.js';
6
6
  import { replace } from './commands/replace/replace.js';
7
+ import { template } from './commands/template/template.js';
7
8
  import { uuid } from './commands/uuid/uuid.js';
8
9
  import { writeLog } from './log/log.js';
9
10
  [
@@ -12,7 +13,8 @@ import { writeLog } from './log/log.js';
12
13
  history,
13
14
  uuid,
14
15
  rename,
15
- replace
16
+ replace,
17
+ template
16
18
  ].forEach((e)=>e(program));
17
19
  const aenode = program.name('aenode').description('aenode cli');
18
20
  aenode.hook('postAction', (command, action)=>{
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main.ts"],"sourcesContent":["import { program } from 'commander';\nimport { bye } from './commands/bye/bye.js';\nimport { history } from './commands/history/history.js';\nimport { merge } from './commands/merge/merge.js';\nimport { rename } from './commands/rename/rename.js';\nimport { replace } from './commands/replace/replace.js';\nimport { uuid } from './commands/uuid/uuid.js';\nimport { writeLog } from './log/log.js';\n\n[bye, merge, history, uuid, rename, replace].forEach((e) => e(program));\n\nconst aenode = program.name('aenode').description('aenode cli');\n\naenode.hook('postAction', (command, action) => {\n const options = Object.entries(action.opts())\n .map(([k, v]) => `--${k} \"${v}\"`)\n .join(' ');\n writeLog(`${command.name()} ${action.name()} ${options}`);\n});\n\naenode.parse();\n"],"names":["program","bye","history","merge","rename","replace","uuid","writeLog","forEach","e","aenode","name","description","hook","command","action","options","Object","entries","opts","map","k","v","join","parse"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,SAASC,GAAG,QAAQ,wBAAwB;AAC5C,SAASC,OAAO,QAAQ,gCAAgC;AACxD,SAASC,KAAK,QAAQ,4BAA4B;AAClD,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,OAAO,QAAQ,gCAAgC;AACxD,SAASC,IAAI,QAAQ,0BAA0B;AAC/C,SAASC,QAAQ,QAAQ,eAAe;AAExC;IAACN;IAAKE;IAAOD;IAASI;IAAMF;IAAQC;CAAQ,CAACG,OAAO,CAAC,CAACC,IAAMA,EAAET;AAE9D,MAAMU,SAASV,QAAQW,IAAI,CAAC,UAAUC,WAAW,CAAC;AAElDF,OAAOG,IAAI,CAAC,cAAc,CAACC,SAASC;IAClC,MAAMC,UAAUC,OAAOC,OAAO,CAACH,OAAOI,IAAI,IACvCC,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK,CAAC,EAAE,EAAED,EAAE,EAAE,EAAEC,EAAE,CAAC,CAAC,EAC/BC,IAAI,CAAC;IACRhB,SAAS,GAAGO,QAAQH,IAAI,GAAG,CAAC,EAAEI,OAAOJ,IAAI,GAAG,CAAC,EAAEK,SAAS;AAC1D;AAEAN,OAAOc,KAAK"}
1
+ {"version":3,"sources":["../src/main.ts"],"sourcesContent":["import { program } from 'commander';\nimport { bye } from './commands/bye/bye.js';\nimport { history } from './commands/history/history.js';\nimport { merge } from './commands/merge/merge.js';\nimport { rename } from './commands/rename/rename.js';\nimport { replace } from './commands/replace/replace.js';\nimport { template } from './commands/template/template.js';\nimport { uuid } from './commands/uuid/uuid.js';\nimport { writeLog } from './log/log.js';\n\n[bye, merge, history, uuid, rename, replace, template].forEach((e) =>\n e(program),\n);\n\nconst aenode = program.name('aenode').description('aenode cli');\n\naenode.hook('postAction', (command, action) => {\n const options = Object.entries(action.opts())\n .map(([k, v]) => `--${k} \"${v}\"`)\n .join(' ');\n writeLog(`${command.name()} ${action.name()} ${options}`);\n});\n\naenode.parse();\n"],"names":["program","bye","history","merge","rename","replace","template","uuid","writeLog","forEach","e","aenode","name","description","hook","command","action","options","Object","entries","opts","map","k","v","join","parse"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,SAASC,GAAG,QAAQ,wBAAwB;AAC5C,SAASC,OAAO,QAAQ,gCAAgC;AACxD,SAASC,KAAK,QAAQ,4BAA4B;AAClD,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,OAAO,QAAQ,gCAAgC;AACxD,SAASC,QAAQ,QAAQ,kCAAkC;AAC3D,SAASC,IAAI,QAAQ,0BAA0B;AAC/C,SAASC,QAAQ,QAAQ,eAAe;AAExC;IAACP;IAAKE;IAAOD;IAASK;IAAMH;IAAQC;IAASC;CAAS,CAACG,OAAO,CAAC,CAACC,IAC9DA,EAAEV;AAGJ,MAAMW,SAASX,QAAQY,IAAI,CAAC,UAAUC,WAAW,CAAC;AAElDF,OAAOG,IAAI,CAAC,cAAc,CAACC,SAASC;IAClC,MAAMC,UAAUC,OAAOC,OAAO,CAACH,OAAOI,IAAI,IACvCC,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK,CAAC,EAAE,EAAED,EAAE,EAAE,EAAEC,EAAE,CAAC,CAAC,EAC/BC,IAAI,CAAC;IACRhB,SAAS,GAAGO,QAAQH,IAAI,GAAG,CAAC,EAAEI,OAAOJ,IAAI,GAAG,CAAC,EAAEK,SAAS;AAC1D;AAEAN,OAAOc,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aenode/cli",
3
- "version": "0.0.37",
3
+ "version": "0.0.40",
4
4
  "description": "Aenode CLI",
5
5
  "author": {
6
6
  "name": "Ahmet Emrebas",
@@ -58,6 +58,7 @@
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
+ "@aenode/names": "workspace:*",
61
62
  "@swc/helpers": "~0.5.18",
62
63
  "commander": "^15.0.0",
63
64
  "uuid": "^14.0.3"