diff --git a/_gulp/modules/pathConfig.test.ts b/_gulp/modules/pathConfig.test.ts index 7717307..c220700 100644 --- a/_gulp/modules/pathConfig.test.ts +++ b/_gulp/modules/pathConfig.test.ts @@ -1,6 +1,6 @@ import test from 'node:test'; import assert from 'node:assert/strict'; -import { resolveProjectPaths } from './pathConfig'; +import { resolveProjectPaths, resolveWatchGlobs } from './pathConfig'; test('resolveProjectPaths returns correct folders/extensions for Sass + JavaScript + HTML', () => { const result = resolveProjectPaths({ @@ -35,3 +35,33 @@ test('resolveProjectPaths returns correct folders/extensions for SCSS + TypeScri assert.equal(result.markupFolder, 'pug'); assert.equal(result.markupExtension, 'pug'); }); + +test('resolveWatchGlobs returns expected watch paths for JavaScript + Sass + HTML', () => { + const globs = resolveWatchGlobs({ + script: 'JavaScript', + style: 'Sass', + markup: 'HTML', + addNormalize: false, + addReset: false, + }); + + assert.equal(globs.styleGlob, 'src/sass/**/*.sass'); + assert.equal(globs.scriptGlob, 'src/js/**/*.js'); + assert.equal(globs.markupGlob, 'src/html/**/*.html'); + assert.equal(globs.imageGlob, 'src/img/**/*'); +}); + +test('resolveWatchGlobs returns expected watch paths for TypeScript + SCSS + Pug', () => { + const globs = resolveWatchGlobs({ + script: 'TypeScript', + style: 'SCSS', + markup: 'Pug', + addNormalize: true, + addReset: true, + }); + + assert.equal(globs.styleGlob, 'src/scss/**/*.scss'); + assert.equal(globs.scriptGlob, 'src/ts/**/*.ts'); + assert.equal(globs.markupGlob, 'src/pug/**/*.pug'); + assert.equal(globs.imageGlob, 'src/img/**/*'); +}); diff --git a/_gulp/modules/pathConfig.ts b/_gulp/modules/pathConfig.ts index 407e2e7..5e2ef7e 100644 --- a/_gulp/modules/pathConfig.ts +++ b/_gulp/modules/pathConfig.ts @@ -10,6 +10,13 @@ export interface ResolvedProjectPaths { markupExtension: 'html' | 'pug'; } +export interface ResolvedWatchGlobs { + styleGlob: string; + scriptGlob: string; + markupGlob: string; + imageGlob: 'src/img/**/*'; +} + export function resolveProjectPaths(choices: UserChoices): ResolvedProjectPaths { const styleFolder = choices.style === 'Sass' ? 'sass' : 'scss'; @@ -23,3 +30,14 @@ export function resolveProjectPaths(choices: UserChoices): ResolvedProjectPaths markupExtension: choices.markup === 'Pug' ? 'pug' : 'html', }; } + +export function resolveWatchGlobs(choices: UserChoices): ResolvedWatchGlobs { + const paths = resolveProjectPaths(choices); + + return { + styleGlob: `src/${paths.styleFolder}/**/*.${paths.styleExtension}`, + scriptGlob: `src/${paths.scriptFolder}/**/*.${paths.scriptExtension}`, + markupGlob: `src/${paths.markupFolder}/**/*.${paths.markupExtension}`, + imageGlob: 'src/img/**/*', + }; +} diff --git a/_gulp/templates/gulpfile/sections.ts b/_gulp/templates/gulpfile/sections.ts index a36e598..daf9975 100644 --- a/_gulp/templates/gulpfile/sections.ts +++ b/_gulp/templates/gulpfile/sections.ts @@ -86,7 +86,7 @@ export function imagesSection(): string { }`; } -export function devServerSection({ styleFolder, styleExtension, scriptFolder, scriptExtension, markupFolder, markupExtension }: GulpTemplateContext): string { +export function devServerSection({ styleGlob, scriptGlob, markupGlob, imageGlob }: GulpTemplateContext): string { return `function serve(cb) { browserSync.init({ server: { @@ -98,10 +98,10 @@ export function devServerSection({ styleFolder, styleExtension, scriptFolder, sc } function watchFiles(cb) { - watch('src/${styleFolder}/**/*.${styleExtension}', styles); - watch('src/${scriptFolder}/**/*.${scriptExtension}', series(scripts, reload)); - watch('src/${markupFolder}/**/*.${markupExtension}', series(markup, reload)); - watch('src/img/**/*', series(images, reload)); + watch('${styleGlob}', styles); + watch('${scriptGlob}', series(scripts, reload)); + watch('${markupGlob}', series(markup, reload)); + watch('${imageGlob}', series(images, reload)); cb(); } diff --git a/_gulp/templates/gulpfile/types.ts b/_gulp/templates/gulpfile/types.ts index 909d61f..4c2f7b0 100644 --- a/_gulp/templates/gulpfile/types.ts +++ b/_gulp/templates/gulpfile/types.ts @@ -1,7 +1,7 @@ -import { resolveProjectPaths, ResolvedProjectPaths } from '../../modules/pathConfig'; +import { resolveProjectPaths, ResolvedProjectPaths, resolveWatchGlobs, ResolvedWatchGlobs } from '../../modules/pathConfig'; import { UserChoices } from '../../types'; -export interface GulpTemplateContext extends ResolvedProjectPaths { +export interface GulpTemplateContext extends ResolvedProjectPaths, ResolvedWatchGlobs { choices: UserChoices; } @@ -9,5 +9,6 @@ export function createGulpTemplateContext(choices: UserChoices): GulpTemplateCon return { choices, ...resolveProjectPaths(choices), + ...resolveWatchGlobs(choices), }; }