diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e82cdd..f42bdb4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Use Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x - name: Install run: npm install - name: Run typecheck @@ -29,12 +33,11 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] node-version: - - 20.10.0 - - 21.x + - 22.x steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install @@ -46,12 +49,11 @@ jobs: strategy: matrix: node-version: - - 20.10.0 - - 21.x + - 22.x steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install diff --git a/commands/make/middleware.ts b/commands/make/middleware.ts index a9750db..74ad8ef 100644 --- a/commands/make/middleware.ts +++ b/commands/make/middleware.ts @@ -4,7 +4,6 @@ import { stubsRoot } from '../../stubs/main.js' import { flags } from '@adonisjs/core/ace' import MakeMiddleware from '@adonisjs/core/commands/make/middleware' import stringHelpers from '@adonisjs/core/helpers/string' -import { slash } from '@adonisjs/core/helpers' import { COMMAND_PREFIX, MODULE_FLAG } from '../../src/constants.js' import { checkModule } from '../../src/utils.js' @@ -62,7 +61,7 @@ export default class MMakeMiddleware extends MakeMiddleware { * Creative relative path for the middleware file from * the "./app/middleware" directory */ - const middlewareRelativePath = slash( + const middlewareRelativePath = stringHelpers.toUnixSlash( relative(this.app.middlewarePath(), destination).replace(extname(destination), '') ) diff --git a/commands/make/provider.ts b/commands/make/provider.ts index 59dbbe6..dcb4f44 100644 --- a/commands/make/provider.ts +++ b/commands/make/provider.ts @@ -4,9 +4,9 @@ import { stubsRoot } from '../../stubs/main.js' import type { AppEnvironments } from '@adonisjs/core/types/app' import { flags } from '@adonisjs/core/ace' import MakeProvider from '@adonisjs/core/commands/make/provider' -import { slash } from '@adonisjs/core/helpers' import { COMMAND_PREFIX, MODULE_FLAG } from '../../src/constants.js' import { checkModule } from '../../src/utils.js' +import stringHelpers from '@adonisjs/core/helpers/string' const ALLOWED_ENVIRONMENTS = ['web', 'console', 'test', 'repl'] satisfies AppEnvironments[] @@ -74,7 +74,7 @@ export default class MMakeProvider extends MakeProvider { * Creative relative path for the provider file from * the "./start" directory */ - const providerRelativePath = slash( + const providerRelativePath = stringHelpers.toUnixSlash( relative(this.app.providersPath(), destination).replace(extname(destination), '') ) diff --git a/commands/make/transformer.ts b/commands/make/transformer.ts new file mode 100644 index 0000000..e651acd --- /dev/null +++ b/commands/make/transformer.ts @@ -0,0 +1,27 @@ +import { stubsRoot } from '../../stubs/main.ts' +import MakeTransformer from '@adonisjs/core/commands/make/transformer' +import { flags } from '@adonisjs/core/ace' +import { COMMAND_PREFIX, MODULE_FLAG } from '../../src/constants.ts' +import { checkModule } from '../../src/utils.ts' + +export default class MMakeTransformer extends MakeTransformer { + @flags.string(MODULE_FLAG) + declare module: string + + override async run() { + if (!this.module) { + return super.run() + } + + if (!checkModule(this.app, this.module)) { + this.kernel.exec(`${COMMAND_PREFIX}:module`, [this.module]) + } + const codemods = await this.createCodemods() + + await codemods.makeUsingStub(stubsRoot, this.stubPath, { + flags: this.parsed.flags, + entity: this.app.generators.createEntity(this.name), + model: this.app.generators.createEntity(this.name), + }) + } +} diff --git a/configure.ts b/configure.ts index 6b25904..be87c1b 100644 --- a/configure.ts +++ b/configure.ts @@ -12,7 +12,7 @@ | */ -import ConfigureCommand from '@adonisjs/core/commands/configure' +import type ConfigureCommand from '@adonisjs/core/commands/configure' export async function configure(command: ConfigureCommand) { const codemods = await command.createCodemods() diff --git a/package.json b/package.json index 6942639..053efd1 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@adonisjs-community/modules", "description": "", - "version": "1.1.0", + "version": "1.1.0-next.1", "engines": { - "node": ">=20.6.0" + "node": ">=22.0.0" }, "type": "module", "files": [ @@ -35,29 +35,29 @@ "author": "", "license": "MIT", "devDependencies": { - "@adonisjs/assembler": "^7.8.2", - "@adonisjs/core": "^6.12.0", - "@adonisjs/eslint-config": "2.0.0-beta.7", - "@adonisjs/lucid": "^21.7.0", - "@adonisjs/prettier-config": "^1.4.0", - "@adonisjs/tsconfig": "^1.3.0", - "@japa/assert": "^3.0.0", - "@japa/runner": "^3.1.4", - "@swc/core": "^1.6.3", - "@types/node": "^20.14.5", - "c8": "^10.1.2", + "@adonisjs/assembler": "^8.4.0", + "@adonisjs/core": "^7.3.1", + "@adonisjs/eslint-config": "3.0.0", + "@adonisjs/lucid": "^22.4.2", + "@adonisjs/prettier-config": "^1.4.5", + "@adonisjs/tsconfig": "^2.0.0", + "@japa/assert": "^4.2.0", + "@japa/runner": "^5.3.0", + "@swc/core": "^1.15.26", + "@types/node": "^20.19.39", + "c8": "^10.1.3", "copyfiles": "^2.4.1", "del-cli": "^5.1.0", - "eslint": "^9.15.0", - "np": "^10.0.6", - "prettier": "^3.3.2", - "ts-node-maintained": "^10.9.4", - "tsup": "^8.5.0", - "typescript": "^5.4.5", - "release-it": "^19.0.3" + "eslint": "^9.39.4", + "np": "^10.3.0", + "prettier": "^3.8.3", + "release-it": "^19.2.4", + "ts-node-maintained": "^10.9.6", + "tsup": "^8.5.1", + "typescript": "^5.9.3" }, "peerDependencies": { - "@adonisjs/core": "^6.2.0" + "@adonisjs/core": "^7.0.0-next.23" }, "publishConfig": { "access": "public", diff --git a/src/utils.ts b/src/utils.ts index 6b3cfdc..01f7236 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' import stringHelpers from '@adonisjs/core/helpers/string' -import { ApplicationService } from '@adonisjs/core/types' +import type { ApplicationService } from '@adonisjs/core/types' import { readFileSync, writeFileSync } from 'node:fs' export function checkModule(app: ApplicationService, value: string): boolean { diff --git a/stubs/main.ts b/stubs/main.ts index e3365fb..4949118 100644 --- a/stubs/main.ts +++ b/stubs/main.ts @@ -1,8 +1,7 @@ -import { getDirname } from '@adonisjs/core/helpers' import path from 'node:path' /** * Path to the root directory where the stubs are stored. We use * this path within commands and the configure hook */ -export const stubsRoot = path.join(getDirname(import.meta.url), 'stubs') +export const stubsRoot = path.join(import.meta.dirname, 'stubs') diff --git a/stubs/make/model/main.stub b/stubs/make/model/main.stub index a5062d4..060319c 100644 --- a/stubs/make/model/main.stub +++ b/stubs/make/model/main.stub @@ -1,4 +1,5 @@ {{#var modelName = generators.modelName(entity.name)}} +{{#var modelSchemaName = `${modelName}Schema` }} {{#var modelFileName = generators.modelFileName(entity.name)}} {{#var moduleDirectoryName = flags.module}} {{{ @@ -6,16 +7,7 @@ to: app.makePath('app', moduleDirectoryName, 'models', modelFileName) }) }}} -import { DateTime } from 'luxon' -import { BaseModel, column } from '@adonisjs/lucid/orm' +import { {{ modelSchemaName }} } from '#database/schema' -export default class {{ modelName }} extends BaseModel { - @column({ isPrimary: true }) - declare id: number - - @column.dateTime({ autoCreate: true }) - declare createdAt: DateTime - - @column.dateTime({ autoCreate: true, autoUpdate: true }) - declare updatedAt: DateTime +export default class {{ modelName }} extends {{ modelSchemaName }} { } \ No newline at end of file diff --git a/stubs/make/transformer/main.stub b/stubs/make/transformer/main.stub new file mode 100644 index 0000000..ba662d6 --- /dev/null +++ b/stubs/make/transformer/main.stub @@ -0,0 +1,18 @@ +{{#var transformerName = generators.transformerName(entity.name)}} +{{#var transformerFileName = generators.transformerFileName(entity.name)}} +{{#var modelName = generators.modelName(model.name)}} +{{#var modelFileName = generators.modelFileName(model.name)}} +{{#var moduleDirectoryName = flags.module}} +{{{ + exports({ + to: app.makePath('app', moduleDirectoryName, 'transformers', transformerFileName) + }) +}}} +import { BaseTransformer } from '@adonisjs/core/transformers' +import {{ modelName }} from '{{ app.makePath('app', moduleDirectoryName, 'models', modelFileName) }}' + +export default class {{ transformerName }} extends BaseTransformer<{{modelName}}> { + toObject() { + return this.pick(this.resource, ['id']) + } +} \ No newline at end of file