Skip to content

Commit 53c8278

Browse files
author
CI Fix
committed
miscellaneous updates
1 parent 60e2f93 commit 53c8278

File tree

5 files changed

+136
-138
lines changed

5 files changed

+136
-138
lines changed

bin/lib/cli.mjs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
import { Command } from 'commander';
2-
import loadInit from './init.mjs';
3-
import loadStart from './start.mjs';
4-
import loadInvalidUsernames from './invalidUsernames.mjs';
5-
import loadMigrateLegacyResources from './migrateLegacyResources.mjs';
6-
import loadUpdateIndex from './updateIndex.mjs';
7-
import { spawnSync } from 'child_process';
8-
import path from 'path';
9-
import { fileURLToPath } from 'url';
1+
import { Command } from 'commander'
2+
import loadInit from './init.mjs'
3+
import loadStart from './start.mjs'
4+
import loadInvalidUsernames from './invalidUsernames.mjs'
5+
import loadMigrateLegacyResources from './migrateLegacyResources.mjs'
6+
import loadUpdateIndex from './updateIndex.mjs'
7+
import { spawnSync } from 'child_process'
8+
import path from 'path'
9+
import fs from 'fs'
10+
import { fileURLToPath } from 'url'
1011

11-
const __filename = fileURLToPath(import.meta.url);
12-
const __dirname = path.dirname(__filename);
12+
const __filename = fileURLToPath(import.meta.url)
13+
const __dirname = path.dirname(__filename)
1314

14-
export default function startCli(server) {
15-
const program = new Command();
16-
program.version(getVersion());
17-
loadInit(program);
18-
loadStart(program, server);
19-
loadInvalidUsernames(program);
20-
loadMigrateLegacyResources(program);
21-
loadUpdateIndex(program);
22-
program.parse(process.argv);
23-
if (program.args.length === 0) program.help();
15+
export default function startCli (server) {
16+
const program = new Command()
17+
program.version(getVersion())
18+
19+
loadInit(program)
20+
loadStart(program, server)
21+
loadInvalidUsernames(program)
22+
loadMigrateLegacyResources(program)
23+
loadUpdateIndex(program)
24+
25+
program.parse(process.argv)
26+
if (program.args.length === 0) program.help()
2427
}
2528

26-
function getVersion() {
29+
function getVersion () {
2730
try {
28-
const options = { cwd: __dirname, encoding: 'utf8' };
29-
const { stdout } = spawnSync('git', ['describe', '--tags'], options);
30-
const { stdout: gitStatusStdout } = spawnSync('git', ['status'], options);
31-
const version = stdout.trim();
31+
const options = { cwd: __dirname, encoding: 'utf8' }
32+
const { stdout } = spawnSync('git', ['describe', '--tags'], options)
33+
const { stdout: gitStatusStdout } = spawnSync('git', ['status'], options)
34+
const version = stdout.trim()
3235
if (version === '' || gitStatusStdout.match('Not currently on any branch')) {
33-
throw new Error('No git version here');
36+
throw new Error('No git version here')
3437
}
35-
return version;
38+
return version
3639
} catch (e) {
37-
const pkgPath = path.join(__dirname, '../../package.json');
38-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
39-
return pkg.version;
40+
const pkgPath = path.join(__dirname, '../../package.json')
41+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
42+
return pkg.version
4043
}
4144
}

bin/lib/init.mjs

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
1-
import inquirer from 'inquirer';
2-
import fs from 'fs';
3-
import options from './options.mjs';
4-
import camelize from 'camelize';
1+
import inquirer from 'inquirer'
2+
import fs from 'fs'
3+
import options from './options.mjs'
4+
import camelize from 'camelize'
55

6-
let questions = options.map((option) => {
7-
if (!option.type) {
8-
if (option.flag) {
9-
option.type = 'confirm';
10-
} else {
11-
option.type = 'input';
6+
let questions = options
7+
.map((option) => {
8+
if (!option.type) {
9+
if (option.flag) {
10+
option.type = 'confirm'
11+
} else {
12+
option.type = 'input'
13+
}
1214
}
13-
}
14-
option.message = option.question || option.help;
15-
return option;
16-
});
15+
16+
option.message = option.question || option.help
17+
return option
18+
})
1719

1820
export default function (program) {
1921
program
2022
.command('init')
2123
.option('--advanced', 'Ask for all the settings')
2224
.description('create solid server configurations')
2325
.action((opts) => {
24-
let filteredQuestions = questions;
26+
// Filter out advanced commands
27+
let filtered = questions
2528
if (!opts.advanced) {
26-
filteredQuestions = filteredQuestions.filter((option) => option.prompt);
29+
filtered = filtered.filter((option) => option.prompt)
2730
}
28-
inquirer.prompt(filteredQuestions)
31+
32+
// Prompt to the user
33+
inquirer.prompt(filtered)
2934
.then((answers) => {
30-
manipulateEmailSection(answers);
31-
manipulateServerSection(answers);
32-
cleanupAnswers(answers);
33-
const config = JSON.stringify(camelize(answers), null, ' ');
34-
const configPath = process.cwd() + '/config.json';
35+
manipulateEmailSection(answers)
36+
manipulateServerSection(answers)
37+
cleanupAnswers(answers)
38+
39+
// write config file
40+
const config = JSON.stringify(camelize(answers), null, ' ')
41+
const configPath = process.cwd() + '/config.json'
42+
3543
fs.writeFile(configPath, config, (err) => {
3644
if (err) {
37-
return console.log('failed to write config.json');
45+
return console.log('failed to write config.json')
3846
}
39-
console.log('config created on', configPath);
40-
});
47+
console.log('config created on', configPath)
48+
})
4149
})
4250
.catch((err) => {
43-
console.log('Error:', err);
44-
});
45-
});
51+
console.log('Error:', err)
52+
})
53+
})
4654
}
4755

