forked from mark-hahn/atom-git-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-projects.coffee
121 lines (103 loc) · 3.53 KB
/
git-projects.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
fs = require 'fs-plus'
path = require 'path'
{Task} = require 'atom'
# defer these until used
utils = null
Project = null
ProjectsListView = null
FindGitReposTask = null
module.exports =
config:
rootPath:
title: "Root paths"
description: "Paths to folders containing Git repositories, separated by semicolons."
type: "string"
default: fs.absolute(fs.getHomeDirectory() + "#{path.sep}repos")
ignoredPath:
title: "Ignored paths"
description: "Paths to folders that should be ignored, separated by semicolons."
type: "string"
default: ""
ignoredPatterns:
title: "Ignored patterns"
description: "Patterns that should be ignored (e.g.: node_modules), separated by semicolons."
type: "string"
default: "node_modules;\\.git"
sortBy:
title: "Sort by"
type: "string"
default: "Project name"
enum: ["Project name", "Latest modification date", "Size"]
maxDepth:
title: "Max Folder Depth"
type: 'integer'
default: 5
minimum: 1
openInDevMode:
title: "Open in development mode"
type: "boolean"
default: false
notificationsEnabled:
title: "Notifications enabled"
type: "boolean"
default: true
showGitInfo:
title: "Show repositories status"
description: "Display the branch and a status icon in the list of projects"
type: "boolean"
default: true
projects: null
view: null
activate: (state) ->
if state.projectsCache?
utils ?= require './utils'
Project ?= require './models/project'
filter = (project) -> utils.isRepositorySync(project.path)
map = (project) -> Project.deserialize(project)
@projects = state.projectsCache.filter(filter).map(map)
atom.commands.add 'atom-workspace',
'git-projects:toggle': =>
@createView().toggle(@)
atom.commands.add 'atom-workspace',
'git-projects:toggle-add': =>
@createView().toggle(@, 'add')
serialize: ->
projectsCache: @projects
# Opens a project. Supports for dev mode via package settings
#
# project - The {Project} to open.
openProject: (project) ->
atom.open options =
pathsToOpen: [project.path]
devMode: atom.config.get('git-projects.openInDevMode')
# Adds a project to the list of root paths.
#
# project - The {Project} to add.
addProject: (project) ->
atom.project.addPath project.path
# Creates an instance of the list view
createView: ->
ProjectsListView ?= require './views/projects-list-view'
@view ?= new ProjectsListView()
# Finds all the git repositories recursively from the given root path(s)
#
# root - {String} the path to search from
findGitRepos: (root = atom.config.get('git-projects.rootPath'), cb) ->
utils ?= require './utils'
Project ?= require './models/project'
FindGitReposTask ?= require.resolve './find-git-repos-task'
rootPaths = utils.parsePathString(root)
return cb(@projects) unless rootPaths?
# The task doesn't have the `atom` global
config = {
maxDepth: atom.config.get('git-projects.maxDepth')
sortBy: atom.config.get('git-projects.sortBy')
ignoredPath: atom.config.get('git-projects.ignoredPath')
ignoredPatterns: atom.config.get('git-projects.ignoredPatterns')
}
task = Task.once FindGitReposTask, root, config, =>
cb(@projects)
task.on 'found-repos', (data) =>
# The projects emitted from the task must be deserialized first
@projects = data.map (project) ->
Project.deserialize(project)