1
+ import { posixify } from '$lib/utils.js' ;
1
2
import fs from 'node:fs' ;
2
3
import path from 'node:path' ;
3
4
import glob from 'tiny-glob/sync.js' ;
@@ -32,16 +33,19 @@ function is_valid(dir) {
32
33
* @returns {import('$lib/types').PartStub[] }
33
34
*/
34
35
export function get_index ( ) {
35
- const parts = fs . readdirSync ( 'content/tutorial' ) . filter ( is_valid ) ;
36
+ const parts = fs . readdirSync ( 'content/tutorial' ) . filter ( is_valid ) . map ( posixify ) ;
36
37
37
38
return parts . map ( ( part ) => {
38
- const chapters = fs . readdirSync ( `content/tutorial/${ part } ` ) . filter ( is_valid ) ;
39
+ const chapters = fs . readdirSync ( `content/tutorial/${ part } ` ) . filter ( is_valid ) . map ( posixify ) ;
39
40
40
41
return {
41
42
slug : part ,
42
43
title : json ( `content/tutorial/${ part } /meta.json` ) . title ,
43
44
chapters : chapters . map ( ( chapter ) => {
44
- const exercises = fs . readdirSync ( `content/tutorial/${ part } /${ chapter } ` ) . filter ( is_valid ) ;
45
+ const exercises = fs
46
+ . readdirSync ( `content/tutorial/${ part } /${ chapter } ` )
47
+ . filter ( is_valid )
48
+ . map ( posixify ) ;
45
49
46
50
return {
47
51
slug : chapter ,
@@ -71,7 +75,7 @@ export function get_index() {
71
75
export function get_exercise ( slug ) {
72
76
const exercises = glob ( '[0-9][0-9]-*/[0-9][0-9]-*/[0-9][0-9]-*/README.md' , {
73
77
cwd : 'content/tutorial'
74
- } ) ;
78
+ } ) . map ( posixify ) ;
75
79
76
80
/** @type {string[] } */
77
81
const chain = [ ] ;
@@ -112,7 +116,7 @@ export function get_exercise(slug) {
112
116
const b_ = /** @type {import('$lib/types').FileStub } */ ( b [ key ] ) ;
113
117
114
118
if ( a_ . contents === b_ . contents ) {
115
- throw new Error ( `duplicate file: ${ exercise_slug } ${ key } ` )
119
+ throw new Error ( `duplicate file: ${ exercise_slug } ${ key } ` ) ;
116
120
}
117
121
}
118
122
@@ -192,7 +196,7 @@ export function get_exercise(slug) {
192
196
}
193
197
194
198
// ensure every code block for an exercise with multiple files has a `/// file:` annotation
195
- const filtered = Object . values ( solution ) . filter ( item => {
199
+ const filtered = Object . values ( solution ) . filter ( ( item ) => {
196
200
return item . type === 'file' && item . name . startsWith ( scope . prefix ) ;
197
201
} ) ;
198
202
@@ -208,7 +212,9 @@ export function get_exercise(slug) {
208
212
const all_files = { ...a , ...solution } ;
209
213
const filenames = new Set (
210
214
Object . keys ( all_files )
211
- . filter ( ( filename ) => filename . startsWith ( scope . prefix ) && all_files [ filename ] . type === 'file' )
215
+ . filter (
216
+ ( filename ) => filename . startsWith ( scope . prefix ) && all_files [ filename ] . type === 'file'
217
+ )
212
218
. map ( ( filename ) => filename . slice ( scope . prefix . length ) )
213
219
) ;
214
220
@@ -287,14 +293,14 @@ function walk(cwd, options = {}) {
287
293
* @param {number } depth
288
294
*/
289
295
function walk_dir ( dir , depth ) {
290
- const files = fs . readdirSync ( path . join ( cwd , dir ) ) ;
296
+ const files = fs . readdirSync ( path . join ( cwd , dir ) ) . map ( posixify ) ;
291
297
292
298
for ( const basename of files ) {
293
299
if ( excluded . has ( basename ) ) continue ;
294
300
295
301
const name = dir + basename ;
296
302
297
- if ( options . exclude ?. some ( ( exclude ) => name . replace ( / \\ / g , '/' ) . endsWith ( exclude ) ) ) continue ;
303
+ if ( options . exclude ?. some ( ( exclude ) => posixify ( name ) . endsWith ( exclude ) ) ) continue ;
298
304
299
305
const resolved = path . join ( cwd , name ) ;
300
306
const stats = fs . statSync ( resolved ) ;
0 commit comments