Skip to content

Commit

Permalink
change: read vscode settings to get to format
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeEagle committed Jan 17, 2020
1 parent 88620e8 commit 257fc24
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "flr" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
## [0.0.7]

- Initial release
- read vscode settings to get `dart.lineLength` to format `r.g.dart`

## [0.0.6]

- Initial release
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "flr",
"displayName": "FLR",
"description": "Flutter Resources Manager",
"version": "0.0.6",
"version": "0.0.7",
"repository": "https://github.com/Fly-Mix/flr-vscode-extension",
"engines": {
"vscode": "^1.41.0"
Expand Down
28 changes: 27 additions & 1 deletion src/resource-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from "fs";
import * as yaml from "js-yaml";
import * as flrPathMan from "./folder-manager";
import * as utils from "./utils";
const os = require("os");

export class ResourceGenerator {
static namePool: string[] = new Array();
Expand Down Expand Up @@ -161,7 +162,32 @@ export class ResourceGenerator {
content += textBlock;

fs.writeFileSync(file, content);
utils.execute(`dartfmt -l 100 -w ${file}`);

/// read line length settings for dart and format
let platform = process.platform;
var settingFilePath = "";
let settingFile = "Code/User/settings.json";
/// https://vscode.readthedocs.io/en/latest/getstarted/settings/
if (platform === "win32" && process.env.APPDATA !== undefined) {
// windows
settingFilePath = path.join(process.env.APPDATA, settingFile);
} else if (platform === "darwin") {
// macOS
settingFilePath = `${os.homedir()}/Library/Application Support/${settingFile}`;
} else {
// linux
settingFilePath = `${os.homedir()}/.config/${settingFile}`;
}

let settings = fs.readFileSync(settingFilePath, "utf8");
let json = JSON.parse(settings);
let ll = json["dart.lineLength"];
var lineLength = 80;
if (ll !== null && ll !== undefined) {
lineLength = parseInt(ll);
}

utils.execute(`flutter format -l ${lineLength} ${file}`);
} catch (e) {
console.log(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export async function execute(command: string): Promise<string> {
export enum Names {
generatedFileName = "r.g.dart",
flr = "flr",
pubspec = "pubspec.yaml"
pubspec = "pubspec.yaml",
settings = "settings.json"
}

export enum Commands {
Expand Down

0 comments on commit 257fc24

Please sign in to comment.