@@ -10,7 +10,7 @@ const caption = concolor('b,white');
10
10
const fatal = concolor ( 'b,white/red' ) ;
11
11
const fixup = concolor ( 'b,black/yellow' ) ;
12
12
13
- const TITLE = caption ` Software engineering self assessment` ;
13
+ const TITLE = ' Software engineering self assessment' ;
14
14
const PARSING_TIMEOUT = 1000 ;
15
15
const EXECUTION_TIMEOUT = 5000 ;
16
16
@@ -29,27 +29,27 @@ let exitCode = 0;
29
29
const wrongFormat = ( msg , file ) => {
30
30
exitCode = 1 ;
31
31
console . log ( fatal ` Wrong file format: ${ msg } ` ) ;
32
- console . log ( ` File: ${ file } `) ;
32
+ console . log ( fatal ` File: ${ file } `) ;
33
33
} ;
34
34
35
35
const warnFixup = ( msg , file ) => {
36
36
console . log ( fixup ` Fixup file format: ${ msg } ` ) ;
37
- console . log ( ` File: ${ file } `) ;
37
+ console . log ( fixup ` File: ${ file } `) ;
38
38
} ;
39
39
40
40
const codeBlock = ( code ) => '```\n' + code + '\n```' ;
41
41
42
- const loadFile = async ( file ) => {
43
- const fileName = path . join ( PATH , file ) ;
44
- const data = await fs . readFile ( fileName , 'utf8' ) ;
42
+ const loadFile = async ( filePath ) => {
43
+ const fileName = path . basename ( filePath ) ;
44
+ const data = await fs . readFile ( filePath , 'utf8' ) ;
45
45
if ( data . includes ( '\r' ) ) {
46
- warnFixup ( 'expected LF linebreaks, not CRLF or CR' , file ) ;
46
+ warnFixup ( 'expected LF linebreaks, not CRLF or CR' , fileName ) ;
47
47
}
48
48
if ( ! data . startsWith ( '## ' ) ) {
49
- wrongFormat ( 'no markdown «## Heading»' , file ) ;
49
+ wrongFormat ( 'no markdown «## Heading»' , fileName ) ;
50
50
}
51
51
if ( ! data . endsWith ( '\n' ) ) {
52
- warnFixup ( 'no newline at the end of file' , file ) ;
52
+ warnFixup ( 'no newline at the end of file' , fileName ) ;
53
53
}
54
54
return data ;
55
55
} ;
@@ -115,13 +115,14 @@ const formatSkill = (line) => {
115
115
return { skill, level } ;
116
116
} ;
117
117
118
- const getSkills = ( data , file ) => {
118
+ const getSkills = ( data , file , options ) => {
119
119
const lines = data . split ( '\n' ) ;
120
120
if ( lines . at ( - 1 ) . trim ( ) === '' ) lines . pop ( ) ;
121
121
let section = '' ;
122
122
let empty = 0 ;
123
+ const sections = { } ;
124
+ const skills = new Set ( ) ;
123
125
const out = [ ] ;
124
- const skills = [ ] ;
125
126
for ( const [ i , s ] of lines . entries ( ) ) {
126
127
const line = s . trim ( ) ;
127
128
if ( line === '' ) {
@@ -141,6 +142,7 @@ const getSkills = (data, file) => {
141
142
if ( s . startsWith ( '-' ) ) {
142
143
out . push ( line ) ;
143
144
section = line . slice ( 1 ) . trim ( ) ;
145
+ sections [ section ] = { } ;
144
146
continue ;
145
147
}
146
148
if ( s . startsWith ( ' -' ) ) {
@@ -149,93 +151,72 @@ const getSkills = (data, file) => {
149
151
const msg = 'not matching level and emoji' ;
150
152
wrongFormat ( `${ msg } «${ line } » at line ${ i + 1 } ` , file ) ;
151
153
out . push ( `${ s } 👉 Warning: ${ msg } ` ) ;
152
- skills . push ( skill ) ;
154
+ skills . add ( skill ) ;
153
155
continue ;
154
156
}
155
- if ( skills . includes ( skill ) ) {
157
+ if ( skills . has ( skill ) && options . unique ) {
156
158
warnFixup ( `removed duplicate skill «${ skill } » at line ${ i + 1 } ` , file ) ;
157
159
} else {
158
- out . push ( ` - ${ skill } ${ level ? ': ' + level : '' } ` ) ;
159
- skills . push ( skill ) ;
160
+ if ( level ) {
161
+ out . push ( ` - ${ skill } : ${ level } ` ) ;
162
+ sections [ section ] [ skill ] = level ;
163
+ } else {
164
+ out . push ( ` - ${ skill } ` ) ;
165
+ sections [ section ] [ skill ] = '' ;
166
+ }
167
+ skills . add ( skill ) ;
160
168
}
161
169
continue ;
162
170
}
163
171
wrongFormat ( `unkonw structure at line ${ i + 1 } ` , file ) ;
164
172
}
165
173
const output = out . join ( '\n' ) + '\n' ;
166
174
if ( data !== output ) {
167
- const fileName = path . join ( PATH , file ) ;
168
- fs . writeFile ( fileName , output ) . catch ( ( ) => { } ) ;
169
- console . log ( `Fixup: ${ data . length } -> ${ output . length } saved: ${ file } ` ) ;
175
+ fs . writeFile ( file , output ) . catch ( ( ) => { } ) ;
176
+ const fileName = file . slice ( PATH . length ) ;
177
+ console . log ( `Fixup: ${ data . length } -> ${ output . length } saved: ${ fileName } ` ) ;
170
178
}
171
- return skills ;
179
+ return { sections , skills } ;
172
180
} ;
173
181
174
- const getRoles = ( data , file ) => {
175
- const lines = data . split ( '\n' ) ;
176
- if ( lines . at ( - 1 ) . trim ( ) === '' ) lines . pop ( ) ;
177
- let section = '' ;
178
- const roles = { } ;
179
- for ( const [ i , s ] of lines . entries ( ) ) {
180
- const line = s . trim ( ) ;
181
- if ( s . startsWith ( '-' ) ) {
182
- section = line . slice ( 1 ) . trim ( ) ;
183
- roles [ section ] = [ ] ;
184
- continue ;
185
- }
186
- if ( s . startsWith ( ' -' ) ) {
187
- const skill = line . slice ( 1 ) . trim ( ) ;
188
- roles [ section ] . push ( skill ) ;
189
- }
190
- }
191
- return roles ;
192
- } ;
193
-
194
- const analise = async ( section ) => {
195
- console . log ( caption `Skills: ${ section } ` ) ;
196
- const file = `Skills/${ section } .md` ;
182
+ const analise = async ( dir , unit , options ) => {
183
+ console . log ( caption `Unit: ${ unit } ` ) ;
184
+ const file = `${ dir } /${ unit } .md` ;
197
185
const md = await loadFile ( file ) ;
198
- const skills = getSkills ( md , file ) ;
199
- console . log ( `Count: ${ skills . length } \n` ) ;
200
- return skills ;
201
- } ;
202
-
203
- const match = async ( role ) => {
204
- console . log ( caption `Roles: ${ role } ` ) ;
205
- const file = `.github/src/Roles/${ role } .md` ;
206
- const md = await loadFile ( file ) ;
207
- const roles = getRoles ( md , file ) ;
208
- console . log ( `Count: ${ Object . keys ( roles ) . length } \n` ) ;
209
- return roles ;
186
+ const data = getSkills ( md , file , options ) ;
187
+ const { sections, skills } = data ;
188
+ const count = Object . keys ( sections ) . length ;
189
+ console . log ( `Sections: ${ count } , Skills: ${ skills . size } \n` ) ;
190
+ return data ;
210
191
} ;
211
192
212
- const loadDir = async ( dir , mapper ) => {
193
+ const loadDir = async ( place , options = { } ) => {
194
+ const dir = path . join ( PATH , place ) ;
213
195
const files = await fs . readdir ( dir ) ;
214
- const sections = files
196
+ const units = files
215
197
. filter ( ( file ) => file . endsWith ( '.md' ) )
216
198
. map ( ( file ) => file . substring ( 0 , file . length - '.md' . length ) ) ;
217
199
const collection = { } ;
218
- for ( const section of sections ) {
219
- collection [ section ] = await mapper ( section ) ;
200
+ for ( const unit of units ) {
201
+ collection [ unit ] = await analise ( dir , unit , options ) ;
220
202
}
221
203
return collection ;
222
204
} ;
223
205
224
206
( async ( ) => {
225
- console . log ( TITLE ) ;
207
+ console . log ( caption ` ${ TITLE } ` ) ;
226
208
console . log ( 'Auto Checker\n' ) ;
227
209
228
- const skills = await loadDir ( ` ${ PATH } / Skills/` , analise ) ;
229
- const roles = await loadDir ( ` ${ PATH } / .github/src/Roles/` , match ) ;
210
+ const skills = await loadDir ( ' Skills' , { unique : true } ) ;
211
+ const roles = await loadDir ( ' .github/src/Roles' ) ;
230
212
231
213
const badgeCode = codeBlock ( BADGE ) ;
232
-
233
214
const report = `## ${ TITLE } \n\n${ BADGE } \n\n${ badgeCode } \n` ;
234
215
await fs . writeFile ( `${ PATH } /Profile/REPORT.md` , report ) ;
235
216
236
- const readme = await loadFile ( ' .github/src/Templates/README.md' ) ;
237
- const newReadme = readme . replace ( '$BADGE' , BADGE ) ;
238
- await fs . writeFile ( `${ PATH } /README.md` , newReadme ) ;
217
+ const template = await loadFile ( ` ${ PATH } / .github/src/Templates/README.md` ) ;
218
+ const readme = template . replace ( '$BADGE' , BADGE ) ;
219
+ await fs . writeFile ( `${ PATH } /README.md` , readme ) ;
239
220
240
221
console . log ( '' ) ;
241
222
process . exit ( exitCode ) ;
0 commit comments