-
Notifications
You must be signed in to change notification settings - Fork 734
Infra/assets internal new structure #3635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 33 commits
627ecbb
09884c2
517b077
2219ccb
bf5b253
9c59698
76d7e03
c25d1e5
1224520
5bac3cf
893c73e
656b0ac
d9168a8
f5099c3
64e5930
94b12f8
9857ed7
e8c0415
730a5c9
50761fa
121d646
33629c6
fde6928
c7e17a0
52fdada
c21c826
9aee276
fd939f3
0c88600
0caa8d2
7dc1ac4
267e930
06f0d96
4d64cbf
4adb167
34b9e07
e81cd7e
ae1eff4
58eb45c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,8 @@ | |
"releaseDemo": "./scripts/release/releaseDemo.sh", | ||
"releaseDocs": "./scripts/release/releaseDocs.sh", | ||
"releaseEslint": "./scripts/release/releaseEslint.sh", | ||
"releaseNative": "./scripts/release/releaseNative.sh" | ||
"releaseNative": "./scripts/release/releaseNative.sh", | ||
"update-web-assets": "node scripts/assets/extract-dimensions.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateWebAssets - let's follow the other scripts' naming convention |
||
}, | ||
"dependencies": { | ||
"babel-plugin-transform-inline-environment-variables": "^0.0.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const fs = require('fs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename the file to |
||
const path = require('path'); | ||
const mime = require('mime-types'); | ||
const {imageSize: sizeOf} = require('image-size'); | ||
|
||
// Base paths | ||
const ICONS_PATH = path.resolve(__dirname, '../../src/assets/internal/icons'); | ||
const IMAGES_PATH = path.resolve(__dirname, '../../src/assets/internal/images'); | ||
|
||
// Function to check if file is an image | ||
function isImageFile(filePath) { | ||
const mimeType = mime.lookup(filePath); | ||
return !!mimeType && mimeType.includes('image'); | ||
} | ||
|
||
// Function to get dimensions of an image | ||
function getDimensions(imagePath) { | ||
try { | ||
if (!isImageFile(imagePath)) { | ||
console.warn(`File is not an image: ${imagePath}`); | ||
return {width: 0, height: 0}; | ||
} | ||
|
||
try { | ||
const buffer = fs.readFileSync(imagePath); | ||
const dimensions = sizeOf(buffer); | ||
return { | ||
width: dimensions.width, | ||
height: dimensions.height | ||
}; | ||
} catch (sizeError) { | ||
console.log(`Error getting dimensions for ${imagePath}:`, sizeError); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd put this as error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed, added |
||
// Default dimensions if sizeOf fails | ||
return {width: 24, height: 24}; | ||
} | ||
} catch (error) { | ||
console.log(`Error getting dimensions for ${imagePath}:`, error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be error |
||
return {width: 0, height: 0}; | ||
} | ||
} | ||
|
||
// Function to create index files with dimensions | ||
function createIndexFile(sourcePath, targetPath, fileType) { | ||
const files = fs.readdirSync(sourcePath).filter(file => !file.includes('@') && !file.startsWith('.')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this is Devin script. |
||
|
||
let content = ''; | ||
|
||
if (fileType === 'icons') { | ||
content = 'export const icons = {\n'; | ||
} else if (fileType === 'images') { | ||
content = 'export const images = {\n'; | ||
} | ||
|
||
files.forEach((file, index) => { | ||
const filePath = path.join(sourcePath, file); | ||
const mimeType = mime.lookup(filePath); | ||
const isImage = !!mimeType && mimeType.includes('image'); | ||
|
||
if (!isImage) { | ||
console.warn(`Skipping non-image file: ${filePath}`); | ||
return; | ||
} | ||
|
||
const name = path.basename(file, path.extname(file)); | ||
const dimensions = getDimensions(filePath); | ||
|
||
// Handle hyphenated filenames by converting to camelCase | ||
const propertyName = name.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()); | ||
|
||
content += ` get ${propertyName}() {\n`; | ||
// eslint-disable-next-line max-len | ||
content += ` return {uri: require('./${file}').default, width: ${dimensions.width}, height: ${dimensions.height}};\n`; | ||
content += index === files.length - 1 ? ` }\n` : ` },\n`; // Conditional check for the last file | ||
}); | ||
|
||
content += '};\n'; | ||
|
||
fs.writeFileSync(targetPath, content); | ||
console.log(`Created ${targetPath}`); | ||
} | ||
|
||
// Create index files | ||
createIndexFile(ICONS_PATH, path.join(ICONS_PATH, 'index.web.js'), 'icons'); | ||
createIndexFile(IMAGES_PATH, path.join(IMAGES_PATH, 'index.web.js'), 'images'); | ||
|
||
console.log('Index files created successfully!'); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import {Assets} from './Assets'; | ||
|
||
export default new Assets().loadAssetsGroup('', { | ||
get icons() { | ||
return require('./icons').icons; | ||
}, | ||
get emojis() { | ||
return require('./emojis').emojis; | ||
}, | ||
get images() { | ||
return require('./images').images; | ||
get internal() { | ||
return require('./internal').internal; | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export const icons = { | ||
get check() { | ||
return require('./check.png'); | ||
}, | ||
get checkMarkSmall() { | ||
return require('./checkMarkSmall.png'); | ||
}, | ||
get checkSmall() { | ||
return require('./checkSmall.png'); | ||
}, | ||
get chevronDown() { | ||
return require('./chevronDown.png'); | ||
}, | ||
get exclamationSmall() { | ||
return require('./exclamationSmall.png'); | ||
}, | ||
get minusOutline() { | ||
return require('./minusOutline.png'); | ||
}, | ||
get minusOutlineSmall() { | ||
return require('./minusOutlineSmall.png'); | ||
}, | ||
get minusSmall() { | ||
return require('./minusSmall.png'); | ||
}, | ||
get plusOutline() { | ||
return require('./plusOutline.png'); | ||
}, | ||
get plusOutlineSmall() { | ||
return require('./plusOutlineSmall.png'); | ||
}, | ||
get plusSmall() { | ||
return require('./plusSmall.png'); | ||
}, | ||
get search() { | ||
return require('./search.png'); | ||
}, | ||
get x() { | ||
return require('./x.png'); | ||
}, | ||
get xFlat() { | ||
return require('./xFlat.png'); | ||
}, | ||
get xMedium() { | ||
return require('./xMedium.png'); | ||
}, | ||
get xSmall() { | ||
return require('./xSmall.png'); | ||
} | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.