Skip to content

Add prettier #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.cs]
indent_size = 4
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
with:
dotnet-version: '9.0.x'

- name: Lint
run: |
npm run format-check

- name: Test
run: |
npm test
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
106 changes: 65 additions & 41 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@ import queryString from 'query-string';
import yosay from 'yosay';

export default class extends Generator {

initializing() {
this.templateData = {};
this.log(yosay('Welcome to the classy ASP.NET OAuth Provider generator!'));
}

async prompting() {
const prompts = [{
type: 'input',
name: 'name',
message: 'What is the name of the provider you want to create?',
store: true
},
{
type: 'input',
name: 'authorname',
message: 'What is your name?',
store: true
},
{
type: 'input',
name: 'authorizationendpoint',
message: 'What is the Authorization Endpoint for this service?',
store: true
},
{
type: 'input',
name: 'tokenendpoint',
message: 'What is the Token Endpoint for this service?',
store: true
},
{
type: 'input',
name: 'userinformationendpoint',
message: 'What is the User Information Endpoint for this service?',
store: true
}];
const prompts = [
{
type: 'input',
name: 'name',
message: 'What is the name of the provider you want to create?',
store: true,
},
{
type: 'input',
name: 'authorname',
message: 'What is your name?',
store: true,
},
{
type: 'input',
name: 'authorizationendpoint',
message: 'What is the Authorization Endpoint for this service?',
store: true,
},
{
type: 'input',
name: 'tokenendpoint',
message: 'What is the Token Endpoint for this service?',
store: true,
},
{
type: 'input',
name: 'userinformationendpoint',
message: 'What is the User Information Endpoint for this service?',
store: true,
},
];

const answers = await this.prompt(prompts);

Expand All @@ -58,23 +59,44 @@ export default class extends Generator {
}

writing() {
this.fs.copyTpl(this.templatePath('Project.csproj'), this.applicationName + '/' + this.applicationName + '.csproj', this.templateData)
this.fs.copyTpl(this.templatePath('AuthenticationDefaults.cs'), this.applicationName + '/' + this.name + 'AuthenticationDefaults.cs', this.templateData)
this.fs.copyTpl(this.templatePath('AuthenticationExtensions.cs'), this.applicationName + '/' + this.name + 'AuthenticationExtensions.cs', this.templateData)
this.fs.copyTpl(this.templatePath('AuthenticationHandler.cs'), this.applicationName + '/' + this.name + 'AuthenticationHandler.cs', this.templateData)
this.fs.copyTpl(this.templatePath('AuthenticationOptions.cs'), this.applicationName + '/' + this.name + 'AuthenticationOptions.cs', this.templateData)
this.fs.copyTpl(
this.templatePath('Project.csproj'),
this.applicationName + '/' + this.applicationName + '.csproj',
this.templateData
);
this.fs.copyTpl(
this.templatePath('AuthenticationDefaults.cs'),
this.applicationName + '/' + this.name + 'AuthenticationDefaults.cs',
this.templateData
);
this.fs.copyTpl(
this.templatePath('AuthenticationExtensions.cs'),
this.applicationName + '/' + this.name + 'AuthenticationExtensions.cs',
this.templateData
);
this.fs.copyTpl(
this.templatePath('AuthenticationHandler.cs'),
this.applicationName + '/' + this.name + 'AuthenticationHandler.cs',
this.templateData
);
this.fs.copyTpl(
this.templatePath('AuthenticationOptions.cs'),
this.applicationName + '/' + this.name + 'AuthenticationOptions.cs',
this.templateData
);
}

async getCurrentVersion() {

let response = await fetch('https://api.nuget.org/v3/index.json');

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

const serviceIndex = await response.json();
const baseAddress = serviceIndex.resources.find(resource => resource['@type'] === 'SearchQueryService/3.5.0')['@id'];
const baseAddress = serviceIndex.resources.find(
(resource) => resource['@type'] === 'SearchQueryService/3.5.0'
)['@id'];

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

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

if (!response.ok) {
throw new Error(`Failed to search for NuGet package from '${searchUrl}'. HTTP status code: ${response.status}.`);
throw new Error(
`Failed to search for NuGet package from '${searchUrl}'. HTTP status code: ${response.status}.`
);
}

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

return versionParts.join(dot);
}
};
}
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"url": "https://github.com/jerriep"
},
"scripts": {
"test": "mocha"
"format": "prettier --write **/*.js",
"format-check": "prettier --check **/*.js",
"test": "mocha",
"all": "npm run format && npm test"
},
"files": [
"generators"
Expand All @@ -32,14 +35,26 @@
"dependencies": {
"cross-fetch": "^4.1.0",
"query-string": "^9.2.2",
"yosay": "^3.0.0",
"yeoman-generator": "^7.5.1"
"yeoman-generator": "^7.5.1",
"yosay": "^3.0.0"
},
"devDependencies": {
"glob": "^11.0.3",
"mocha": "^11.7.1",
"prettier": "3.6.2",
"yeoman-assert": "^3.1.1",
"yeoman-environment": "^4.4.3",
"yeoman-test": "^10.1.1"
},
"prettier": {
"arrowParens": "always",
"bracketSpacing": true,
"printWidth": 100,
"quoteProps": "consistent",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
}
57 changes: 42 additions & 15 deletions test/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const __dirname = path.dirname(__filename);
describe('aspnet-oauth:app', () => {
before(async function () {
this.timeout(10000);
await helpers.run(path.join(__dirname, '../generators/app'))
await helpers
.run(path.join(__dirname, '../generators/app'))
.withOptions({ skipInstall: true })
.withAnswers({
name: 'Foo',
authorname: 'John Smith',
authorizationendpoint: 'https://foo.local/auth',
tokenendpoint: 'https://foo.local/token',
userinformationendpoint: 'https://foo.local/user'
userinformationendpoint: 'https://foo.local/user',
});
});

Expand All @@ -31,7 +32,7 @@ describe('aspnet-oauth:app', () => {
'AspNet.Security.OAuth.Foo/FooAuthenticationDefaults.cs',
'AspNet.Security.OAuth.Foo/FooAuthenticationExtensions.cs',
'AspNet.Security.OAuth.Foo/FooAuthenticationHandler.cs',
'AspNet.Security.OAuth.Foo/FooAuthenticationOptions.cs'
'AspNet.Security.OAuth.Foo/FooAuthenticationOptions.cs',
]);
});
it('sets the authors name', () => {
Expand Down Expand Up @@ -144,7 +145,6 @@ describe('aspnet-oauth:app', () => {
});

describe('generating a new provider', () => {

const projectName = 'AspNet.Security.OAuth.Foo';
const tempDir = path.join(os.tmpdir(), `_generator-aspnet-oauth-${Math.random()}`);
const artifactsDir = path.join(tempDir, 'artifacts');
Expand All @@ -156,32 +156,36 @@ describe('aspnet-oauth:app', () => {
this.timeout(180000);

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

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

// Run the generator to create the project
context = await helpers.run(path.join(__dirname, '../generators/app'), { tmpdir: false })
context = await helpers
.run(path.join(__dirname, '../generators/app'), { tmpdir: false })
.cd(sourceDir)
.withOptions({ skipInstall: true })
.withPrompts({
name: 'Foo',
authorname: 'John Smith',
authorizationendpoint: 'https://foo.local/auth',
tokenendpoint: 'https://foo.local/token',
userinformationendpoint: 'https://foo.local/user'
userinformationendpoint: 'https://foo.local/user',
});

// Add the new project to the solution
const dotnetSlnAdd = spawnSync(
`dotnet`,
['sln', 'add', path.join(projectDir, `${projectName}.csproj`)],
{ cwd: tempDir });
{ cwd: tempDir }
);

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

if (process.platform === 'win32') {
build = spawnSync('build.cmd', ['-test', '-pack', '-configuration', configuration], { cwd: tempDir, shell: true });
build = spawnSync('build.cmd', ['-test', '-pack', '-configuration', configuration], {
cwd: tempDir,
shell: true,
});
} else {
build = spawnSync('./build.sh', ['--test', '--pack', '--configuration', configuration], { cwd: tempDir });
build = spawnSync('./build.sh', ['--test', '--pack', '--configuration', configuration], {
cwd: tempDir,
});
}

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

it('compiles the provider', async () => {
const expected = path.join(artifactsDir, 'bin', projectName, configuration, 'net*', `${projectName}.dll`);
const expected = path.join(
artifactsDir,
'bin',
projectName,
configuration,
'net*',
`${projectName}.dll`
);
await glob(expected);
});
it('generates the NuGet package', async () => {
const expected = path.join(artifactsDir, 'packages', configuration, 'Shipping', `${projectName}.*.nupkg`);
const expected = path.join(
artifactsDir,
'packages',
configuration,
'Shipping',
`${projectName}.*.nupkg`
);
await glob(expected);
});
it('runs the tests', async () => {
const expected = path.join(artifactsDir, 'TestResults', configuration, 'AspNet.Security.OAuth.Providers.Tests_net*_x64.html');
const expected = path.join(
artifactsDir,
'TestResults',
configuration,
'AspNet.Security.OAuth.Providers.Tests_net*_x64.html'
);
await glob(expected);
});
});
Expand Down