Skip to content

Commit bfef91c

Browse files
committed
update js files to semi-standard style
Signed-off-by: Michael Dawson <[email protected]>
1 parent 7d7c5f7 commit bfef91c

File tree

7 files changed

+187
-187
lines changed

7 files changed

+187
-187
lines changed

index.js

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,130 @@
1-
'use strict'
2-
const path = require('path')
3-
const fs = require('fs')
4-
const normalizeUrl = require('normalize-url')
5-
const Ajv = require('ajv')
6-
const got = require('got')
7-
const betterAjvErrors = require('better-ajv-errors')
1+
'use strict';
2+
const path = require('path');
3+
const fs = require('fs');
4+
const normalizeUrl = require('normalize-url');
5+
const Ajv = require('ajv');
6+
const got = require('got');
7+
const betterAjvErrors = require('better-ajv-errors');
88

9-
let ajv
10-
let compiledSchema
11-
let ajvElement
12-
let compiledSchemaElement
9+
let ajv;
10+
let compiledSchema;
11+
let ajvElement;
12+
let compiledSchemaElement;
1313

14-
const schema = module.exports.schema = require('./schema.json')
15-
const supportElementSchema = module.exports.schema = require('./support-element-schema.json')
14+
const schema = module.exports.schema = require('./schema.json');
15+
const supportElementSchema = module.exports.schema = require('./support-element-schema.json');
1616

17-
module.exports.defaultPackageSupport = 'package-support.json'
17+
module.exports.defaultPackageSupport = 'package-support.json';
1818

1919
function getBetterAjvErrorsOptions (cli) {
20-
const options = { format: 'js' }
20+
const options = { format: 'js' };
2121
if (cli === true) {
22-
options.format = 'cli'
22+
options.format = 'cli';
2323
}
24-
return options
24+
return options;
2525
}
2626

2727
module.exports.validateSupportElement = (obj, cli = false) => {
2828
if (!ajvElement) {
29-
ajvElement = new Ajv({ jsonPointers: true })
30-
compiledSchemaElement = ajvElement.compile(supportElementSchema)
29+
ajvElement = new Ajv({ jsonPointers: true });
30+
compiledSchemaElement = ajvElement.compile(supportElementSchema);
3131
}
3232

33-
const validates = compiledSchemaElement(obj)
33+
const validates = compiledSchemaElement(obj);
3434
if (!validates) {
35-
const err = new Error('Validation Failed')
36-
err.validationErrors = compiledSchemaElement.errors
37-
err.prettyValidationErrors = betterAjvErrors(supportElementSchema, obj, compiledSchemaElement.errors, getBetterAjvErrorsOptions(cli))
38-
err.validationSchema = compiledSchemaElement.schema
39-
throw err
35+
const err = new Error('Validation Failed');
36+
err.validationErrors = compiledSchemaElement.errors;
37+
err.prettyValidationErrors = betterAjvErrors(supportElementSchema, obj, compiledSchemaElement.errors, getBetterAjvErrorsOptions(cli));
38+
err.validationSchema = compiledSchemaElement.schema;
39+
throw err;
4040
}
41-
return true
42-
}
41+
return true;
42+
};
4343

4444
module.exports.validate = (obj, cli = false) => {
4545
if (!ajv) {
46-
ajv = new Ajv({ jsonPointers: true })
47-
compiledSchema = ajv.compile(schema)
46+
ajv = new Ajv({ jsonPointers: true });
47+
compiledSchema = ajv.compile(schema);
4848
}
4949

50-
const validates = compiledSchema(obj)
50+
const validates = compiledSchema(obj);
5151
if (!validates) {
52-
const err = new Error('Validation Failed')
53-
err.validationErrors = compiledSchema.errors
54-
err.prettyValidationErrors = betterAjvErrors(schema, obj, compiledSchema.errors, getBetterAjvErrorsOptions(cli))
55-
err.validationSchema = compiledSchema.schema
56-
throw err
52+
const err = new Error('Validation Failed');
53+
err.validationErrors = compiledSchema.errors;
54+
err.prettyValidationErrors = betterAjvErrors(schema, obj, compiledSchema.errors, getBetterAjvErrorsOptions(cli));
55+
err.validationSchema = compiledSchema.schema;
56+
throw err;
5757
}
58-
return true
59-
}
58+
return true;
59+
};
6060

