Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions add-template-suffix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const suffix = '.template';

console.log(`Renaming files in ${path}...`);
const files = getRecursiveFileList(path).filter(
(file) => !file.endsWith(suffix)
(file) => !file.endsWith(suffix) && !file.endsWith('.DS_Store')
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always ignore the .DS_Store files so we filter them here and I removed them from the template.


if (!files.length) {
Expand All @@ -19,7 +19,13 @@ if (!files.length) {
}

for (const file of files) {
if (file.endsWith(".meta") || file.endsWith(".png") || file.endsWith(".dll")|| file.endsWith(".unity")) {
if (
file.endsWith('.meta') ||
file.endsWith('.png') ||
file.endsWith('.dll') ||
file.endsWith('.unity') ||
file.endsWith('.DS_Store')
) {
continue;
}
const newFile = `${file}${suffix}`;
Expand Down
17,011 changes: 16,588 additions & 423 deletions packages/preset-lumberjack/src/generators/preset/__snapshots__/generator.spec.ts.snap

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 28 additions & 6 deletions packages/preset-lumberjack/src/util/get-gecursive-file-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import { Tree } from '@nx/devkit';

export interface FileContents {
path: string;
content?: string;
content?: string | string[];
isBinary?: boolean;
children?: Record<string, FileContents>;
}

const binaries = [
'asset',
'cginc',
'DS_Store',
'dll',
'dwlt',
'eot',
'gif',
'ico',
'jpeg',
'jpg',
'lock',
'mat',
'mdb',
'meta',
'pdf',
'png',
Expand All @@ -28,26 +32,44 @@ const binaries = [
'woff2',
];

export function getRecursiveFileContents(tree: Tree, path: string) {
export function getRecursiveFileContents(
tree: Tree,
path: string,
includeBinaries = false
) {
const contents: Record<string, FileContents> = {};
const dir = tree.children(path);
const dir = tree.children(path).sort();
dir.forEach((file) => {
if (tree.isFile(`${path}/${file}`)) {
const isBinary = binaries.includes(file.split('.').pop());
const content = tree.read(`${path}/${file}`);
const binaryContent = includeBinaries ? content.toString('base64') : null;

contents[file] = {
path: `${path}/${file}`,
isBinary,
content: isBinary
? null
: tree.read(`${path}/${file}`).toString('utf-8'),
? binaryContent
: formatOutput(content.toString('utf-8')),
};
} else {
contents[file] = {
path: `${path}/${file}`,
children: getRecursiveFileContents(tree, `${path}/${file}`),
children: getRecursiveFileContents(
tree,
`${path}/${file}`,
includeBinaries
),
};
}
});

return contents;
}

export function formatOutput(value: string) {
return value
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0);
}