Skip to content

Commit 647311e

Browse files
committed
initial commit
0 parents  commit 647311e

15 files changed

+5024
-0
lines changed

.eslintrc.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"commonjs": true,
5+
"es6": true,
6+
"node": true,
7+
"mocha": true
8+
},
9+
"parserOptions": {
10+
"ecmaVersion": 2018,
11+
"ecmaFeatures": {
12+
"jsx": true
13+
},
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"no-const-assign": "warn",
18+
"no-this-before-super": "warn",
19+
"no-undef": "warn",
20+
"no-unreachable": "warn",
21+
"no-unused-vars": "warn",
22+
"constructor-super": "warn",
23+
"valid-typeof": "warn"
24+
}
25+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.vscode-test/
3+
*.vsix

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint"
6+
]
7+
}

.vscode/launch.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
]
15+
},
16+
{
17+
"name": "Extension Tests",
18+
"type": "extensionHost",
19+
"request": "launch",
20+
"args": [
21+
"--extensionDevelopmentPath=${workspaceFolder}",
22+
"--extensionTestsPath=${workspaceFolder}/test/suite/index"
23+
]
24+
}
25+
]
26+
}

.vscodeignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode/**
2+
.vscode-test/**
3+
test/**
4+
.gitignore
5+
.yarnrc
6+
vsc-extension-quickstart.md
7+
**/jsconfig.json
8+
**/*.map
9+
**/.eslintrc.json

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## v0.0.1 (2021-11-24)
2+
3+
- Initial release

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Flutter Image Asset Generator
2+
3+
A simple [Visual Studio Code](https://code.visualstudio.com/) extension which helps you generate your image assets in 1x, 2x, and 3x and simply added them to your pubspec.yaml file.
4+
5+
## Usage
6+
7+
After installing the extension, you should see a new option has been added yo your context menu when you right click on any folder inside the `Explorer` section named `Flutter Image Assets: Generate`:
8+
9+
<p align='center'>
10+
<img
11+
src='https://github.com/devmuaz/flutter-image-assets/blob/master/assets/preview.png?raw=true'
12+
title='Flutter Image Assets Preview'
13+
alt='Flutter Image Assets Preview'
14+
/>
15+
</p>
16+
17+
Click on it and select the image you want to add.. after that, the selected image will be scaled down to 1x, 2x, and 3x in seprated directories.
18+
19+
<p align='center'>
20+
<img
21+
src='https://github.com/devmuaz/flutter-image-assets/blob/master/assets/preview2.png?raw=true'
22+
title='Flutter Image Assets Preview'
23+
alt='Flutter Image Assets Preview'
24+
/>
25+
</p>
26+
27+
## Known Issues
28+
29+
Currently, this extension only generates the scaled images.. but not adding them to the `pubspec.yaml` file so you have to add them yourself.. and it will be added soon as possible.
30+
31+
## Medium articles by the author
32+
33+
You can always read the articles I write on my [devmuaz](https://devmuaz.medium.com/) medium account which I write pretty great Flutter content out there.
34+
35+
## Contributions & Support
36+
37+
Issues and pull requests are always welcome 😄
38+
39+
If you found this extension useful for you and liked it, please star the repo ⭐️ it would mean a lot!
40+
41+
## License
42+
43+
**MIT**
44+
45+
**Enjoy!**

assets/icon.png

18.8 KB
Loading

assets/preview.png

682 KB
Loading

assets/preview2.png

548 KB
Loading

extension.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const vscode = require('vscode');
2+
const fileSystem = require('fs');
3+
const imageUtils = require('./src/image_utils');
4+
5+
/**
6+
* @param {vscode.ExtensionContext} context
7+
*/
8+
const activate = (context) => {
9+
10+
const command = 'flutter-image-assets.generate';
11+
const commandHandler = async (args) => {
12+
const destinationPath = getDestinationPath(args);
13+
14+
if (destinationPath) {
15+
const imagePath = await getImagePath();
16+
17+
// generating images for (1x, 2x, and 3x)
18+
for (let mode = 1; mode < 4; mode++) {
19+
imageUtils.scaleImageToMode(destinationPath, imagePath, mode);
20+
}
21+
}
22+
}
23+
24+
context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));
25+
}
26+
27+
/**
28+
* @param {string} args
29+
*/
30+
const getDestinationPath = (args) => {
31+
if (args) {
32+
const uri = vscode.Uri.parse(args);
33+
const path = uri.fsPath;
34+
const exists = fileSystem.existsSync(path);
35+
const isDirectoryAndExists = exists ? isDirectory(path) : false;
36+
37+
if (isDirectoryAndExists) {
38+
return path;
39+
} else {
40+
vscode.window.showErrorMessage(`The '${path}' isn't a directory.`);
41+
}
42+
} else {
43+
vscode.window.showErrorMessage(`Can't run the command without a destination directory.`);
44+
}
45+
}
46+
/**
47+
*
48+
* @returns The path of the image file that where selected through the vscode open dialog
49+
*/
50+
const getImagePath = async () => {
51+
const options = {
52+
canSelectMany: false,
53+
openLabel: 'Select Image',
54+
filters: { 'Images': ['png', 'jpg', 'jpeg', 'JPG', 'JPEG'] }
55+
};
56+
57+
const uri = await vscode.window.showOpenDialog(options);
58+
if (uri && uri[0]) {
59+
return uri[0].fsPath;
60+
}
61+
}
62+
63+
/**
64+
* @param {string} path
65+
*/
66+
const isDirectory = (path) => {
67+
try {
68+
return fileSystem.lstatSync(path).isDirectory();
69+
} catch (e) {
70+
return false;
71+
}
72+
}
73+
74+
// this method is called when your extension is deactivated
75+
const deactivate = () => { }
76+
77+
module.exports = {
78+
activate,
79+
deactivate
80+
}

jsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "ES2020",
5+
"checkJs": true, /* Typecheck .js files. */
6+
"lib": [
7+
"ES2020"
8+
]
9+
},
10+
"exclude": [
11+
"node_modules"
12+
]
13+
}

0 commit comments

Comments
 (0)