6161
// extract the URL for the support info from the pkg info
6262
module.exports.getRemoteSupportInfoUrl = (repository, supportPath) => {
63-
const gitHubInitialPath = '/blob/master/'
63+
const gitHubInitialPath = '/blob/master/';
6464

6565
if (repository && (repository.type === 'git')) {
66-
const directory = repository.directory || ''
67-
let remoteURL = repository.url
68-
const trailerLocation = remoteURL.indexOf('.git')
66+
const directory = repository.directory || '';
67+
let remoteURL = repository.url;
68+
const trailerLocation = remoteURL.indexOf('.git');
6969
if (trailerLocation >= 0) {
7070
remoteURL = remoteURL.substring(0, trailerLocation) +
7171
gitHubInitialPath + '/' + directory +
72-
'/' + supportPath
72+
'/' + supportPath;
7373
}
74-
return normalizeUrl(remoteURL)
74+
return normalizeUrl(remoteURL);
7575
} else {
76-
return 'unknown'
76+
return 'unknown';
7777
}
78-
}
78+
};
7979

8080
// the path should not try to escape the root as it
8181
// is specified to be a relative path
8282
module.exports.sanitizePath = (basePath, inputPath, basePathOverride) => {
83-
const effectiveBasePath = path.normalize(basePathOverride || basePath)
84-
const candidatePath = path.join(basePath, inputPath)
85-
let ret = path.basename(inputPath)
83+
const effectiveBasePath = path.normalize(basePathOverride || basePath);
84+
const candidatePath = path.join(basePath, inputPath);
85+
let ret = path.basename(inputPath);
8686
if (candidatePath.indexOf(effectiveBasePath) === 0) {
8787
// inputPath did not try to escape
88-
ret = inputPath
88+
ret = inputPath;
8989
}
90-
return ret
91-
}
90+
return ret;
91+
};
9292

9393
async function resolveSupportInfo (supportInfo, fetchCanonical) {
94-
supportInfo.resolved = false
94+
supportInfo.resolved = false;
9595
if (fetchCanonical) {
9696
const url = normalizeUrl(supportInfo.url
9797
.replace('blob', '')
98-
.replace('github.com', 'raw.githubusercontent.com'))
98+
.replace('github.com', 'raw.githubusercontent.com'));
9999
try {
100-
const result = await got(url)
101-
supportInfo.contents = result.body
102-
supportInfo.resolved = true
100+
const result = await got(url);
101+
supportInfo.contents = result.body;
102+
supportInfo.resolved = true;
103103
} catch (e) {
104-
supportInfo.error = e
104+
supportInfo.error = e;
105105
}
106106
}
107107
}
108108

109109
module.exports.getSupportData = async (pkg, pkgPath, preferCanonical, basePathOverride, fetchCanonical) => {
110-
const supportInfo = { contents: 'unknown', url: '', resolved: true }
110+
const supportInfo = { contents: 'unknown', url: '', resolved: true };
111111
if (pkg.support) {
112112
if ((pkg.support === true) || (typeof pkg.support === 'string')) {
113113
const supportInfoName = (pkg.support === true)
114-
? module.exports.defaultPackageSupport : module.exports.sanitizePath(pkgPath, pkg.support, basePathOverride)
115-
const localPath = path.join(pkgPath, supportInfoName)
114+
? module.exports.defaultPackageSupport : module.exports.sanitizePath(pkgPath, pkg.support, basePathOverride);
115+
const localPath = path.join(pkgPath, supportInfoName);
116116
if (!preferCanonical && fs.existsSync(localPath)) {
117-
supportInfo.contents = fs.readFileSync(localPath)
118-
supportInfo.resolved = true
117+
supportInfo.contents = fs.readFileSync(localPath);
118+
supportInfo.resolved = true;
119119
} else {
120-
supportInfo.url = module.exports.getRemoteSupportInfoUrl(pkg.repository, supportInfoName)
121-
await resolveSupportInfo(supportInfo, fetchCanonical)
120+
supportInfo.url = module.exports.getRemoteSupportInfoUrl(pkg.repository, supportInfoName);
121+
await resolveSupportInfo(supportInfo, fetchCanonical);
122122
}
123123
} else if (typeof pkg.support === 'object') {
124-
const supportInfoName = pkg.support.path ? pkg.support.path : module.exports.defaultPackageSupport
125-
supportInfo.url = module.exports.getRemoteSupportInfoUrl(pkg.support.repository, supportInfoName)
126-
await resolveSupportInfo(supportInfo, fetchCanonical)
124+
const supportInfoName = pkg.support.path ? pkg.support.path : module.exports.defaultPackageSupport;
125+
supportInfo.url = module.exports.getRemoteSupportInfoUrl(pkg.support.repository, supportInfoName);
126+
await resolveSupportInfo(supportInfo, fetchCanonical);
127127
}
128128
}
129-
return supportInfo
130-
}
129+
return supportInfo;
130+
};

