Skip to content

Commit 47b64dc

Browse files
committed
refactor: refactor file tree
1 parent 000962b commit 47b64dc

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

lib/commands/package/icons.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sharp from "sharp";
2+
import File from "#core/file";
23
import FileTree from "#core/file-tree";
34
import Command from "#lib/command";
45

@@ -143,10 +144,10 @@ export default class extends Command {
143144

144145
if ( target.greyscale ) icon.greyscale();
145146

146-
fileTree.add( {
147+
fileTree.add( new File( {
147148
"path": "resources/" + name,
148149
"sources": await icon.toFormat( "png" ).toBuffer(),
149-
} );
150+
} ) );
150151
}
151152
}
152153
}

lib/package.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,10 +1289,10 @@ export default class Package {
12891289
}
12901290
}
12911291

1292-
fileTree.add( {
1292+
fileTree.add( new File( {
12931293
"path": ( pkg.rootSlug || "" ) + "/package.json",
12941294
"sources": JSON.stringify( config, null, 4 ) + "\n",
1295-
} );
1295+
} ) );
12961296

12971297
// chmod
12981298
res = await pkg.updateFilesMode();
@@ -1302,7 +1302,6 @@ export default class Package {
13021302
// dependabot
13031303
if ( updateDependabot ) {
13041304
res = await this.#updateDependabotConfig();
1305-
13061305
if ( !res.ok ) return res;
13071306

13081307
if ( res.data ) {
@@ -1311,9 +1310,9 @@ export default class Package {
13111310
}
13121311

13131312
// lint
1314-
for ( const file of fileTree ) {
1313+
for ( const [ filePath, file ] of fileTree ) {
13151314
const res = await lintFile( new File( {
1316-
"path": path.join( this.root, file.path ),
1315+
"path": path.join( this.root, filePath ),
13171316
"sources": await file.text(),
13181317
} ) );
13191318

lib/package/docs.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,37 +129,37 @@ export default class Docs {
129129
if ( this.location !== "/" ) {
130130

131131
// default readme
132-
fileTree.add( {
132+
fileTree.add( new File( {
133133
"path": "README.md",
134134
"sources": await ejs.renderFile( readmeTmpl, options ),
135-
} );
135+
} ) );
136136
}
137137
else {
138138

139139
// copy root readme
140140
if ( await pathExists( this.#package.root + "/README.md" ) ) {
141-
fileTree.add( {
141+
fileTree.add( new File( {
142142
"path": "README.md",
143143
"sources": fs.readFileSync( this.#package.root + "/README.md" ),
144-
} );
144+
} ) );
145145
}
146146

147147
// default readme
148148
else {
149-
fileTree.add( {
149+
fileTree.add( new File( {
150150
"path": "README.md",
151151
"sources": await ejs.renderFile( readmeTmpl, options ),
152-
} );
152+
} ) );
153153
}
154154
}
155155
}
156156

157157
// generate default sidebar
158158
if ( !( await pathExists( this.locationPath + "/_sidebar.md" ) ) ) {
159-
fileTree.add( {
159+
fileTree.add( new File( {
160160
"path": "_sidebar.md",
161161
"sources": await ejs.renderFile( utils.resolve( "#resources/templates/docs/_sidebar.md", import.meta.url ), options ),
162-
} );
162+
} ) );
163163
}
164164

165165
await fileTree.write( this.locationPath );
@@ -230,10 +230,10 @@ export default class Docs {
230230

231231
// lint
232232
if ( lint ) {
233-
for ( const file of fileTree ) {
233+
for ( const path of fileTree.keys() ) {
234234
const res = await lintFile(
235235
new File( {
236-
"path": this.locationPath + "/" + file.path,
236+
"path": this.locationPath + "/" + path,
237237
} ),
238238
{
239239
"write": true,
@@ -257,10 +257,10 @@ export default class Docs {
257257

258258
// TODO: replace relative urls
259259

260-
fileTree.add( {
260+
fileTree.add( new File( {
261261
"path": "README.md",
262262
"sources": await ejs.renderFile( template, options ),
263-
} );
263+
} ) );
264264

265265
await fileTree.write( this.#package.root );
266266
}

resources/docs-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ for ( const type in options.types ) {
2222
if ( !res.ok ) throw res;
2323
const fileTree = res.data;
2424

25-
for ( const file of fileTree ) {
26-
data[ type + "/" + file.path ] = await file.text();
25+
for ( const [ filePath, file ] of fileTree ) {
26+
data[ type + "/" + filePath ] = await file.text();
2727
}
2828
}
2929

0 commit comments

Comments
 (0)