Skip to content

Commit

Permalink
refactor: introduce monorepo to Generator Repo (#1213)
Browse files Browse the repository at this point in the history
Co-authored-by: AyushNautiyalDeveloper <ayush@betalectic.com>%0ACo-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>%0ACo-authored-by: Turbobot <turbobot@vercel.com>
  • Loading branch information
ayushnau and turbobot-temp authored Jun 20, 2024
1 parent 128c92c commit bc9dbec
Show file tree
Hide file tree
Showing 95 changed files with 8,371 additions and 10,275 deletions.
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.
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.
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 <fmvilas@gmail.com>",
"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.
File renamed without changes.
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.
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.
Loading

0 comments on commit bc9dbec

Please sign in to comment.