Skip to content

Commit e29ec01

Browse files
committed
Fixed CSS compiling to ignore files that start with underscore. Also fixed destination filename when copying SASS, SCSS or LESS files.
1 parent 5a7eb83 commit e29ec01

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

  • src/obsidian-build-tools

src/obsidian-build-tools/lib.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ export function clearScreen(): void {
263263

264264
/**
265265
* Wraps the text in ANSI sequence to make the foreground color red.
266-
*
266+
*
267267
* @param text The text that should be made red.
268-
*
268+
*
269269
* @returns A new string with the text wrapped in ANSI sequences.
270270
*/
271271
export function red(text: string): string {
@@ -274,9 +274,9 @@ export function red(text: string): string {
274274

275275
/**
276276
* Wraps the text in ANSI sequence to make the foreground color green.
277-
*
277+
*
278278
* @param text The text that should be made green.
279-
*
279+
*
280280
* @returns A new string with the text wrapped in ANSI sequences.
281281
*/
282282
export function green(text: string): string {
@@ -285,9 +285,9 @@ export function green(text: string): string {
285285

286286
/**
287287
* Wraps the text in ANSI sequence to make the foreground color yellow.
288-
*
288+
*
289289
* @param text The text that should be made yellow.
290-
*
290+
*
291291
* @returns A new string with the text wrapped in ANSI sequences.
292292
*/
293293
export function yellow(text: string): string {
@@ -296,9 +296,9 @@ export function yellow(text: string): string {
296296

297297
/**
298298
* Wraps the text in ANSI sequence to make the foreground color dim.
299-
*
299+
*
300300
* @param text The text that should be made dim.
301-
*
301+
*
302302
* @returns A new string with the text wrapped in ANSI sequences.
303303
*/
304304
export function dim(text: string): string {
@@ -558,13 +558,13 @@ export function defineScriptFileBuilder(input: string, output: string, options:
558558
* Defines the configuration for all the stylesheet files that need to be
559559
* compiled, including those in sub directories, for a given directory. Any
560560
* filename ending with .css, .less, .scss or .sass will be included.
561-
*
561+
*
562562
* @param sourcePath The base path to use when searching for files to compile.
563563
* @param outputPath The base output path to use when writing the compiled
564564
* files. The relative paths to the source files will be maintained when
565565
* compiled to this location.
566566
* @param options The options that define how the files are compiled.
567-
*
567+
*
568568
* @returns An array of {@link BundleBuilder} objects.
569569
*/
570570
export function defineStylesheetBuilders(sourcePath: string, outputPath: string, options: ConfigOptions): BundleBuilder[] {
@@ -579,7 +579,10 @@ export function defineStylesheetBuilders(sourcePath: string, outputPath: string,
579579

580580
const files = globSync(sourcePath.replace(/\\/g, "/") + "/**/*.@(css|less|sass|scss)")
581581
.map(f => path.normalize(f).substring(sourcePath.length + 1))
582-
.filter(f => !ignoredExtensions.some(ext => f.endsWith(ext)));
582+
// Ignore any files that are partials, or those whose name starts with
583+
// an underscore, which is a common convention for partial CSS files.
584+
.filter(f => !ignoredExtensions.some(ext => f.endsWith(ext))
585+
&& !path.basename(f).startsWith("_"));
583586

584587
return files.map(file => {
585588
let outFile = file;
@@ -591,7 +594,7 @@ export function defineStylesheetBuilders(sourcePath: string, outputPath: string,
591594
const configuration: StylesheetConfiguration = {
592595
source: path.join(sourcePath, file),
593596
destination: path.join(outputPath, outFile),
594-
minify: false
597+
minify: options.minify === true,
595598
};
596599

597600
// If the caller requested a copy operation, append the path to the
@@ -615,9 +618,9 @@ export function defineStylesheetBuilders(sourcePath: string, outputPath: string,
615618

616619
/**
617620
* Builds a single stylesheet from the configuration.
618-
*
621+
*
619622
* @param configuration The configuration that defines the stylesheet to build.
620-
*
623+
*
621624
* @returns An instance of {@link Bundle} describing the output.
622625
*/
623626
export async function buildStylesheet(configuration: StylesheetConfiguration): Promise<Bundle> {
@@ -646,7 +649,7 @@ export async function buildStylesheet(configuration: StylesheetConfiguration): P
646649

647650
if (configuration.copy) {
648651
await mkdir(configuration.copy, { recursive: true });
649-
await writeFile(path.join(configuration.copy, path.basename(configuration.source)), css);
652+
await writeFile(path.join(configuration.copy, path.basename(configuration.destination)), css);
650653
}
651654

652655
const duration = Math.floor((Date.now() - start) / 1000);
@@ -667,13 +670,13 @@ export async function buildStylesheet(configuration: StylesheetConfiguration): P
667670
* Defines the configuration for all the static files that need to be
668671
* "compiled", including those in sub directories, for a given directory. Any
669672
* filename ending with .css, .less, .scss or .sass will be included.
670-
*
673+
*
671674
* @param sourcePath The base path to use when searching for files to compile.
672675
* @param outputPath The base output path to use when writing the compiled
673676
* files. The relative paths to the source files will be maintained when
674677
* compiled to this location.
675678
* @param options The options that define how the files are compiled.
676-
*
679+
*
677680
* @returns An array of {@link BundleBuilder} objects.
678681
*/
679682
export function defineStaticFileBuilders(sourcePath: string, outputPath: string, options: ConfigOptions): BundleBuilder[] {
@@ -726,9 +729,9 @@ export function defineStaticFileBuilders(sourcePath: string, outputPath: string,
726729

727730
/**
728731
* Builds a single static from the configuration.
729-
*
732+
*
730733
* @param configuration The configuration that defines the static file to copy.
731-
*
734+
*
732735
* @returns An instance of {@link Bundle} describing the output.
733736
*/
734737
export async function buildStaticFile(configuration: StaticFileConfiguration): Promise<Bundle> {
@@ -747,11 +750,11 @@ export async function buildStaticFile(configuration: StaticFileConfiguration): P
747750
}
748751

749752
await mkdir(path.dirname(configuration.destination), { recursive: true });
750-
await writeFile(configuration.destination, data);
753+
await writeFile(configuration.destination, data as Uint8Array);
751754

752755
if (configuration.copy) {
753756
await mkdir(configuration.copy, { recursive: true });
754-
await writeFile(path.join(configuration.copy, path.basename(configuration.source)), data);
757+
await writeFile(path.join(configuration.copy, path.basename(configuration.destination)), data as Uint8Array);
755758
}
756759

757760
const duration = Math.floor((Date.now() - start) / 1000);
@@ -781,7 +784,7 @@ export class BundleError extends Error {
781784

782785
/**
783786
* Creates a new instance of {@link BundleError}.
784-
*
787+
*
785788
* @param message The message that describes the error.
786789
* @param filename The filename that caused the error.
787790
* @param line The line number that caused the error.
@@ -814,7 +817,7 @@ export class Watcher {
814817

815818
/**
816819
* Creates a new instance of {@link Watcher}.
817-
*
820+
*
818821
* @param callback The function to call when any file has changed.
819822
*/
820823
public constructor(callback: () => void) {
@@ -829,7 +832,7 @@ export class Watcher {
829832
/**
830833
* Updates the list of watched files by adding new watchers and removing old
831834
* watchers based on the list of files.
832-
*
835+
*
833836
* @param files The new list of files to be watched.
834837
*/
835838
public updateWatchFiles(files: string[]): void {

0 commit comments

Comments
 (0)