-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
executable file
·148 lines (123 loc) · 4.57 KB
/
index.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env node
'use strict';
require('dotenv').config();
const program = require('commander');
const fs = require('fs');
const pjson = require('./package.json');
const env = require('./controller/env');
const init = require('./controller/init');
const github = require('./controller/github');
const install = require('./controller/install');
const npm = require('./controller/npm');
const test = require('./controller/test');
const submit = require('./controller/submit');
const publish = require('./controller/publish');
const shelve = require('./controller/shelve');
const uninstall = require('./controller/uninstall');
const janitor = require('./controller/janitor');
const pair = require('./controller/pair');
program
.version(pjson.version);
program
.command('login')
.description('Sets up authorizations for github.')
.action(init.login);
program
.command('auth')
.description('Obtain list of authorizations for github.')
.action(github.listAuths);
program
.command('logout')
.description('Will clear any local authorizations from the user\'s workspace. The user will be asked to authorize next time they trip the need.')
.action(github.deauthorizeUser);
program
.command('init-ws')
.description('To get up and running quickly, installs a completed version of the index.html and portfolio.html files of the Operation Spark website project.')
.action(init.website);
program
.command('init-pf')
.description('Initialize your portfolio.html with the JavaScript necessary to dynamically add portfolio projects as list items to the unordered-list with the id of portfolio.')
.action(initPortfolio);
program
.option('-t, --test', 'Keep test files')
.option('-m, --master', 'Keep master files')
.command('install')
.description('List installable projects.')
.action(install);
program
.command('npm')
.description('Selects a project to install npm packages to, then specifies whether one or all packages should be installed.')
.action(npm.install);
program
.command('start')
.description('Runs npm start script of selected project.')
.action(npm.start);
program
.command('test')
.description('Downloads tests for selected project and presents student with current results.')
.action(test.test);
program
.command('submit')
.description('Submits test results to Greenlight as student\'s grade.')
.action(submit.submit);
program
.command('publish [message]')
.description('Pushes all branches to the users GitHub pages repository at <username>.github.io by serially invoking:\ngit add -A\ngit commit -m"update website"\ngit push"\nOptional commit message defaults to "update website".')
.action(function (message) {
const commitMessage = message ? message : 'update website';
publish.all(commitMessage)
.then(function (result) {
console.log(result);
});
});
program
.command('shelve')
.description('Save previous work in a project in order to begin anew.')
.action(shelve);
program
.command('uninstall')
.description('Remove an installed project.')
.action(uninstall);
program
.command('fix')
.description('Reads the projects directory, reconciles the installed projects with the projects.json file, and removes any git or svn cruft from installed projects.')
.action(fix);
program
.option('-m, --master', 'Keep master files')
.command('pairup')
.description('Installs a project for pair programming. The workspace owner will be asked to provide the GitHub username of their partner.')
.action(pairup);
program
.command('pairdown')
.description('Downloads and installs a project from the GitHub Pages repository of the student with whom the using student paired. Will fail if project is already installed.')
.action(pairdown);
program.parse(process.argv);
// TODO : move to pair.js and call directly //
function pairup() {
pair.up(function (err) {
if (err) console.log(err);
});
}
// TODO : move to pair.js and call directly //
function pairdown() {
pair.down(function (err) {
if (err) console.log(err);
});
}
function initPortfolio() {
if (env.cloud9User) {
const githubDir = fs.readdirSync(`${env.home()}/environment`).filter(dir => /[\w]+\.github\.io/.test(dir))[0];
init.portfolio(`${env.home()}/environment/${githubDir}/portfolio.html`);
return;
} else if (env.codenvyUser) {
const githubDir = fs.readdirSync(`${env.codenvyUser}`).filter(dir => /[\w]+\.github\.io/.test(dir))[0];
init.portfolio(`${env.codenvyUser}/${githubDir}/portfolio.html`);
return;
}
init.portfolio();
}
function fix() {
janitor.fix(function (err) {
if (err) console.log(err);
});
}