Skip to content

Commit

Permalink
add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Jan 23, 2024
1 parent 5e4a143 commit a8742b8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 14 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

All notable changes to the extension will be documented in this file.

## [1.0.10] - 2024-02-
## [1.0.10] - 2024-02-23

- Add file progress for long running archives

## [1.0.9] - 2024-01-21

- Option to exclude `.git` folders
- Add workspace settings for archive path and option to exclude `.git` folders

## [1.0.5] - 2024-01-17

Expand Down
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@
"multi-root ready"
],
"contributes": {
"configuration": {
"title": "Archiver",
"properties": {
"archiver.outputPath": {
"type": "string",
"scope": "resource",
"description": "Relative or absolute path to archived files.",
"default": ""
},
"archiver.includeGitFolders": {
"type": "string",
"scope": "resource",
"description": "Whether to include .git folders in archive.",
"default": "Ask",
"enum": [
"Ask",
"Yes",
"No"
]
}
}
},
"commands": [
{
"command": "vscode-archiver.archive",
Expand Down
35 changes: 26 additions & 9 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import archiver from "archiver";
import walk from "ignore-walk";
import { ProgressLocation, window } from "vscode";
import { createWriteStream } from "fs";
import {
IncludeGitFoldersType,
getIncludeGitFolders,
getOutputPath,
} from "./settings";

export async function archive() {
const folder = await window.showWorkspaceFolderPick();
Expand All @@ -25,23 +30,35 @@ export async function archive() {
ignoreFiles: [".gitignore"],
});

const git = files.find((file) => file.includes(".git/"));
let type = getIncludeGitFolders(folder);

if (git) {
const picked = await window.showQuickPick(["Yes", "No"], {
title: "Include .git folders?",
placeHolder: "Yes",
});
if (type === IncludeGitFoldersType.ASK) {
const git = files.find((file) => file.includes(".git/"));

if (picked === "No") {
files = files.filter((file) => !file.includes(".git/"));
if (git) {
const picked = await window.showQuickPick(["Yes", "No"], {
title: "Include .git folders?",
placeHolder: "Yes",
});

if (picked === "No") {
type = IncludeGitFoldersType.NO;
}
}
}

if (type === IncludeGitFoldersType.NO) {
files = files.filter((file) => !file.includes(".git/"));
}

const name = folder.name;
const date = new Date();
const arch = `${name}_${date.toISOString().replace(/[:.Z]/g, "")}.zip`;
const dest = path.join(root, arch);
const outputPath = getOutputPath(folder);

const dest = path.isAbsolute(outputPath)
? path.join(outputPath, arch)
: path.join(root, outputPath, arch);

await window.withProgress(
{
Expand Down
26 changes: 26 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 1986-2024 Ecmel Ercan (https://ecmel.dev/)
* Licensed under the MIT License
*/

import { ConfigurationScope, workspace } from "vscode";

export function getOutputPath(scope: ConfigurationScope): string {
return workspace
.getConfiguration("archiver", scope)
.get<string>("outputPath", "");
}

export const enum IncludeGitFoldersType {
ASK = "Ask",
YES = "Yes",
NO = "No",
}

export function getIncludeGitFolders(
scope: ConfigurationScope
): IncludeGitFoldersType {
return workspace
.getConfiguration("archiver", scope)
.get<IncludeGitFoldersType>("includeGitFolders", IncludeGitFoldersType.ASK);
}

0 comments on commit a8742b8

Please sign in to comment.