11import { existsSync , readFileSync } from 'fs' ;
22import path from 'path' ;
33import { ILEObject , ILEObjectTarget , ImpactedObject , ObjectType , Targets } from '../../targets' ;
4- import { asPosix , getFiles , toCl } from '../../utils' ;
4+ import { asPosix , fromCl , getFiles , toCl } from '../../utils' ;
55import { warningOut } from '../../cli' ;
66import { name } from '../../../webpack.config' ;
77import { FolderOptions , getFolderOptions } from './folderSettings' ;
88import { readAllRules } from './customRules' ;
99import { CompileData , CommandParameters } from '../environment' ;
1010import { iProject } from '../iProject' ;
11+ import { ReadFileSystem } from '../../readFileSystem' ;
12+ import { ProjectActions } from '../actions' ;
1113
1214export class MakeProject {
1315 private noChildren : boolean = false ;
1416 private settings : iProject = new iProject ( ) ;
17+ private actions : ProjectActions ;
18+
1519 private folderSettings : { [ folder : string ] : FolderOptions } = { } ;
1620
17- constructor ( private cwd : string , private targets : Targets ) {
18- this . setupSettings ( ) ;
21+ constructor ( private cwd : string , private targets : Targets , private rfs : ReadFileSystem ) {
22+ this . actions = new ProjectActions ( this . targets , this . rfs ) ;
1923 }
2024
2125 public setNoChildrenInBuild ( noChildren : boolean ) {
2226 this . noChildren = noChildren ;
2327 }
2428
25- private setupSettings ( ) {
29+ async setupSettings ( ) {
2630 // First, let's setup the project settings
2731 try {
28- const content = readFileSync ( path . join ( this . cwd , `iproj.json` ) , { encoding : `utf-8` } ) ;
32+ const content = await this . rfs . readFile ( path . join ( this . cwd , `iproj.json` ) ) ;
2933 const asJson : iProject = JSON . parse ( content ) ;
3034
3135 this . settings . applySettings ( asJson ) ;
@@ -37,6 +41,8 @@ export class MakeProject {
3741 this . folderSettings = getFolderOptions ( this . cwd ) ;
3842
3943 readAllRules ( this . targets , this ) ;
44+
45+ await this . actions . loadAllActions ( ) ;
4046 }
4147
4248 public getSettings ( ) {
@@ -168,7 +174,7 @@ export class MakeProject {
168174 let lines = [ ] ;
169175
170176 for ( const entry of Object . entries ( this . settings . compiles ) ) {
171- const [ type , data ] = entry ;
177+ let [ type , data ] = entry ;
172178
173179 // commandSource means 'is this object built from CL commands in a file'
174180 if ( data . commandSource ) {
@@ -213,7 +219,24 @@ export class MakeProject {
213219 // This is used when your object really has source
214220
215221 const possibleTarget : ILEObjectTarget = this . targets . getTarget ( ileObject ) || ( ileObject as ILEObjectTarget ) ;
216- const customAttributes = this . getObjectAttributes ( data , possibleTarget ) ;
222+ let customAttributes = this . getObjectAttributes ( data , possibleTarget ) ;
223+
224+ if ( ileObject . relativePath ) {
225+ const possibleAction = this . actions . getActionForPath ( ileObject . relativePath ) ;
226+ if ( possibleAction ) {
227+ const clData = fromCl ( possibleAction . command ) ;
228+ // If there is an action for this object, we want to apply the action's parameters
229+ // to the custom attributes.
230+
231+ data = {
232+ ...data ,
233+ command : clData . command ,
234+ parameters : {
235+ ...data . parameters ,
236+ }
237+ }
238+ }
239+ }
217240
218241 lines . push ( ...MakeProject . generateSpecificTarget ( data , possibleTarget , customAttributes ) ) ;
219242 }
0 commit comments