48-
function cleanupAnswers(answers) {
56+
function cleanupAnswers (answers) {
4957
Object.keys(answers).forEach((answer) => {
5058
if (answer.startsWith('use')) {
51-
delete answers[answer];
59+
delete answers[answer]
5260
}
53-
});
61+
})
5462
}
5563

56-
function manipulateEmailSection(answers) {
64+
function manipulateEmailSection (answers) {
5765
if (answers.useEmail) {
5866
answers.email = {
5967
host: answers['email-host'],
@@ -63,23 +71,24 @@ function manipulateEmailSection(answers) {
6371
user: answers['email-auth-user'],
6472
pass: answers['email-auth-pass']
6573
}
66-
};
67-
delete answers['email-host'];
68-
delete answers['email-port'];
69-
delete answers['email-auth-user'];
70-
delete answers['email-auth-pass'];
74+
}
75+
delete answers['email-host']
76+
delete answers['email-port']
77+
delete answers['email-auth-user']
78+
delete answers['email-auth-pass']
7179
}
7280
}
7381

74-
function manipulateServerSection(answers) {
82+
function manipulateServerSection (answers) {
7583
answers.server = {
7684
name: answers['server-info-name'],
7785
description: answers['server-info-description'],
7886
logo: answers['server-info-logo']
79-
};
87+
}
8088
Object.keys(answers).forEach((answer) => {
8189
if (answer.startsWith('server-info-')) {
82-
delete answers[answer];
90+
delete answers[answer]
8391
}
84-
});
92+
})
8593
}
94+

bin/lib/options.mjs

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import validUrl from 'valid-url';
4-
import { URL } from 'url';
5-
import validator from 'validator';
6-
const { isEmail } = validator;
1+
import fs from 'fs'
2+
import path from 'path'
3+
import validUrl from 'valid-url'
4+
import { URL } from 'url'
5+
import validator from 'validator'
6+
const { isEmail } = validator
77

