Skip to content

Commit

Permalink
Merge pull request #212 from cosmology-tech/fix/image-handling
Browse files Browse the repository at this point in the history
Fix image handling
  • Loading branch information
pyramation authored Oct 8, 2024
2 parents c198450 + f14a9ba commit 36ade1d
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions packages/create-cosmos-app/src/git-cca-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,47 @@ export const createGitApp = (repo: string, version: string) => {
const templateFile = files[i];
if (fs.lstatSync(templateFile).isDirectory()) continue;

let content = fs.readFileSync(templateFile).toString();

// LICENSE
if (
basename(templateFile) === 'LICENSE' &&
// @ts-ignore
license.__LICENSE__ === 'closed'
) {
content = `Copyright (c) ${new Date().getFullYear()} __USERFULLNAME__ <__USEREMAIL__> - All Rights Reserved
const isImage = /\.(png|jpe?g|gif|svg|webp|ico)$/i.test(templateFile);

let content;
if (isImage) {
content = fs.readFileSync(templateFile);
} else {
content = fs.readFileSync(templateFile).toString();

// LICENSE
if (
basename(templateFile) === 'LICENSE' &&
// @ts-ignore
license.__LICENSE__ === 'closed'
) {
content = `Copyright (c) ${new Date().getFullYear()} __USERFULLNAME__ <__USEREMAIL__> - All Rights Reserved
Unauthorized copying via any medium is strictly prohibited
Proprietary and confidential`;
}

// swap out content from results!
Object.keys(results).forEach(key => {
if (/^__/.test(key)) {
content = content.replace(new RegExp(key, 'g'), results[key]);
}
});

// access
if (hasResults) {
// Determine the prefix based on the conditions
let prefix = '';
if (results.__ACCESS__ === 'public') {
prefix = scopedResults.scoped ? `@${results.__USERNAME__}/` : '';
} else {
prefix = `@${results.__USERNAME__}/`;
}

// Replace __PACKAGE_IDENTIFIER__ with the determined prefix and module name
content = content.replace(/__PACKAGE_IDENTIFIER__/g, `${prefix}${results.__MODULENAME__}`);
// swap out content from results!
Object.keys(results).forEach((key) => {
if (/^__/.test(key)) {
content = content.replace(new RegExp(key, 'g'), results[key]);
}
});

// access
if (hasResults) {
// Determine the prefix based on the conditions
let prefix = '';
if (results.__ACCESS__ === 'public') {
prefix = scopedResults.scoped ? `@${results.__USERNAME__}/` : '';
} else {
prefix = `@${results.__USERNAME__}/`;
}

// Replace __PACKAGE_IDENTIFIER__ with the determined prefix and module name
content = content.replace(/__PACKAGE_IDENTIFIER__/g, `${prefix}${results.__MODULENAME__}`);
}
}


// Construct the file path
const relativeFilePath = templateFile.split(toPosixPath(join(folderName, template) + '/'))[1];

Expand Down

0 comments on commit 36ade1d

Please sign in to comment.