Skip to content

Commit f895725

Browse files
Update dependency yeoman-generator to v7 (#328)
* Update dependency yeoman-generator to v7 * Fix --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Xiao <michael.xiao@smartcontract.com>
1 parent ba46fd3 commit f895725

File tree

9 files changed

+938
-2065
lines changed

9 files changed

+938
-2065
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
path_to_generator="$GITHUB_WORKSPACE/dist/src/generator-adapter"
8888
npm install -g yo@4.3.1
8989
# The command bellow will generate new EA with default name 'example-adapter' in specified directory 'examples'
90-
yo "$path_to_generator" examples
90+
yo "$path_to_generator" examples --ignore-version-check
9191
cd examples/example-adapter
9292
yarn build
9393
yarn test

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"prom-client": "13.2.0",
1616
"redlock": "5.0.0-beta.2",
1717
"ws": "8.18.0",
18-
"yeoman-generator": "3.2.0"
18+
"yeoman-generator": "7.3.3",
19+
"@yeoman/types": "1.5.0",
20+
"mem-fs": "4.1.1",
21+
"@yeoman/adapter": "1.6.0"
1922
},
2023
"scripts": {
2124
"build": "mkdir -p ./dist/src && cp package.json dist/src && cp README.md dist/src && tsc && yarn build-generator",
@@ -39,7 +42,6 @@
3942
"@types/node": "22.10.1",
4043
"@types/sinonjs__fake-timers": "8.1.5",
4144
"@types/ws": "8.5.13",
42-
"@types/yeoman-generator": "5.2.14",
4345
"@typescript-eslint/eslint-plugin": "8.16.0",
4446
"@typescript-eslint/parser": "8.16.0",
4547
"ava": "6.2.0",

scripts/adapter-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import { execSync } from 'child_process'
66
const pathArg = process.argv[2] || ''
77

88
const generatorPath = resolve(__dirname, './generator-adapter')
9-
const generatorCommand = `yo ${generatorPath} ${pathArg} `
9+
const generatorCommand = `yo ${generatorPath} ${pathArg} --ignore-version-check`
1010

1111
execSync(generatorCommand, { stdio: 'inherit' })

scripts/generator-adapter/generators/app/index.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import * as Generator from 'yeoman-generator'
2+
import { exec } from 'child_process'
3+
4+
import { createRequire } from 'node:module';
5+
const require = createRequire(import.meta.url);
26

37
interface InputTransport {
48
type: string
@@ -18,8 +22,7 @@ interface GeneratorEndpointContext {
1822
normalizedEndpointNameCap: string
1923
}
2024

21-
22-
module.exports = class extends Generator<{rootPath: string}> {
25+
export default class extends Generator.default {
2326
props: {
2427
// Current ea-framework version in package.json
2528
frameworkVersion: string
@@ -43,7 +46,7 @@ module.exports = class extends Generator<{rootPath: string}> {
4346
standalone = process.env.EXTERNAL_ADAPTER_GENERATOR_STANDALONE === 'true'
4447

4548
constructor(args, opts) {
46-
super(args, opts)
49+
super(args, opts, { customInstallTask: true })
4750
this.argument('rootPath', {
4851
type: String,
4952
required: false,
@@ -85,7 +88,7 @@ module.exports = class extends Generator<{rootPath: string}> {
8588
this.props = {
8689
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8790
// @ts-ignore
88-
frameworkVersion: (await import('../../../package.json')).version,
91+
frameworkVersion: (await require('../../../package.json')).version,
8992
adapterName,
9093
endpoints,
9194
endpointNames,
@@ -117,22 +120,22 @@ module.exports = class extends Generator<{rootPath: string}> {
117120
baseFiles.forEach(fileName => {
118121
this.fs.copyTpl(
119122
this.templatePath(fileName),
120-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/${fileName}`),
123+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/${fileName}`),
121124
{...this.props, standalone: this.standalone}
122125
)
123126
})
124127

125128
// copy main index.ts file
126129
this.fs.copyTpl(
127130
this.templatePath(`src/index.ts.ejs`),
128-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/index.ts`),
131+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/index.ts`),
129132
this.props
130133
)
131134

132135
// Copy overrides
133136
this.fs.copyTpl(
134137
this.templatePath('src/config/overrides.json'),
135-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/config/overrides.json`),
138+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/config/overrides.json`),
136139
this.props,
137140
)
138141

@@ -142,7 +145,7 @@ module.exports = class extends Generator<{rootPath: string}> {
142145
// Router endpoints
143146
this.fs.copyTpl(
144147
this.templatePath('src/endpoint/endpoint-router.ts.ejs'),
145-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/endpoint/${inputEndpointName}.ts`),
148+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/endpoint/${inputEndpointName}.ts`),
146149
{
147150
inputEndpointName,
148151
inputTransports,
@@ -155,15 +158,15 @@ module.exports = class extends Generator<{rootPath: string}> {
155158
inputTransports.forEach(transport => {
156159
this.fs.copyTpl(
157160
this.templatePath(`src/transport/${transport.type}.ts.ejs`),
158-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/transport/${inputEndpointName}-${transport.type}.ts`),
161+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/transport/${inputEndpointName}-${transport.type}.ts`),
159162
{ inputEndpointName, includeComments: this.props.includeComments },
160163
)
161164
})
162165
} else {
163166
// Single transport endpoints
164167
this.fs.copyTpl(
165168
this.templatePath('src/endpoint/endpoint.ts.ejs'),
166-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/endpoint/${inputEndpointName}.ts`),
169+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/endpoint/${inputEndpointName}.ts`),
167170
{
168171
inputEndpointName,
169172
inputTransports,
@@ -175,7 +178,7 @@ module.exports = class extends Generator<{rootPath: string}> {
175178

176179
this.fs.copyTpl(
177180
this.templatePath(`src/transport/${inputTransports[0].type}.ts.ejs`),
178-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/transport/${inputEndpointName}.ts`),
181+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/transport/${inputEndpointName}.ts`),
179182
{ inputEndpointName, includeComments: this.props.includeComments },
180183
)
181184
}
@@ -184,7 +187,7 @@ module.exports = class extends Generator<{rootPath: string}> {
184187
// Create endpoint barrel file
185188
this.fs.copyTpl(
186189
this.templatePath(`src/endpoint/index.ts.ejs`),
187-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/endpoint/index.ts`),
190+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/endpoint/index.ts`),
188191
{ endpoints: Object.values(this.props.endpoints) },
189192
)
190193

@@ -196,7 +199,7 @@ module.exports = class extends Generator<{rootPath: string}> {
196199
// Copy config
197200
this.fs.copyTpl(
198201
this.templatePath('src/config/index.ts.ejs'),
199-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/src/config/index.ts`),
202+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/src/config/index.ts`),
200203
{setBgExecuteMsEnv: customBgEndpoints.length}
201204
)
202205

@@ -205,7 +208,7 @@ module.exports = class extends Generator<{rootPath: string}> {
205208
if (httpEndpoints.length) {
206209
this.fs.copyTpl(
207210
this.templatePath(`test/adapter.test.ts.ejs`),
208-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/test/integration/adapter.test.ts`),
211+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/test/integration/adapter.test.ts`),
209212
{ endpoints: httpEndpoints, transportName: 'rest', setBgExecuteMsEnv: false },
210213
)
211214
}
@@ -218,7 +221,7 @@ module.exports = class extends Generator<{rootPath: string}> {
218221
}
219222
this.fs.copyTpl(
220223
this.templatePath(`test/adapter-ws.test.ts.ejs`),
221-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/test/integration/${fileName}`),
224+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/test/integration/${fileName}`),
222225
{ endpoints: wsEndpoints },
223226
)
224227
}
@@ -234,7 +237,7 @@ module.exports = class extends Generator<{rootPath: string}> {
234237
}
235238
this.fs.copyTpl(
236239
this.templatePath(`test/adapter.test.ts.ejs`),
237-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/test/integration/${fileName}`),
240+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/test/integration/${fileName}`),
238241
{ endpoints: customFgEndpoints, transportName: 'customfg', setBgExecuteMsEnv: false },
239242
)
240243
}
@@ -245,15 +248,15 @@ module.exports = class extends Generator<{rootPath: string}> {
245248
}
246249
this.fs.copyTpl(
247250
this.templatePath(`test/adapter.test.ts.ejs`),
248-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/test/integration/${fileName}`),
251+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/test/integration/${fileName}`),
249252
{ endpoints: customBgEndpoints, transportName: 'custombg', setBgExecuteMsEnv: true },
250253
)
251254
}
252255

253256
// Copy test fixtures
254257
this.fs.copyTpl(
255258
this.templatePath(`test/fixtures.ts.ejs`),
256-
this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/test/integration/fixtures.ts`),
259+
this.destinationPath(`${this.args[0]}/${this.props.adapterName}/test/integration/fixtures.ts`),
257260
{
258261
includeWsFixtures: wsEndpoints.length > 0,
259262
includeHttpFixtures: httpEndpoints.length > 0 || customBgEndpoints.length > 0 || customFgEndpoints.length > 0,
@@ -290,17 +293,17 @@ module.exports = class extends Generator<{rootPath: string}> {
290293
pkgJson.scripts['test'] = 'EA_PORT=0 METRICS_ENABLED=false jest --updateSnapshot'
291294
}
292295

293-
this.fs.extendJSON(this.destinationPath(`${this.options.rootPath}/${this.props.adapterName}/package.json`), pkgJson)
296+
this.fs.extendJSON(this.destinationPath(`${this.args[0]}/${this.props.adapterName}/package.json`), pkgJson)
294297
}
295298

296299
// install stage is used to run npm or yarn install scripts
297-
install() {
298-
this.yarnInstall([], {cwd: `${this.options.rootPath}/${this.props.adapterName}`})
300+
async install() {
301+
await exec(`yarn install --cwd ${this.args[0]}/${this.props.adapterName}`);
299302
}
300303

301304
// end is the last stage. can be used for messages or cleanup
302305
end() {
303-
this.log(`🚀 Adapter '${this.props.adapterName}' was successfully created. 📍${this.options.rootPath}/${this.props.adapterName}`)
306+
this.log(`🚀 Adapter '${this.props.adapterName}' was successfully created. 📍${this.args[0]}/${this.props.adapterName}`)
304307
}
305308

306309
private async _promptAdapterName(): Promise<string> {

scripts/generator-adapter/generators/app/templates/src/endpoint/endpoint-router.ts.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import overrides from '../config/overrides.json'
88
import { <%= inputTransports[i].name %> } from '../transport/<%= inputEndpointName %>-<%= inputTransports[i].type %>' <% }
99
%>
1010
11-
<%- include ./base.ts.ejs %>
11+
<%- include ('base.ts.ejs') %>
1212
1313
export const endpoint = new AdapterEndpoint({
1414
<% if (includeComments) { -%>

scripts/generator-adapter/generators/app/templates/src/endpoint/endpoint.ts.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { config } from '../config'
55
import overrides from '../config/overrides.json'
66
import { <%= inputTransports[0].name %> } from '../transport/<%= inputEndpointName %>'
77

8-
<%- include ./base.ts.ejs %>
8+
<%- include ('base.ts.ejs') %>
99

1010
export const endpoint = new AdapterEndpoint({
1111
<% if (includeComments) { -%>

scripts/generator-adapter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"files": [
55
"generators"
66
],
7+
"type": "module",
78
"main": "generators/app/index.js",
89
"keywords": [
910
"yeoman-generator",

scripts/generator-adapter/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"compilerOptions": {
33
"rootDir": "./../",
44
"outDir": "../../dist/src",
5-
"target": "es2020",
5+
"target": "es2022",
66
"downlevelIteration": true,
7-
"esModuleInterop": false,
7+
"esModuleInterop": true,
88
"moduleResolution": "node",
9-
"module": "CommonJS",
9+
"module": "es2020",
1010
"resolveJsonModule": true
1111
},
1212
"files": [

0 commit comments

Comments
 (0)