Skip to content

Commit 110d4ce

Browse files
committed
refactor: move getFilesRefList to its own file
1 parent 42990d1 commit 110d4ce

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

packages/astro/src/default/utils/content.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import type {
2-
ChapterSchema,
3-
FilesRefList,
4-
Lesson,
5-
LessonSchema,
6-
PartSchema,
7-
Tutorial,
8-
TutorialSchema,
9-
} from '@tutorialkit/types';
10-
import { folderPathToFilesRef, interpolateString } from '@tutorialkit/types';
1+
import type { ChapterSchema, Lesson, LessonSchema, PartSchema, Tutorial, TutorialSchema } from '@tutorialkit/types';
2+
import { interpolateString } from '@tutorialkit/types';
113
import { getCollection } from 'astro:content';
12-
import glob from 'fast-glob';
134
import path from 'node:path';
14-
import { IGNORED_FILES } from './constants';
155
import { DEFAULT_LOCALIZATION } from './content/default-localization';
166
import { squash } from './content/squash.js';
177
import { logger } from './logger';
188
import { joinPaths } from './url';
19-
20-
const CONTENT_DIR = path.join(process.cwd(), 'src/content/tutorial');
9+
import { getFilesRefList } from './content/files-ref';
2110

2211
export async function getTutorial(): Promise<Tutorial> {
2312
const collection = sortCollection(await getCollection('tutorial'));
@@ -331,24 +320,6 @@ function getSlug(entry: CollectionEntryTutorial) {
331320
return slug;
332321
}
333322

334-
async function getFilesRefList(pathToFolder: string): Promise<FilesRefList> {
335-
const root = path.join(CONTENT_DIR, pathToFolder);
336-
337-
const filePaths = (
338-
await glob(`${glob.convertPathToPattern(root)}/**/*`, {
339-
onlyFiles: true,
340-
ignore: IGNORED_FILES,
341-
dot: true,
342-
})
343-
).map((filePath) => `/${path.relative(root, filePath)}`);
344-
345-
filePaths.sort();
346-
347-
const filesRef = folderPathToFilesRef(pathToFolder);
348-
349-
return [filesRef, filePaths];
350-
}
351-
352323
interface CollectionEntryTutorial {
353324
id: string;
354325
slug: string;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { FilesRefList } from '@tutorialkit/types';
2+
import { folderPathToFilesRef } from '@tutorialkit/types';
3+
import glob from 'fast-glob';
4+
import path from 'node:path';
5+
import { IGNORED_FILES } from '../constants';
6+
7+
const CONTENT_DIR = path.join(process.cwd(), 'src/content/tutorial');
8+
9+
export async function getFilesRefList(pathToFolder: string, base = CONTENT_DIR): Promise<FilesRefList> {
10+
const root = path.join(base, pathToFolder);
11+
12+
const filePaths = (
13+
await glob(`${glob.convertPathToPattern(root)}/**/*`, {
14+
onlyFiles: true,
15+
ignore: IGNORED_FILES,
16+
dot: true,
17+
})
18+
).map((filePath) => `/${path.relative(root, filePath)}`);
19+
20+
filePaths.sort();
21+
22+
const filesRef = folderPathToFilesRef(pathToFolder);
23+
24+
return [filesRef, filePaths];
25+
}

packages/cli/tests/__snapshots__/create-tutorial.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ exports[`create and eject a project 1`] = `
253253
"src/utils/content",
254254
"src/utils/content.ts",
255255
"src/utils/content/default-localization.ts",
256+
"src/utils/content/files-ref.ts",
256257
"src/utils/content/squash.ts",
257258
"src/utils/logger.ts",
258259
"src/utils/nav.ts",

0 commit comments

Comments
 (0)