Skip to content

Commit

Permalink
Release v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeboer committed Apr 5, 2020
2 parents d87824c + cab88f9 commit 986476f
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 184 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
npm-debug.log
yarn-error.log
yalc.lock
.idea/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/dubnium
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ Simple workflow that allows you to browse and open [Atom](https://atom.io/) proj

## Requirements

- NodeJS 8+
- NodeJS 10+
- [Atom Project Manager package](https://atom.io/packages/project-manager)
- Alfred 4 with paid [Alfred Powerpack](https://www.alfredapp.com/powerpack)

## Installation

### NPM (preferred)
### Yarn / NPM (preferred)

This workflow can be installed with NPM, as an added bonus you'll get a notification when an update is available!
This workflow can be installed with Yarn or NPM, as an added bonus you'll get a notification when an update is available!

```shell
yarn add -g alfred-atom
# or
npm install -g alfred-atom
```

Expand All @@ -24,7 +26,7 @@ Because some dependencies are quite big you have to run `npm install` yourself a

1. Download the latest `Atom.alfredworkflow` from [Packal](http://www.packal.org/workflow/atom) or [GitHub](https://github.com/Cloudstek/alfred-atom/releases) and import it in Alfred.
2. Open Alfred and go to Workflows. Right-click on Atom and click on *"Open in Terminal"*
3. In the terminal, enter `npm install`
3. In the terminal, enter `yarn` or `npm install`.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Simply type atom and press space to list all projects. Optionally type a search
<string>terminalApp</string>
</array>
<key>version</key>
<string>3.0.4</string>
<string>4.0.0</string>
<key>webaddress</key>
<string>https://github.com/Cloudstek/alfred-atom</string>
</dict>
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alfred-atom",
"version": "3.0.4",
"version": "4.0.0",
"repository": "Cloudstek/alfred-atom",
"author": "Maarten de Boer <[email protected]> (https://cloudstek.nl)",
"license": "BSD-2-Clause",
Expand All @@ -23,14 +23,14 @@
],
"dependencies": {
"@primer/octicons": "^9.3.1",
"alfred-hugo": "^2.0.5",
"alfred-hugo": "^3.0.1",
"change-case": "^4.1.1",
"color": "^3.1.2",
"cson-parser": "^4.0.3",
"fs-extra": "^8.1.0",
"fs-extra": "^9.0.0",
"glob": "^7.1.6",
"moment": "^2.24.0",
"sharp": "^0.24.0",
"sharp": "^0.25.2",
"untildify": "^4.0.0"
},
"devDependencies": {
Expand All @@ -44,7 +44,7 @@
"typescript": "^3.7.2"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"clean": "del-cli dist*",
Expand Down
22 changes: 13 additions & 9 deletions src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fs from "fs-extra";
import path from "path";
import color from "color";
import sharp from "sharp";
import { Item } from "alfred-hugo";
import {Item} from "alfred-hugo";

import { IconsRebuildOptions, Octicon } from "./types";
import {IconsRebuildOptions, Octicon} from "./types";

export class Icons {
public static all() {
Expand Down Expand Up @@ -87,20 +87,24 @@ export class Icons {
}

// Create icons dir if not exists
fs.ensureDir(path.join(__dirname, "icons"));
await fs.ensureDir(path.join(__dirname, "icons"));

for (const [name, icon] of icons) {
// console.log(iconSize, iconColor.rgb().toString());
let sharpTasks: Promise<sharp.OutputInfo>[];

for (const [name, icon] of icons) {
// Add fill to SVG path
const svgPath = icon.path.replace(/\/\>$/, ` fill="${iconColor.rgb().toString()}" />`);
const svgPath = icon.path.replace(/\/>$/, ` fill="${iconColor.rgb().toString()}" />`);

// Build SVG
const svg = `<svg viewBox="0 0 ${icon.width} ${icon.height}" width="${iconSize}" height="${iconSize}" xmlns="http://www.w3.org/2000/svg">${svgPath}</svg>`;

sharp(Buffer.from(svg))
.png()
.toFile(path.join(iconPath, `${name}.png`));
sharpTasks.push(
sharp(Buffer.from(svg))
.png()
.toFile(path.join(iconPath, `${name}.png`))
);
}

await Promise.all(sharpTasks);
}
}
15 changes: 6 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import cson from "cson-parser";
import untildify from "untildify";
import { Hugo, Item } from "alfred-hugo";
import {Hugo, Item} from "alfred-hugo";

import { Icons } from "./icons";
import {Icons} from "./icons";
import * as utils from "./utils";
import { Projects } from "./project";
import {Projects} from "./project";

const hugo = new Hugo({
checkUpdates: true,
updateNotification: false,
updateSource: "npm",
});

hugo.action("projects", () => {
hugo.action("projects", async () => {
// Projects file
const projectsFile = hugo.cacheFile(untildify("~/.atom/projects.cson"));
const configFile = hugo.cacheFile(untildify("~/.atom/config.cson"));
Expand All @@ -25,9 +25,6 @@ hugo.action("projects", () => {
// Parse projects
const p = Projects.parseCson(file);

// Rebuild icons when needed
Icons.rebuild(p, { onlyMissing: true, theme: hugo.alfredTheme });

// Sort projects
p.sort((a, b) => {
const nameA = a.title.toLowerCase();
Expand Down Expand Up @@ -92,7 +89,7 @@ hugo.action("projects", () => {
hugo.items = hugo.items.concat(projects);

// Check icons
utils.checkIcons(hugo, projects);
await utils.checkIcons(hugo, projects);

// Check if any projects found
if (hugo.items.length === 0) {
Expand All @@ -102,7 +99,7 @@ hugo.action("projects", () => {
}

// Output
hugo.feedback();
await hugo.feedback();
});

hugo.run();
14 changes: 6 additions & 8 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import cson from "cson-parser";
import { capitalCase } from "change-case";
import {capitalCase} from "change-case";
import path from "path";
import glob from "glob";
import { Item } from "alfred-hugo";
import {Item} from "alfred-hugo";

import { Project, Octicon } from "./types";
import {Octicon, Project} from "./types";
import * as utils from "./utils";
import { Icons } from "./icons";
import {Icons} from "./icons";

export class Projects {
/**
Expand All @@ -23,7 +23,7 @@ export class Projects {
octicons = Icons.all();
}

const item = {
return {
uid: Buffer.from(this.title(project) + this.subTitle(project), "utf8").toString("base64"),
title: this.title(project),
subtitle: this.subTitle(project),
Expand Down Expand Up @@ -60,8 +60,6 @@ export class Projects {
},
},
};

return item;
}

/**
Expand All @@ -75,7 +73,7 @@ export class Projects {
for (const project of projects) {
const p = this.parse(project, octicons);

if (p && p !== null) {
if (p) {
results.push(p);
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,33 @@ export function checkEnvironmentChanges(hugo: Hugo): void {
}
}

export function checkIcons(hugo: Hugo, items: Item[]): Promise<void> {
export async function checkIcons(hugo: Hugo, items: Item[]): Promise<void> {
const themePath = hugo.alfredMeta.themeFile;
const lastTheme = hugo.config.get("lastTheme");

try {
fs.statSync(path.join(__dirname, "icons"));
} catch (e) {
hugo.config.set("lastTheme", hugo.alfredMeta.theme);
Icons.rebuild(items, { theme: hugo.alfredTheme });
return;
return Icons.rebuild(items, { theme: hugo.alfredTheme });
}

if (!lastTheme || lastTheme !== hugo.alfredMeta.theme) {
hugo.config.set("lastTheme", hugo.alfredMeta.theme);
Icons.rebuild(items, { theme: hugo.alfredTheme });
return;
return Icons.rebuild(items, { theme: hugo.alfredTheme });
}

if (themePath) {
const themeFile = hugo.cacheFile(themePath);

themeFile.on("change", () => {
Icons.rebuild(items, { theme: hugo.alfredTheme });
await themeFile.on("change", async () => {
await Icons.rebuild(items, { theme: hugo.alfredTheme });
});

themeFile.get();
}

Icons.rebuild(items, { onlyMissing: true, theme: hugo.alfredTheme });
return Icons.rebuild(items, { onlyMissing: true, theme: hugo.alfredTheme });
}

export function fileExists(p: string): boolean {
Expand Down
Loading

0 comments on commit 986476f

Please sign in to comment.