Skip to content

Commit 08f0af5

Browse files
authored
Merge pull request #1 from bertdeblock/ensure-consistent-output
Ensure consistent output
2 parents 26ec411 + 71243dc commit 08f0af5

File tree

4 files changed

+23
-45
lines changed

4 files changed

+23
-45
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"dependencies": {
3131
"chalk": "^5.3.0",
3232
"change-case": "^5.4.3",
33-
"fs-extra": "^11.2.0",
34-
"recursive-readdir": "^2.2.3"
33+
"fast-glob": "^3.3.2",
34+
"fs-extra": "^11.2.0"
3535
},
3636
"devDependencies": {
3737
"@release-it-plugins/lerna-changelog": "^6.1.0",

pnpm-lock.yaml

Lines changed: 7 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generate-template-registry.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import chalk from "chalk";
22
import { camelCase, pascalCase } from "change-case";
3+
import glob from "fast-glob";
34
import { pathExists, readJson } from "fs-extra/esm";
45
import { writeFile } from "node:fs/promises";
56
import { join, parse } from "node:path";
67
import { cwd as processCwd } from "node:process";
7-
import recursiveReadDir from "recursive-readdir";
88

99
export async function generateTemplateRegistry(cwd = processCwd()) {
1010
let packageJson: any;
@@ -116,17 +116,16 @@ async function getEntries(dir: string): Promise<string[]> {
116116
const paths: string[] = [];
117117

118118
if (await pathExists(dir)) {
119-
const files = await recursiveReadDir(dir);
119+
const files = await glob("**/*", { cwd: dir });
120120

121-
files.forEach((file) => {
121+
files.sort().forEach((file) => {
122122
const parsed = parse(file);
123-
const folder = parsed.dir.replace(`${dir}`, "");
124123

125124
let path: string;
126125
if (parsed.name === "index") {
127-
path = folder.substring(1);
126+
path = parsed.dir;
128127
} else {
129-
path = `${folder}/${parsed.name}`.substring(1);
128+
path = parsed.dir ? `${parsed.dir}/${parsed.name}` : parsed.name;
130129
}
131130

132131
if (paths.includes(path) === false) {

test/__snapshots__/generate-template-registry.test.ts.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
exports[`generates a template registry for a v1 addon 1`] = `
44
"// Components:
5-
import type FooComponent from "v1-addon/components/foo";
65
import type BarComponent from "v1-addon/components/bar";
6+
import type FooComponent from "v1-addon/components/foo";
77
import type FooBarComponent from "v1-addon/components/foo/bar";
88
99
export default interface Registry {
1010
// Components:
11-
Foo: typeof FooComponent;
12-
"foo": typeof FooComponent;
1311
Bar: typeof BarComponent;
1412
"bar": typeof BarComponent;
13+
Foo: typeof FooComponent;
14+
"foo": typeof FooComponent;
1515
"Foo::Bar": typeof FooBarComponent;
1616
"foo/bar": typeof FooBarComponent;
1717
}
@@ -20,16 +20,16 @@ export default interface Registry {
2020

2121
exports[`generates a template registry for a v2 addon 1`] = `
2222
"// Components:
23-
import type FooComponent from "./components/foo";
2423
import type BarComponent from "./components/bar";
24+
import type FooComponent from "./components/foo";
2525
import type FooBarComponent from "./components/foo/bar";
2626
2727
export default interface Registry {
2828
// Components:
29-
Foo: typeof FooComponent;
30-
"foo": typeof FooComponent;
3129
Bar: typeof BarComponent;
3230
"bar": typeof BarComponent;
31+
Foo: typeof FooComponent;
32+
"foo": typeof FooComponent;
3333
"Foo::Bar": typeof FooBarComponent;
3434
"foo/bar": typeof FooBarComponent;
3535
}
@@ -38,16 +38,16 @@ export default interface Registry {
3838

3939
exports[`generates a template registry for an app 1`] = `
4040
"// Components:
41-
import type FooComponent from "app/components/foo";
4241
import type BarComponent from "app/components/bar";
42+
import type FooComponent from "app/components/foo";
4343
import type FooBarComponent from "app/components/foo/bar";
4444
4545
export default interface Registry {
4646
// Components:
47-
Foo: typeof FooComponent;
48-
"foo": typeof FooComponent;
4947
Bar: typeof BarComponent;
5048
"bar": typeof BarComponent;
49+
Foo: typeof FooComponent;
50+
"foo": typeof FooComponent;
5151
"Foo::Bar": typeof FooBarComponent;
5252
"foo/bar": typeof FooBarComponent;
5353
}

0 commit comments

Comments
 (0)