forked from jsonresume/resume-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·183 lines (150 loc) · 6.04 KB
/
index.js
File metadata and controls
executable file
·183 lines (150 loc) · 6.04 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env node
var program = require('commander');
var fs = require('fs');
var lib = require('./lib');
var colors = require('colors');
var chalk = require('chalk');
var read = require('read');
var pkg = require('./package.json');
function readFileFunction(callback) {
var resumeJson = require('resume-schema').resumeJson;
var readFileErrors = null; // change this
if (fs.existsSync('./resume.json')) {
fs.readFile('./resume.json', {
encoding: 'utf8'
}, function(err, data) {
if (err) console.log(err);
try {
resumeJson = JSON.parse(data);
callback(resumeJson, null);
} catch (readFileErrors) {
callback(null, readFileErrors);
}
});
} else {
callback(null, null);
}
}
program
.version(pkg.version)
.option('-t, --theme <theme name>', 'Specify theme for export or publish (modern, traditional, crisp)', 'modern')
.option('-f, --force', 'Used by `publish` - bypasses schema testing.')
.option('-p, --port <port>', 'Used by `serve` (default: 4000)', 4000)
.option('-s, --silent', 'Used by `serve` to tell it if open browser auto or not.', false);
lib.version.checkConfigFile(null, function(message, LatestnpmVersion) {
if (message === 'out of date') {
console.log('Notice: You are currently using out-of-date version'.yellow, pkg.version, 'resume-cli.'.yellow);
console.log('Type'.cyan, '`sudo npm install -g resume-cli`', 'to upgrade to version'.cyan, LatestnpmVersion);
}
program
.command('init')
.description('Initialize a resume.json file')
.action(function() {
lib.init();
});
program
.command('test')
.description('Schema validation test your resume.json')
.action(function() {
if (!fs.existsSync('./resume.json')) {
console.log('There is no resume.json file located in this directory');
console.log('Type: `resume init` to initialize a new resume');
} else {
readFileFunction(function(resumeJson, readFileErrors) {
lib.test.validate(resumeJson, readFileErrors, function(error, response) {
error && console.log(response.message);
});
});
}
});
program
.command('export [fileName]')
.description('Export locally to .html, .md or .pdf')
.action(function(fileName) {
if (!fs.existsSync('./resume.json')) {
console.log('There is no resume.json file located in this directory');
console.log('Type: `resume init` to initialize a new resume');
} else {
readFileFunction(function(resumeJson, readFileErrors) {
lib.test.validate(resumeJson, readFileErrors, function(error, response) {
if (error) {
console.log(response.message);
} else {
lib.exportResume(resumeJson, fileName, program.theme, function(res, fileName) {
//do nothing
});
}
});
});
}
});
program
.command('serve')
.description('Serve resume at http://localhost:4000/')
.action(function() {
lib.serve(program.port, program.theme, program.silent);
});
program
.command('register')
.description('Register an account at https://registry.jsonresume.org')
.action(function() {
readFileFunction(function(resumeJson, readFileErrors) {
lib.register(resumeJson);
});
});
program
.command('publish')
.description('Publish your resume to https://registry.jsonresume.org')
.action(function() {
if (!fs.existsSync('./resume.json')) {
console.log('There is no resume.json file located in this directory'.yellow);
console.log('Type:'.cyan, 'resume init', 'to initialize a new resume'.cyan);
} else {
readFileFunction(function(resumeJson, readFileErrors) {
lib.test.validate(resumeJson, readFileErrors, function(error, response) {
if (error && !program.force) {
console.log(response.message);
} else {
lib.publish(resumeJson, program);
}
});
});
}
});
program
.command('settings')
.description('Not yet implemented')
.action(function() {
readFileFunction(function(resumeJson, readFileErrors) {
lib.settings(resumeJson, program);
});
});
program
.command('login')
.description('Not yet implemented')
.action(function() {
lib.login();
});
program.parse(process.argv);
var validCommands = program.commands.map(function(cmd) {
return cmd._name;
});
if (!program.args.length) {
console.log('resume-cli:'.cyan, 'http://jsonresume.org', '\n');
program.help();
} else if (validCommands.indexOf(process.argv[2]) === -1) {
console.log('Invalid argument:'.red, process.argv[2]);
console.log('resume-cli:'.cyan, 'http://jsonresume.org', '\n');
program.help();
}
});
// get rid of npm install warning: html to text, wrong node version
// get text converter working again
// version test on menu does not show
// publishing to non existent account error handling
//use jsonlint before schema tests run.
// broken on windows
// resume --version = wrong version
// settings change theme errors if 'account does not exist errors' or resume does not exist.
// resume doesn't handle test errors on 'resume publish' properly.
// or resume test is not running before publish as it should