1+ #!/usr/bin/env node
2+ 'use strict' ;
3+
14/**
2- * The All Algorithms C++ Formatter
5+ * Usage: node generate-readme.js
36 *
47 * Author: Carlos Abraham Hernandez
58 * https://abranhe.com (abraham@abranhe.com)
69 */
7- 'use strict' ;
810
911const fs = require ( 'fs' ) ;
1012const path = require ( 'path' ) ;
1113const glob = require ( 'glob' ) ;
1214const chalk = require ( 'chalk' ) ;
13- const decamelize = require ( 'decamelize' ) ;
14- const shell = require ( 'child_process' ) . execSync ;
1515
1616const getFiles = ( src , callback ) => {
1717 glob ( src + '/**' , callback ) ;
1818} ;
1919
20- getFiles ( '../' , ( err , res ) => {
21- if ( err ) {
22- console . log ( 'Error' , err ) ;
23- } else {
24- res . map ( ( file ) => {
25- // Accept only valid C++ Files (.cpp,.hpp,.h)
26- if ( path . extname ( file ) !== '.cpp' && path . extname ( file ) !== '.hpp' && path . extname ( file ) !== '.h' ) {
27- return ;
28- }
29-
30- // Only avilable for Linux/Macos
31- // https://stackoverflow.com/a/41030518/7602110
32- // Can be replaced in the future
33- shell ( `mv ${ file . replace ( ' ' , '\\ ' ) } ${ decamelize ( file . replace ( ' ' , '_' ) ) } ` ) ;
34-
35- if ( file . replace ( ' ' , '\\ ' ) !== decamelize ( file ) ) {
36- console . log (
37- `The file ${ chalk . red ( file ) } was successfuly changed to ${ chalk . green ( decamelize ( file . replace ( ' ' , '_' ) ) ) } `
38- ) ;
39-
40- // Change file on git history
41- // https://stackoverflow.com/a/16071375/7602110
42- shell ( `cd ../\
43- git mv --force ${ file . replace ( ' ' , '\\ ' ) . replace ( '../' , '' ) } ${ decamelize (
44- file . replace ( ' ' , '_' ) . replace ( '../' , '' )
45- ) } `) ;
46- }
47-
48- // Replace for convention .h for .hpp
49- if ( path . extname ( file ) === '.h' ) {
50- shell ( `mv ${ file } ${ file . replace ( / \. [ ^ \. ] + $ / , '.hpp' ) } ` ) ;
51- }
52- } ) ;
53- }
54- } ) ;
55-
5620const categories = [
5721 'artificial-intelligence' ,
5822 'backtracking' ,
@@ -149,6 +113,12 @@ getFiles('../', (err, res) => {
149113 readme . push ( `
150114<!-- Please do not edit this file | This file is authomatically generated by ~/scripts/formatter.js -->
151115
116+ ## Maintainers
117+
118+ |[![1][1-avatar]][1]|[![2][2-avatar]][2]|
119+ | :-: | :-: |
120+ | [Carlos Abraham][1] | [Christian Bender][2] |
121+
152122## License
153123
154124This work is released under [MIT License][MIT]
@@ -166,11 +136,17 @@ To the extent possible under law, [Carlos Abraham](https://go.abranhe.com/github
166136
167137[MIT]: https://github.com/abranhe/algorithms/blob/master/license
168138[MIT-logo]: https://cdn.abranhe.com/projects/algorithms/mit-license.png
139+
140+ <!-- Maintainers -->
141+ [1]: https://github.com/abranhe
142+ [1-avatar]: https://avatars3.githubusercontent.com/u/21347264?s=50
143+ [2]: https://github.com/christianbender
144+ [2-avatar]: https://avatars3.githubusercontent.com/u/23243382?s=50
169145` ) ;
170146
171147 fs . writeFile ( `../readme.md` , readme . join ( '\n' ) , ( err ) => {
172148 if ( err ) throw err ;
173149 console . log ( chalk . green ( 'The file was succesfully saved!' ) ) ;
174150 } ) ;
175151 }
176- } ) ;
152+ } ) ;
0 commit comments