lib/cli/commands/badges.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict'
1+
'use strict';
22
module.exports = function (opts) {
33
return {
44
command: 'badges',
55
desc: 'Output badges markdown based on support',
66
builder: function (yargs) {
7-
return yargs
7+
return yargs;
88
},
99
handler: function (argv) {
10-
argv.log.info('badges')
10+
argv.log.info('badges');
1111
}
12-
}
13-
}
12+
};
13+
};

lib/cli/commands/setup.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict'
1+
'use strict';
22
module.exports = function (opts) {
33
return {
44
command: 'setup',
55
desc: 'Setup a support declaration for a package',
66
builder: function (yargs) {
7-
return yargs
7+
return yargs;
88
},
99
handler: function (argv) {
10-
argv.log.info('setup')
10+
argv.log.info('setup');
1111
}
12-
}
13-
}
12+
};
13+
};

lib/cli/commands/show.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
'use strict'
2-
const support = require('../../../index.js')
3-
const Arborist = require('@npmcli/arborist')
1+
'use strict';
2+
const support = require('../../../index.js');
3+
const Arborist = require('@npmcli/arborist');
44

55
// print out the information for a module and its
66
// children
77
async function printModule (module, depth, argv) {
8-
const pkg = module.package
9-
const moduleInfo = `${pkg.name}(${pkg.version})`
8+
const pkg = module.package;
9+
const moduleInfo = `${pkg.name}(${pkg.version})`;
1010

1111
const supportInfo = await support.getSupportData(pkg,
1212
module.path,
1313
argv.canonical,
1414
argv['base-path'],
15-
argv.fetch)
15+
argv.fetch);
1616
if (supportInfo.resolved) {
17-
const flattenedSupportInfo = supportInfo.contents.toString().replace(/\n/g, '').replace(/\s+/g, ' ')
18-
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - ${flattenedSupportInfo}`)
17+
const flattenedSupportInfo = supportInfo.contents.toString().replace(/\n/g, '').replace(/\s+/g, ' ');
18+
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - ${flattenedSupportInfo}`);
1919
} else if (supportInfo.error) {
20-
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - failed to fetch - ${supportInfo.url}`)
20+
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - failed to fetch - ${supportInfo.url}`);
2121
} else {
22-
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - ${supportInfo.url}`)
22+
console.log(`${' '.repeat(2 * (depth + 1))}${moduleInfo} - ${supportInfo.url}`);
2323
}
2424

2525
// sort child modules
26-
module.children = new Map([...module.children.entries()].sort())
26+
module.children = new Map([...module.children.entries()].sort());
2727

2828
// print info for all of the child modules
2929
for (const child of module.children.values()) {
30-
await printModule(child, depth + 1, argv)
30+
await printModule(child, depth + 1, argv);
3131
}
32-
};
32+
}
3333

3434
module.exports = function (opts) {
3535
return {
3636
command: 'show',
3737
desc: 'Show support information',
3838
builder: function (yargs) {
39-
return yargs
39+
return yargs;
4040
},
4141
handler: function (argv) {
42-
const arb = new Arborist()
42+
const arb = new Arborist();
4343
arb.buildIdealTree({ legacyBundling: true }).then(root => {
4444
printModule(root, 0, argv).then(() => {}, (e) => {
45-
argv.log.error('show failed: ', e)
46-
})
47-
})
45+
argv.log.error('show failed: ', e);
46+
});
47+
});
4848
}
49-
}
50-
}
49+
};
50+
};

0 commit comments

Comments
 (0)