Skip to content
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

WIP : #258 #666

Merged
merged 7 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"cmd.otherOptions.preserve.prompt": "例 : 'http.proxy' => このコンピュータのプロキシを保存して, それで上書きします. 空の場合プロキシを削除します.",
"cmd.otherOptions.preserve.info.done1": "Sync : 終了します. {0} の値はダウンロード後 settings.json から削除されます.",
"cmd.otherOptions.preserve.info.done2": "Sync : 終了します. ダウンロード後に {0} : {1} で settings.json に保持します.",
"cmd.otherOptions.customizedSync": "Sync: カスタム同期",
"cmd.otherOptions.customizedSync.placeholder": "追加でアップロードするファイルの絶対パスを入力してください.",
"cmd.otherOptions.customizedSync.prompt": "(ex. /path/to/.eslint) はアップロードされ, 指定したパスにダウンロードされます.",
"cmd.otherOptions.customizedSync.done": "Sync : {0} を登録しました.",
"cmd.otherOptions.joinCommunity": "Sync : コミュニティに参加する",
"cmd.otherOptions.openIssue": "Sync : Issue を作成する",
"cmd.otherOptions.releaseNotes": "Sync : リリースノート",
Expand Down
4 changes: 4 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"cmd.otherOptions.preserve.prompt": "Example : Write 'http.proxy' => store this computer proxy and overwrite it , if set empty it will remove proxy.",
"cmd.otherOptions.preserve.info.done1": "Sync : Done. {0} value will be removed from settings.json after downloading.",
"cmd.otherOptions.preserve.info.done2": "Sync : Done. Extension will keep {0} : {1} in setting.json after downloading.",
"cmd.otherOptions.customizedSync": "Sync: Customized Sync",
"cmd.otherOptions.customizedSync.placeholder": "Enter an absolute path of the additional uploaded file.",
"cmd.otherOptions.customizedSync.prompt": "(ex. /path/to/.eslint) will be uploaded and downloaded to the specified path.",
"cmd.otherOptions.customizedSync.done": "Sync : {0} has been registered.",
"cmd.otherOptions.joinCommunity": "Sync : Join Community",
"cmd.otherOptions.openIssue": "Sync : Open Issue",
"cmd.otherOptions.releaseNotes": "Sync : Release Notes",
Expand Down
41 changes: 41 additions & 0 deletions src/service/fileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class File {
) {}
}
export class FileService {
public static CUSTOMIZED_SYNC_PREFIX = "|customized_sync|";

public static async ReadFile(filePath: string): Promise<string> {
try {
const data = await fs.readFile(filePath, { encoding: "utf8" });
Expand Down Expand Up @@ -193,4 +195,43 @@ export class FileService {
throw err;
}
}

Copy link
Author

Choose a reason for hiding this comment

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

add some util methods

public static async GetCustomFile(
filePath: string,
fileName: string
): Promise<File> {
const fileExists: boolean = await FileService.FileExists(filePath);

if (!fileExists) {
return null;
}

const content = await FileService.ReadFile(filePath);

if (content === null) {
return null;
}

// for identifing Customized Sync file
const gistName: string = FileService.CUSTOMIZED_SYNC_PREFIX + fileName;

const file: File = new File(fileName, content, filePath, gistName);
return file;
}

public static async CreateCustomDirTree(filePath: string): Promise<string> {
const dir = path.dirname(filePath);
const fileExists = await FileService.FileExists(dir);

if (!fileExists) {
// mkdir recursively
await fs.mkdirs(dir);
}

return filePath;
}

public static ExtractFileName(fullPath: string): string {
return path.basename(fullPath);
}
}
1 change: 1 addition & 0 deletions src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export class CustomSettings {
public lastDownload: Date = null;
public githubEnterpriseUrl: string = null;
public askGistName: boolean = false;
public customFiles: { [key: string]: string } = {};
}
69 changes: 62 additions & 7 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ export class Sync {
return matchedFolders.length > 0;
});
}
const customFileKeys: string[] = Object.keys(
Copy link
Author

Choose a reason for hiding this comment

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

upload additional files

customSettings.customFiles
);
if (customFileKeys.length > 0) {
for (const key of customFileKeys) {
const val = customSettings.customFiles[key];
const customFile: File = await FileService.GetCustomFile(val, key);
if (customFile !== null) {
allSettingFiles.push(customFile);
}
}
}
} else {
Commons.LogException(null, common.ERROR_MESSAGE, true);
return;
Expand Down Expand Up @@ -437,7 +449,21 @@ export class Sync {
keys.forEach(gistName => {
if (res.data.files[gistName]) {
if (res.data.files[gistName].content) {
if (gistName.indexOf(".") > -1) {
const prefix = FileService.CUSTOMIZED_SYNC_PREFIX;
Copy link
Author

Choose a reason for hiding this comment

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

download additional files

if (gistName.indexOf(prefix) > -1) {
const fileName = gistName.split(prefix).join(""); // |customized_sync|.htmlhintrc => .htmlhintrc
if (!(fileName in customSettings.customFiles)) {
// syncLocalSettings.json > customFiles doesn't have key
return;
Copy link
Author

Choose a reason for hiding this comment

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

skip download if does not set download path.

}
const f: File = new File(
fileName,
res.data.files[gistName].content,
customSettings.customFiles[fileName],
gistName
);
updatedFiles.push(f);
} else if (gistName.indexOf(".") > -1) {
if (
env.OsType === OsType.Mac &&
gistName === env.FILE_KEYBINDING_DEFAULT
Expand Down Expand Up @@ -559,10 +585,15 @@ export class Sync {
if (file.gistName === env.FILE_KEYBINDING_MAC) {
file.fileName = env.FILE_KEYBINDING_DEFAULT;
}
const filePath: string = await FileService.CreateDirTree(
env.USER_FOLDER,
file.fileName
);
let filePath: string = "";
if (file.filePath !== null) {
filePath = await FileService.CreateCustomDirTree(file.filePath);
} else {
filePath = await FileService.CreateDirTree(
env.USER_FOLDER,
file.fileName
);
}

actionList.push(
FileService.WriteFile(filePath, content)
Expand Down Expand Up @@ -699,6 +730,7 @@ export class Sync {
"cmd.otherOptions.toggleAutoDownload",
"cmd.otherOptions.toggleSummaryPage",
"cmd.otherOptions.preserve",
"cmd.otherOptions.customizedSync",
Copy link
Author

Choose a reason for hiding this comment

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

create new advanced option

"cmd.otherOptions.joinCommunity",
"cmd.otherOptions.openIssue",
"cmd.otherOptions.releaseNotes"
Expand Down Expand Up @@ -817,22 +849,45 @@ export class Sync {
}
},
8: async () => {
// add customized sync file
const options: vscode.InputBoxOptions = {
ignoreFocusOut: true,
placeHolder: localize("cmd.otherOptions.customizedSync.placeholder"),
prompt: localize("cmd.otherOptions.customizedSync.prompt")
};
const input = await vscode.window.showInputBox(options);

if (input) {
const fileName: string = FileService.ExtractFileName(input);
if (fileName === "") {
return;
}
customSettings.customFiles[fileName] = input;
const done: boolean = await common.SetCustomSettings(customSettings);
if (done) {
vscode.window.showInformationMessage(
localize("cmd.otherOptions.customizedSync.done", fileName)
);
}
}
},
9: async () => {
Copy link
Author

Choose a reason for hiding this comment

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

download customized file from gist option

vscode.commands.executeCommand(
"vscode.open",
vscode.Uri.parse(
"https://join.slack.com/t/codesettingssync/shared_invite/enQtMzE3MjY5NTczNDMwLTYwMTIwNGExOGE2MTJkZWU0OTU5MmI3ZTc4N2JkZjhjMzY1OTk5OGExZjkwMDMzMDU4ZTBlYjk5MGQwZmMyNzk"
)
);
},
9: async () => {
10: async () => {
vscode.commands.executeCommand(
"vscode.open",
vscode.Uri.parse(
"https://github.com/shanalikhan/code-settings-sync/issues/new"
)
);
},
10: async () => {
11: async () => {
vscode.commands.executeCommand(
"vscode.open",
vscode.Uri.parse(
Expand Down