5
5
6
6
const path = require ( 'path' ) ;
7
7
const fs = require ( 'fs' ) ;
8
- const prettier = require ( 'prettier' ) ;
9
- const typesFile = 'page-builder-types/index.d.ts' ;
10
- const copyrightComment = `/**
8
+ const prettier = require ( 'prettier' ) ,
9
+ typesFile = 'page-builder-types/index.d.ts' ,
10
+ copyrightComment = `/**
11
11
* Copyright © Magento, Inc. All rights reserved.
12
12
* See COPYING.txt for license details.
13
13
*/` ;
@@ -18,6 +18,7 @@ const copyrightComment = `/**
18
18
* @param {string } currentModuleId
19
19
* @returns {string }
20
20
*/
21
+ // eslint-disable-next-line strict
21
22
function resolveModuleIdToMagentoPath ( currentModuleId ) {
22
23
return currentModuleId . replace (
23
24
'app/code/Magento/PageBuilder/view/adminhtml/web/ts/' ,
@@ -29,9 +30,11 @@ function resolveModuleIdToMagentoPath(currentModuleId) {
29
30
require ( 'dts-generator' ) . default ( {
30
31
project : './' ,
31
32
out : typesFile ,
33
+ // eslint-disable-next-line strict
32
34
resolveModuleId : ( params ) => {
33
35
return resolveModuleIdToMagentoPath ( params . currentModuleId ) ;
34
36
} ,
37
+ // eslint-disable-next-line strict
35
38
resolveModuleImport : ( params ) => {
36
39
// Convert relative imports into their Magento counterparts
37
40
if ( params . importedModuleId . startsWith ( '../' ) || params . importedModuleId . startsWith ( './' ) ) {
@@ -48,11 +51,13 @@ require('dts-generator').default({
48
51
49
52
return params . importedModuleId ;
50
53
}
54
+ // eslint-disable-next-line strict
51
55
} ) . then ( ( ) => {
52
- const { exec } = require ( 'child_process' ) ;
53
- // Lint the generated file
54
- const lint = exec ( `./node_modules/tslint/bin/tslint --fix ${ typesFile } ` ) ;
55
- lint . on ( "exit" , ( ) => {
56
+ const { exec } = require ( 'child_process' ) ,
57
+ // Lint the generated file
58
+ lint = exec ( `./node_modules/tslint/bin/tslint --fix ${ typesFile } ` ) ;
59
+
60
+ lint . on ( 'exit' , ( ) => {
56
61
// Replace all tab characters with 4 spaces
57
62
fs . readFile ( typesFile , 'utf-8' , ( error , contents ) => {
58
63
if ( error ) {
@@ -61,9 +66,10 @@ require('dts-generator').default({
61
66
let modifiedContents = contents
62
67
. replace ( / .* \/ \* \* \n .* C o p y r i g h t © M a g e n t o .* \n .* \n .* \* \/ / gm, '' ) // Strip all Magento copyright
63
68
. replace ( / .* \/ \* \* \n .* @ a p i .* \n .* \* \/ / gm, '' ) ; // Strip all @api comments
69
+
64
70
modifiedContents = `${ copyrightComment } \n${ modifiedContents } ` ;
65
- fs . writeFile ( typesFile , prettier . format ( modifiedContents , { parser : " typescript" } ) , null , ( ) => {
66
- console . log ( " Type definition generation completed." ) ;
71
+ fs . writeFile ( typesFile , prettier . format ( modifiedContents , { parser : ' typescript' } ) , null , ( ) => {
72
+ console . log ( ' Type definition generation completed.' ) ;
67
73
process . exit ( ) ;
68
74
} ) ;
69
75
} ) ;
0 commit comments