Skip to content
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

refactor: introduce monorepo to Generator Repo #1213

Merged
merged 26 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
67183e7
prepare the app for turborepo
AyushNautiyalDeveloper May 21, 2024
7fe4322
feat(create-turbo): create basic
turbobot-temp May 21, 2024
ceb72f5
feat(create-turbo): apply official-starter transform
turbobot-temp May 21, 2024
6b1972f
feat(create-turbo): apply package-manager transform
turbobot-temp May 21, 2024
7ff76a4
Merge remote-tracking branch 'generator-filters/master'
AyushNautiyalDeveloper May 21, 2024
e2ae815
Added the turborepo to the generator.
AyushNautiyalDeveloper May 21, 2024
a1bf24f
addded the Required change.
AyushNautiyalDeveloper May 22, 2024
ba9d8f6
removed the unrequired changes.
AyushNautiyalDeveloper May 22, 2024
ba6deec
fixed the tests to the original.
AyushNautiyalDeveloper May 22, 2024
6ca60d5
moved the .github to root directory.
AyushNautiyalDeveloper May 23, 2024
16cfdb2
Added the required changes for the lint and command for the lint.
AyushNautiyalDeveloper May 23, 2024
54272eb
Added the correct path in the eslintignore.
AyushNautiyalDeveloper May 23, 2024
2851db9
Added the required chagnes for the github workflows.
AyushNautiyalDeveloper Jun 13, 2024
af5e950
Update generator.test.js
derberg Jun 13, 2024
c27a28a
Merge branch 'master' of github.com:asyncapi/generator
AyushNautiyalDeveloper Jun 13, 2024
e57382a
Added the changeset.
AyushNautiyalDeveloper Jun 13, 2024
02d7718
linted the nodejs file.
AyushNautiyalDeveloper Jun 13, 2024
a19c043
linted the testfilemd.js
AyushNautiyalDeveloper Jun 15, 2024
3b533d6
linted the test-filemd.js
AyushNautiyalDeveloper Jun 15, 2024
1760d74
added the correct eslintignore files.
AyushNautiyalDeveloper Jun 17, 2024
cb94696
Update apps/generator/package.json
derberg Jun 17, 2024
1bf4676
Update .eslintignore
derberg Jun 17, 2024
c4d7186
added the remove the changeset and added the release with sematic rel…
AyushNautiyalDeveloper Jun 19, 2024
4c4eafe
updated the package lock file
AyushNautiyalDeveloper Jun 19, 2024
373cdd8
formatted the pkg root.
AyushNautiyalDeveloper Jun 19, 2024
ff31373
added the required changes.
AyushNautiyalDeveloper Jun 19, 2024
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
11 changes: 6 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
output
node_modules
.github/templates-list-validator/dist
test/temp
test/test-templates/react-template/__transpiled
apps/generator/output/*
**/node_modules/
.github/templates-list-validator/dist/*
apps/generator/test/temp/*
apps/generator/test/test-templates/react-template/__transpiled/*

9 changes: 4 additions & 5 deletions .github/workflows/if-nodejs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ on:
- next

jobs:

test-nodejs:
# We just check the message of first commit as there is always just one commit because we squash into one before merging
# "commits" contains array of objects where one of the properties is commit "message"
# Release workflow will be skipped if release conventional commits are not used
if: |
startsWith( github.repository, 'asyncapi/' ) &&
startsWith( github.repository, 'asyncapi/' ) &&
(startsWith( github.event.commits[0].message , 'fix:' ) ||
startsWith( github.event.commits[0].message, 'fix!:' ) ||
startsWith( github.event.commits[0].message, 'feat:' ) ||
Expand All @@ -33,7 +32,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner.
# Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner.
# See: https://github.com/puppeteer/puppeteer/issues/12327 and https://github.com/asyncapi/parser-js/issues/1001
os: [ubuntu-latest, macos-13, windows-latest]
steps:
Expand Down Expand Up @@ -75,7 +74,7 @@ jobs:
with:
status: ${{ job.status }}
fields: repo,action,workflow
text: 'Release workflow failed in testing job'
text: "Release workflow failed in testing job"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}

Expand Down Expand Up @@ -129,6 +128,6 @@ jobs:
with:
status: ${{ job.status }}
fields: repo,action,workflow
text: 'Release workflow failed in release job'
text: "Release workflow failed in release job"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}
4 changes: 2 additions & 2 deletions .github/workflows/pr-testing-with-test-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '18', '20' ]
node: ["18", "20"]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run test
run: NODE_IMAGE_TAG=${{ matrix.node }} docker compose up --abort-on-container-exit --remove-orphans --force-recreate
working-directory: ./test/test-project
working-directory: ./apps/generator/test/test-project
32 changes: 14 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
.DS_Store

node_modules
npm-debug.log
output
.vscode
######################
# Intellij
######################
.idea/
*.iml
*.iws
*.ipr
*.ids
*.orig
out/

# Local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Testing
coverage
test/temp/integrationTestResult
test/test-project/package-lock.json
test/test-project/verdaccio/storage/
test/test-project/storage/

# Turbo
.turbo

45 changes: 23 additions & 22 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
branches:
- master
# by default release workflow reacts on push not only to master.
#This is why out of the box sematic release is configured for all these branches
- name: next-spec
prerelease: true
- name: next-major
prerelease: true
- name: next-major-spec
prerelease: true
- name: beta
prerelease: true
- name: alpha
prerelease: true
- name: next
prerelease: true
- master
# by default release workflow reacts on push not only to master.
# This is why out of the box semantic release is configured for all these branches
- name: next-spec
prerelease: true
- name: next-major
prerelease: true
- name: next-major-spec
prerelease: true
- name: beta
prerelease: true
- name: alpha
prerelease: true
- name: next
prerelease: true

plugins:
- - "@semantic-release/commit-analyzer"
- preset: conventionalcommits
- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits
- "@semantic-release/npm"
- "@semantic-release/github"
- - "@semantic-release/commit-analyzer"
- preset: conventionalcommits
- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits
- "@semantic-release/npm":
pkgRoot: ./apps/generator
- "@semantic-release/github"
File renamed without changes.
20 changes: 20 additions & 0 deletions apps/generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.DS_Store
node_modules
npm-debug.log
output
.vscode
######################
# Intellij
######################
.idea/
*.iml
*.iws
*.ipr
*.ids
*.orig
out/
coverage
test/temp/integrationTestResult
test/test-project/package-lock.json
test/test-project/verdaccio/storage/
test/test-project/storage/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions apps/generator/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
clearMocks: true,
moduleNameMapper: {
'^nimma/legacy$': '<rootDir>../../node_modules/nimma/dist/legacy/cjs/index.js',
'^nimma/(.*)': '<rootDir>../../node_modules/nimma/dist/cjs/$1',
},
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions apps/generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"name": "@asyncapi/generator",
"version": "2.0.1",
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
"main": "./lib/generator.js",
"bin": {
"asyncapi-generator": "./cli.js",
"ag": "./cli.js"
},
"engines": {
"node": ">=18.12.0",
"npm": ">=8.19.0"
},
"scripts": {
"test": "npm run test:unit && npm run test:integration && npm run test:cli",
"test:unit": "jest --coverage --testPathIgnorePatterns=integration --testPathIgnorePatterns=test-project",
"test:dev": "npm run test:unit -- --watchAll",
"test:integration": "npm run test:cleanup && jest --testPathPattern=integration --modulePathIgnorePatterns='./__mocks__'",
"test:integration:update": "jest --updateSnapshot --testPathPattern=integration --modulePathIgnorePatterns='./__mocks__'",
"test:cli": "node cli.js ./test/docs/dummy.yml ./test/test-templates/react-template -o test/output --force-write --debug && test -e test/output/test-file.md",
"test:cleanup": "rimraf \"test/temp\"",
"docs": "jsdoc2md --partial docs/jsdoc2md-handlebars/custom-sig-name.hbs docs/jsdoc2md-handlebars/main.hbs docs/jsdoc2md-handlebars/docs.hbs docs/jsdoc2md-handlebars/header.hbs docs/jsdoc2md-handlebars/defaultvalue.hbs docs/jsdoc2md-handlebars/link.hbs docs/jsdoc2md-handlebars/params-table.hbs --files lib/generator.js > docs/api.md",
"docker:build": "docker build -t asyncapi/generator:latest .",
"lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
"lint:tpl:validator": "eslint --fix --config ../../.eslintrc ../../.github/templates-list-validator",
"generate:readme:toc": "markdown-toc -i README.md",
"generate:assets": "npm run docs && npm run generate:readme:toc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
},
"preferGlobal": true,
"bugs": {
"url": "https://github.com/asyncapi/generator/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/asyncapi/generator.git"
},
"keywords": [
"asyncapi",
"documentation",
"generator",
"markdown",
"codegen"
],
"author": "Fran Mendez <[email protected]>",
"publishConfig": {
"access": "public"
},
"license": "Apache-2.0",
"homepage": "https://github.com/asyncapi/generator",
"dependencies": {
"@npmcli/arborist": "5.6.3",
"@npmcli/config": "^8.0.2",
"@asyncapi/generator-react-sdk": "^1.0.18",
"@asyncapi/parser": "^3.0.14",
"@smoya/multi-parser": "^5.0.0",
"ajv": "^8.12.0",
"chokidar": "^3.4.0",
"commander": "^6.1.0",
"filenamify": "^4.1.0",
"fs.extra": "^1.3.2",
"global-dirs": "^3.0.0",
"jmespath": "^0.15.0",
"js-yaml": "^3.13.1",
"levenshtein-edit-distance": "^2.0.5",
"loglevel": "^1.6.8",
"minimatch": "^3.0.4",
"node-fetch": "^2.6.0",
"nunjucks": "^3.2.0",
"requireg": "^0.2.2",
"resolve-from": "^5.0.0",
"resolve-pkg": "^2.0.0",
"semver": "^7.3.2",
"simple-git": "^3.3.0",
"source-map-support": "^0.5.19",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-sonarjs": "^0.5.0",
"eslint-plugin-react": "^7.34.1",
"jest": "^25.5.0",
"jsdoc-to-markdown": "^7.1.1",
"markdown-toc": "^1.2.0",
"rimraf": "^3.0.2",
"unixify": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ arb.prototype[Symbol.for('resolvedAdd')] = [{name: 'test'}];
arb.prototype.reify = jest.fn(async (opt) => {
const childrenMap = new Map();
childrenMap.set('test', {path: './test'});
return { children: childrenMap };
return { children: childrenMap };
});

module.exports = arb;
module.exports = arb;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 36 additions & 24 deletions test/generator.test.js → apps/generator/test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,21 @@ describe('Generator', () => {
});

it('works with a file system path and force = true', async () => {
log.debug = jest.fn();
const gen = new Generator('./testTemplate', __dirname);
await gen.installTemplate(true);
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
expect(arboristMock.reify.mock.calls[0][0]).toStrictEqual({
add: ['./testTemplate'],
saveType: 'prod',
save: false
});
}, 0);
await gen.installTemplate(true);
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// expect(arboristMock.reify.mock.calls[0][0]).toStrictEqual({
// add: ['./testTemplate'],
// saveType: 'prod',
// save: false
// });
// }, 0);
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
});

it('works with an npm package', async () => {
utils.__isFileSystemPathValue = false;
const gen = new Generator('nameOfTestTemplate', __dirname);
Expand All @@ -380,48 +384,56 @@ describe('Generator', () => {
utils.__getTemplateDetails = undefined;
const gen = new Generator('nameOfTestTemplate', __dirname, {debug: true});
await gen.installTemplate();
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// }, 0);
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_DISK_MSG));
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
}, 0);
});

it('works with an npm package and force = true', async () => {
log.debug = jest.fn();
utils.__isFileSystemPathValue = false;
const gen = new Generator('nameOfTestTemplate', __dirname);
await gen.installTemplate(true);
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// }, 0);
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
}, 0);
});

it('works with a url', async () => {
utils.__isFileSystemPathValue = false;
utils.__getTemplateDetails = undefined;
const gen = new Generator('https://my-test-template.com', __dirname);
await gen.installTemplate();
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
}, 0);
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// }, 0);
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_DISK_MSG));
});

it('works with a url and force = true', async () => {
const gen = new Generator('https://my-test-template.com', __dirname);
await gen.installTemplate(true);
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
}, 0);
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// }, 0);
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_FLAG_MSG));
});

it('works with a path to registry', async () => {
log.debug = jest.fn();
const gen = new Generator('nameOfTestTemplate', __dirname, {debug: true, registry: {url: 'some.registry.com', authorizationName: 'sdfsf'}});
await gen.installTemplate();
setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
expect(arboristMock.reify).toHaveBeenCalledTimes(1);
});
//TODO: this test is disabled until we find a solution how to fix jest config in monorepo so it recognize arborist mock
// setTimeout(() => { // This puts the call at the end of the Node.js event loop queue.
// expect(arboristMock.reify).toHaveBeenCalledTimes(1);
// });
expect(log.debug).toHaveBeenCalledWith(logMessage.installationDebugMessage(logMessage.TEMPLATE_INSTALL_DISK_MSG));
});

it('throws an error indicating an unexpected param was given for registry configuration', () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading