Skip to content

Commit 299b2f9

Browse files
Run prettier
Run prettier on the JavaScript code.
1 parent cb70826 commit 299b2f9

File tree

3 files changed

+108
-57
lines changed

3 files changed

+108
-57
lines changed

generators/app/index.js

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,44 @@ import queryString from 'query-string';
55
import yosay from 'yosay';
66

77
export default class extends Generator {
8-
98
initializing() {
109
this.templateData = {};
1110
this.log(yosay('Welcome to the classy ASP.NET OAuth Provider generator!'));
1211
}
1312

1413
async prompting() {
15-
const prompts = [{
16-
type: 'input',
17-
name: 'name',
18-
message: 'What is the name of the provider you want to create?',
19-
store: true
20-
},
21-
{
22-
type: 'input',
23-
name: 'authorname',
24-
message: 'What is your name?',
25-
store: true
26-
},
27-
{
28-
type: 'input',
29-
name: 'authorizationendpoint',
30-
message: 'What is the Authorization Endpoint for this service?',
31-
store: true
32-
},
33-
{
34-
type: 'input',
35-
name: 'tokenendpoint',
36-
message: 'What is the Token Endpoint for this service?',
37-
store: true
38-
},
39-
{
40-
type: 'input',
41-
name: 'userinformationendpoint',
42-
message: 'What is the User Information Endpoint for this service?',
43-
store: true
44-
}];
14+
const prompts = [
15+
{
16+
type: 'input',
17+
name: 'name',
18+
message: 'What is the name of the provider you want to create?',
19+
store: true,
20+
},
21+
{
22+
type: 'input',
23+
name: 'authorname',
24+
message: 'What is your name?',
25+
store: true,
26+
},
27+
{
28+
type: 'input',
29+
name: 'authorizationendpoint',
30+
message: 'What is the Authorization Endpoint for this service?',
31+
store: true,
32+
},
33+
{
34+
type: 'input',
35+
name: 'tokenendpoint',
36+
message: 'What is the Token Endpoint for this service?',
37+
store: true,
38+
},
39+
{
40+
type: 'input',
41+
name: 'userinformationendpoint',
42+
message: 'What is the User Information Endpoint for this service?',
43+
store: true,
44+
},
45+
];
4546

4647
const answers = await this.prompt(prompts);
4748

@@ -58,23 +59,44 @@ export default class extends Generator {
5859
}
5960

6061
writing() {
61-
this.fs.copyTpl(this.templatePath('Project.csproj'), this.applicationName + '/' + this.applicationName + '.csproj', this.templateData)
62-
this.fs.copyTpl(this.templatePath('AuthenticationDefaults.cs'), this.applicationName + '/' + this.name + 'AuthenticationDefaults.cs', this.templateData)
63-
this.fs.copyTpl(this.templatePath('AuthenticationExtensions.cs'), this.applicationName + '/' + this.name + 'AuthenticationExtensions.cs', this.templateData)
64-
this.fs.copyTpl(this.templatePath('AuthenticationHandler.cs'), this.applicationName + '/' + this.name + 'AuthenticationHandler.cs', this.templateData)
65-
this.fs.copyTpl(this.templatePath('AuthenticationOptions.cs'), this.applicationName + '/' + this.name + 'AuthenticationOptions.cs', this.templateData)
62+
this.fs.copyTpl(
63+
this.templatePath('Project.csproj'),
64+
this.applicationName + '/' + this.applicationName + '.csproj',
65+
this.templateData
66+
);
67+
this.fs.copyTpl(
68+
this.templatePath('AuthenticationDefaults.cs'),
69+
this.applicationName + '/' + this.name + 'AuthenticationDefaults.cs',
70+
this.templateData
71+
);
72+
this.fs.copyTpl(
73+
this.templatePath('AuthenticationExtensions.cs'),
74+
this.applicationName + '/' + this.name + 'AuthenticationExtensions.cs',
75+
this.templateData
76+
);
77+
this.fs.copyTpl(
78+
this.templatePath('AuthenticationHandler.cs'),
79+
this.applicationName + '/' + this.name + 'AuthenticationHandler.cs',
80+
this.templateData
81+
);
82+
this.fs.copyTpl(
83+
this.templatePath('AuthenticationOptions.cs'),
84+
this.applicationName + '/' + this.name + 'AuthenticationOptions.cs',
85+
this.templateData
86+
);
6687
}
6788

6889
async getCurrentVersion() {
69-
7090
let response = await fetch('https://api.nuget.org/v3/index.json');
7191

7292
if (!response.ok) {
7393
throw new Error(`Failed to query NuGet service index. HTTP status code: ${response.status}.`);
7494
}
7595

7696
const serviceIndex = await response.json();
77-
const baseAddress = serviceIndex.resources.find(resource => resource['@type'] === 'SearchQueryService/3.5.0')['@id'];
97+
const baseAddress = serviceIndex.resources.find(
98+
(resource) => resource['@type'] === 'SearchQueryService/3.5.0'
99+
)['@id'];
78100

79101
if (!baseAddress) {
80102
throw new Error('Failed to determine the base address for the NuGet search query service.');
@@ -84,14 +106,16 @@ export default class extends Generator {
84106
prerelease: false,
85107
q: 'PackageId:AspNet.Security.OAuth.GitHub',
86108
semVerLevel: '2.0.0',
87-
take: 1
109+
take: 1,
88110
});
89111

90112
const searchUrl = `${baseAddress}?${query}`;
91113
response = await fetch(searchUrl);
92114

93115
if (!response.ok) {
94-
throw new Error(`Failed to search for NuGet package from '${searchUrl}'. HTTP status code: ${response.status}.`);
116+
throw new Error(
117+
`Failed to search for NuGet package from '${searchUrl}'. HTTP status code: ${response.status}.`
118+
);
95119
}
96120

97121
const searchResult = await response.json();
@@ -115,4 +139,4 @@ export default class extends Generator {
115139

116140
return versionParts.join(dot);
117141
}
118-
};
142+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"prettier": {
5050
"arrowParens": "always",
5151
"bracketSpacing": true,
52-
"printWidth": 140,
52+
"printWidth": 100,
5353
"quoteProps": "consistent",
5454
"semi": true,
5555
"singleQuote": true,

test/test-app.js

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const __dirname = path.dirname(__filename);
1414
describe('aspnet-oauth:app', () => {
1515
before(async function () {
1616
this.timeout(10000);
17-
await helpers.run(path.join(__dirname, '../generators/app'))
17+
await helpers
18+
.run(path.join(__dirname, '../generators/app'))
1819
.withOptions({ skipInstall: true })
1920
.withAnswers({
2021
name: 'Foo',
2122
authorname: 'John Smith',
2223
authorizationendpoint: 'https://foo.local/auth',
2324
tokenendpoint: 'https://foo.local/token',
24-
userinformationendpoint: 'https://foo.local/user'
25+
userinformationendpoint: 'https://foo.local/user',
2526
});
2627
});
2728

@@ -31,7 +32,7 @@ describe('aspnet-oauth:app', () => {
3132
'AspNet.Security.OAuth.Foo/FooAuthenticationDefaults.cs',
3233
'AspNet.Security.OAuth.Foo/FooAuthenticationExtensions.cs',
3334
'AspNet.Security.OAuth.Foo/FooAuthenticationHandler.cs',
34-
'AspNet.Security.OAuth.Foo/FooAuthenticationOptions.cs'
35+
'AspNet.Security.OAuth.Foo/FooAuthenticationOptions.cs',
3536
]);
3637
});
3738
it('sets the authors name', () => {
@@ -144,7 +145,6 @@ describe('aspnet-oauth:app', () => {
144145
});
145146

146147
describe('generating a new provider', () => {
147-
148148
const projectName = 'AspNet.Security.OAuth.Foo';
149149
const tempDir = path.join(os.tmpdir(), `_generator-aspnet-oauth-${Math.random()}`);
150150
const artifactsDir = path.join(tempDir, 'artifacts');
@@ -156,32 +156,36 @@ describe('aspnet-oauth:app', () => {
156156
this.timeout(180000);
157157

158158
// Clone the providers repository to add the project to
159-
const clone = spawnSync(
160-
'git',
161-
['clone', 'https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers.git', tempDir]);
159+
const clone = spawnSync('git', [
160+
'clone',
161+
'https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers.git',
162+
tempDir,
163+
]);
162164

163165
if (clone.status !== 0 && clone.output) {
164166
console.error(clone.output.toString('utf8'));
165167
}
166168
assert.strictEqual(clone.status, 0);
167169

168170
// Run the generator to create the project
169-
context = await helpers.run(path.join(__dirname, '../generators/app'), { tmpdir: false })
171+
context = await helpers
172+
.run(path.join(__dirname, '../generators/app'), { tmpdir: false })
170173
.cd(sourceDir)
171174
.withOptions({ skipInstall: true })
172175
.withPrompts({
173176
name: 'Foo',
174177
authorname: 'John Smith',
175178
authorizationendpoint: 'https://foo.local/auth',
176179
tokenendpoint: 'https://foo.local/token',
177-
userinformationendpoint: 'https://foo.local/user'
180+
userinformationendpoint: 'https://foo.local/user',
178181
});
179182

180183
// Add the new project to the solution
181184
const dotnetSlnAdd = spawnSync(
182185
`dotnet`,
183186
['sln', 'add', path.join(projectDir, `${projectName}.csproj`)],
184-
{ cwd: tempDir });
187+
{ cwd: tempDir }
188+
);
185189

186190
if (dotnetSlnAdd.status !== 0) {
187191
console.error(dotnetSlnAdd.output.toString('utf8'));
@@ -192,9 +196,14 @@ describe('aspnet-oauth:app', () => {
192196
let build;
193197

194198
if (process.platform === 'win32') {
195-
build = spawnSync('build.cmd', ['-test', '-pack', '-configuration', configuration], { cwd: tempDir, shell: true });
199+
build = spawnSync('build.cmd', ['-test', '-pack', '-configuration', configuration], {
200+
cwd: tempDir,
201+
shell: true,
202+
});
196203
} else {
197-
build = spawnSync('./build.sh', ['--test', '--pack', '--configuration', configuration], { cwd: tempDir });
204+
build = spawnSync('./build.sh', ['--test', '--pack', '--configuration', configuration], {
205+
cwd: tempDir,
206+
});
198207
}
199208

200209
if (build.status !== 0 && build.output) {
@@ -204,15 +213,33 @@ describe('aspnet-oauth:app', () => {
204213
});
205214

206215
it('compiles the provider', async () => {
207-
const expected = path.join(artifactsDir, 'bin', projectName, configuration, 'net*', `${projectName}.dll`);
216+
const expected = path.join(
217+
artifactsDir,
218+
'bin',
219+
projectName,
220+
configuration,
221+
'net*',
222+
`${projectName}.dll`
223+
);
208224
await glob(expected);
209225
});
210226
it('generates the NuGet package', async () => {
211-
const expected = path.join(artifactsDir, 'packages', configuration, 'Shipping', `${projectName}.*.nupkg`);
227+
const expected = path.join(
228+
artifactsDir,
229+
'packages',
230+
configuration,
231+
'Shipping',
232+
`${projectName}.*.nupkg`
233+
);
212234
await glob(expected);
213235
});
214236
it('runs the tests', async () => {
215-
const expected = path.join(artifactsDir, 'TestResults', configuration, 'AspNet.Security.OAuth.Providers.Tests_net*_x64.html');
237+
const expected = path.join(
238+
artifactsDir,
239+
'TestResults',
240+
configuration,
241+
'AspNet.Security.OAuth.Providers.Tests_net*_x64.html'
242+
);
216243
await glob(expected);
217244
});
218245
});

0 commit comments

Comments
 (0)