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] Convert to TypeScript #31

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,35 @@ Where the contents of the array is a list of packages to ensure are installed.

No keybindings are configured by default for the commands in this package.

## Notes

There are two primary use cases for this package:

1. Ensure minimum set of packages installed
* Atom is allowed to have packages installed that are not in the list
* Package list is auto-generated once and then mostly manually updated
1. Ensure that the list of installed packages is kept completely in sync
* Must install any missing packages
* Must remove any extra packages
* Package list is auto-updated when packages are installed or removed

package-sync was originally intended to only satisfy the first scenario. It has since been pressed into service for the second scenario.

### Minimum set of packages

Operations:

* Create package list from installed packages
* Edit package list by hand
* Ensure all packages in list are installed by syncing

### Synchronize packages

Operations:

* Automated updating of package list
* Ensure all packages are in sync by triggering sync

## Copyright

Copyright © 2014-2016 by [Lee Dohm](http://www.lee-dohm.com), [Lifted Studios](http://www.liftedstudios.com). See the [LICENSE](https://github.com/lee-dohm/package-sync/blob/master/LICENSE.md) for more details.
114 changes: 0 additions & 114 deletions coffeelint.json

This file was deleted.

31 changes: 31 additions & 0 deletions lib/busy-signal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
declare module 'busy-signal' {
export interface BusyMessage {
/**
* Clears the busy message.
*/
dispose(): void

/**
* Sets the title of the busy message.
*/
setTitle(title: string): void
}

export interface BusySignalOptions {
/**
* If set to `true`, the busy signal tooltip will be immediately revealed
* when it first becomes visible (without explicit mouse interaction).
*/
revealTooltip?: boolean
}

export interface BusySignalService {
/**
* Activates the busy signal.
*
* The title can be updated in the returned `BusyMessage` object and the signal can be
* deactivated by calling `dispose` on the `BusyMessage` object.
*/
reportBusy(title: string, options?: BusySignalOptions): BusyMessage
}
}
44 changes: 0 additions & 44 deletions lib/index.coffee

This file was deleted.

65 changes: 65 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// <reference path="./busy-signal" />

import {CompositeDisposable} from 'atom'
import {BusySignalService} from 'busy-signal'

import PackageSync from './package-sync'

let busySignal: BusySignalService
let disposable: CompositeDisposable
let packageSync: PackageSync

function loadModule(): void {
if (!packageSync) {
packageSync = new PackageSync()
}
}

/**
* Activates the package.
*/
export function activate(): void {
disposable = new CompositeDisposable()

disposable.add(atom.commands.add('atom-workspace', 'package-sync:create-package-list', () => {
loadModule()
packageSync.createPackageList()
}))

disposable.add(atom.commands.add('atom-workspace', 'package-sync:open-package-list', () => {
loadModule()
packageSync.openPackageList()
}))

disposable.add(atom.commands.add('atom-workspace', 'package-sync:sync', () => {
loadModule()
packageSync.sync(busySignal)
}))

disposable.add(atom.packages.onDidActivateInitialPackages(() => {
disposable.add(atom.packages.onDidLoadPackage(() => {
if (atom.config.get('package-sync.createOnChange')) {
loadModule()
packageSync.createPackageList()
}
}))

disposable.add(atom.packages.onDidUnloadPackage(() => {
if (atom.config.get('package-sync.createOnChange')) {
loadModule()
packageSync.createPackageList()
}
}))
}))
}

export function consumeBusySignal(busySignalService: BusySignalService): void {
busySignal = busySignalService
}

/**
* Deactivates the package.
*/
export function deactivate(): void {
disposable.dispose()
}
33 changes: 0 additions & 33 deletions lib/package-list.coffee

This file was deleted.

53 changes: 53 additions & 0 deletions lib/package-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as CSON from 'season'
import * as fs from 'fs'
import * as path from 'path'

/**
* Information that gets stored in the `packages.cson` file.
*/
interface PackagesFile {
readonly packages: string[]
}

/**
* Represents the stored package list.
*/
export default class PackageList {
private path: string

public constructor(configDir = atom.getConfigDirPath()) {
this.path = path.join(configDir, 'packages.cson')
}

/**
* Gets the packages from the list.
*/
public getPackages(): string[] {
if (fs.existsSync(this.path)) {
let obj = CSON.readFileSync(this.path) as PackagesFile
return obj.packages
}

return []
}

/**
* Get the path where the list is stored.
*/
public getPath(): string {
return this.path
}

/**
* Updates the stored package list with what is currently installed if the list doesn't exist or
* the `forceOverwrite` configuration option is set to `true`.
*/
public setPackages(): void {
if (atom.config.get('package-sync.forceOverwrite') || !fs.existsSync(this.path)) {
let available = atom.packages.getAvailablePackageNames()
let names = available.filter((name: string) => { return !atom.packages.isBundledPackage(name) })

CSON.writeFileSync(this.path, {packages: names})
}
}
}
Loading