forked from lmihaidaniel/simple-scorm-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
180 lines (172 loc) · 4.25 KB
/
cli.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
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
#!/usr/bin/env node
var path = require("path"),
fs = require("fs"),
inquirer = require("inquirer"),
utils = require(path.join(__dirname, "lib"+path.sep+"utils.js")),
scopackage = require(path.join(__dirname, "lib"+path.sep+"index.js")),
generateDefaultSettings = require(path.join(__dirname,"lib"+path.sep+"schemas"+path.sep+"config.js"));
inquirer.registerPrompt("directory", require("inquirer-directory"));
function getPackageName () {
try {
const pkg = require(path.join(process.cwd(), "package.json"))
return pkg.name
} catch (e) {
return ""
}
}
var validators = {
notEmpty: function(value){
if(value&&utils.cleanAndTrim(value)!="") return true;
return "Please enter a valid information";
},
number: function(value) {
return !isNaN(parseFloat(value)) || "Please enter a number";
}
};
var settings = {
source: process.cwd(),
uuid: utils.uuid(),
version: "1.2",
language: "en",
organization: "",
title: getPackageName(),
identifier: "",
masteryScore: 80,
startingPage: "index.html",
package: {
zip: true
}
};
var cli_init = function(next){
inquirer
.prompt([{
type: "list",
name: "version",
message: "Select scorm version:",
choices: [
"1.2",
new inquirer.Separator(),
{
name: "2004 1st Edition",
disabled: "Unavailable at this time"
},
{
name: "2004 2nd Edition",
disabled: "Unavailable at this time"
},
"2004 3rd Edition",
"2004 4th Edition"
]},{
type: "input",
name: "title",
message: "Select title:",
default: settings.title,
validate: validators.notEmpty,
filter: function(value) {
return value.trim();
}
},{
type: "input",
name: "organization",
message: "Select organization:",
validate: validators.notEmpty,
filter: function(value) {
return value.trim();
}
},
{
type: "input",
name: "language",
message: "Select language:",
default: settings.language,
validate: validators.notEmpty,
filter: function(value) {
return value.trim().toLowerCase();
}
},
{
type: "input",
name: "masteryScore",
message: "Select mastery score [Range 0-100]:",
default: settings.masteryScore,
filter: Number,
validate: validators.number
},
{
type: "input",
name: "startingPage",
message: "Select starting page:",
default: settings.startingPage,
validate: validators.notEmpty,
filter: function(value) {
return value.trim();
}
}
]).then(function(answers) {
settings.version = answers.version;
settings.title = answers.title;
settings.organization = answers.organization;
settings.language = answers.language;
settings.masteryScore = answers.masteryScore;
settings.startingPage = answers.startingPage;
next();
});
}
var cli_identifier = function(next){
inquirer
.prompt([
{
type: "input",
name: "identifier",
message: "Select an identifier:",
default: (utils.acronym(settings.organization)+"00").toUpperCase(),
validate: validators.notEmpty,
filter: function(value) {
return value.trim();
}
},{
type: "input",
name: "uuid",
message: "Select an unique identifier:",
default: settings.uuid,
validate: validators.notEmpty,
filter: function(value) {
return value.trim();
}
}
])
.then(function(answers) {
settings.identifier = answers.identifier;
settings.uuid = answers.uuid;
next();
});
}
var cli_source = function(next){
inquirer
.prompt([
{
type: "directory",
name: "from",
message: "Select source directory:",
basePath: settings.source
}
])
.then(function(answers) {
var dir = (answers.from || settings.source) + path.sep;
settings.source = path.resolve(dir);
next();
});
}
cli_init(function(){
cli_identifier(function(){
cli_source(function(){
var config = generateDefaultSettings(settings);
/*TODO
- add cli input for package
- add cli helper
- add cli input config file
*/
scopackage(config);
});
})
});