88
const options = [
9-
// {
10-
// abbr: 'v',
11-
// flag: true,
12-
// help: 'Print the logs to console\n'
13-
// },
149
{
1510
name: 'root',
1611
help: "Root folder to serve (default: './data')",
@@ -80,9 +75,7 @@ const options = [
8075
filter: (value) => {
8176
if (value === 'WebID-OpenID Connect') return 'oidc'
8277
},
83-
when: (answers) => {
84-
return answers.webid
85-
}
78+
when: (answers) => answers.webid
8679
},
8780
{
8881
name: 'use-owner',
@@ -150,10 +143,6 @@ const options = [
150143
flag: true,
151144
default: false
152145
},
153-
// {
154-
// full: 'default-app',
155-
// help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
156-
// },
157146
{
158147
name: 'use-cors-proxy',
159148
help: 'Do you want to have a CORS proxy endpoint?',
@@ -225,11 +214,6 @@ const options = [
225214
return value
226215
}
227216
},
228-
// {
229-
// full: 'no-error-pages',
230-
// flag: true,
231-
// help: 'Disable custom error pages (use Node.js default pages instead)'
232-
// },
233217
{
234218
name: 'error-pages',
235219
help: 'Folder from which to look for custom error pages files (files must be named <error-code>.html -- eg. 500.html)',
@@ -259,26 +243,20 @@ const options = [
259243
help: 'Host of your email service',
260244
prompt: true,
261245
default: 'smtp.gmail.com',
262-
when: (answers) => {
263-
return answers['use-email']
264-
}
246+
when: (answers) => answers['use-email']
265247
},
266248
{
267249
name: 'email-port',
268250
help: 'Port of your email service',
269251
prompt: true,
270252
default: '465',
271-
when: (answers) => {
272-
return answers['use-email']
273-
}
253+
when: (answers) => answers['use-email']
274254
},
275255
{
276256
name: 'email-auth-user',
277257
help: 'User of your email service',
278258
prompt: true,
279-
when: (answers) => {
280-
return answers['use-email']
281-
},
259+
when: (answers) => answers['use-email'],
282260
validate: (value) => {
283261
if (!value) {
284262
return 'You must enter this information'
@@ -291,9 +269,7 @@ const options = [
291269
help: 'Password of your email service',
292270
type: 'password',
293271
prompt: true,
294-
when: (answers) => {
295-
return answers['use-email']
296-
}
272+
when: (answers) => answers['use-email']
297273
},
298274
{
299275
name: 'use-api-apps',
@@ -307,42 +283,37 @@ const options = [
307283
help: 'Path to the folder to mount on /api/apps',
308284
prompt: true,
309285
validate: validPath,
310-
when: (answers) => {
311-
return answers['use-api-apps']
312-
}
286+
when: (answers) => answers['use-api-apps']
313287
},
314-
{ // copied from name: 'owner'
288+
{
315289
name: 'redirect-http-from',
316-
help: 'HTTP port or \',\'-separated ports to redirect to the solid server port (e.g. "80,8080").',
290+
help: 'HTTP port or comma-separated ports to redirect to the solid server port (e.g. "80,8080").',
317291
prompt: false,
318292
validate: function (value) {
319293
if (!value.match(/^[0-9]+(,[0-9]+)*$/)) {
320294
return 'direct-port(s) must be a comma-separated list of integers.'
321295
}
322296
const list = value.split(/,/).map(v => parseInt(v))
323297
const bad = list.find(v => { return v < 1 || v > 65535 })
324-
if (bad.length) {
298+
if (bad && bad.length) {
325299
return 'redirect-http-from port(s) ' + bad + ' out of range'
326300
}
327301
return true
328302
}
329303
},
330304
{
331-
// This property is packaged into an object for the server property in config.json
332-
name: 'server-info-name', // All properties with prefix server-info- will be removed from the config
305+
name: 'server-info-name',
333306
help: 'A name for your server (not required, but will be presented on your server\'s frontpage)',
334307
prompt: true,
335308
default: answers => new URL(answers['server-uri']).hostname
336309
},
337310
{
338-
// This property is packaged into an object for the server property in config.json
339-
name: 'server-info-description', // All properties with prefix server-info- will be removed from the config
311+
name: 'server-info-description',
340312
help: 'A description of your server (not required)',
341313
prompt: true
342314
},
343315
{
344-
// This property is packaged into an object for the server property in config.json
345-
name: 'server-info-logo', // All properties with prefix server-info- will be removed from the config
316+
name: 'server-info-logo',
346317
help: 'A logo that represents you, your brand, or your server (not required)',
347318
prompt: true
348319
},
@@ -381,28 +352,28 @@ const options = [
381352
},
382353
when: answers => answers.multiuser
383354
}
384-
];
355+
]
385356

386-
function validPath(value) {
357+
function validPath (value) {
387358
if (value === 'default') {
388-
return Promise.resolve(true);
359+
return Promise.resolve(true)
389360
}
390361
if (!value) {
391-
return Promise.resolve('You must enter a valid path');
362+
return Promise.resolve('You must enter a valid path')
392363
}
393364
return new Promise((resolve) => {
394365
fs.stat(value, function (err) {
395-
if (err) return resolve('Nothing found at this path');
396-
return resolve(true);
397-
});
398-
});
366+
if (err) return resolve('Nothing found at this path')
367+
return resolve(true)
368+
})
369+
})
399370
}
400371

401-
function validUri(value) {
372+
function validUri (value) {
402373
if (!validUrl.isUri(value)) {
403-
return 'Enter a valid uri (with protocol)';
374+
return 'Enter a valid uri (with protocol)'
404375
}
405-
return true;
376+
return true
406377
}
407378

408-
export default options;
379+
export default options

0 commit comments

Comments
 (0)