|
1 | 1 | import { existsSync, readFileSync } from 'fs'; |
2 | 2 | import path from 'path'; |
3 | 3 | import { ILEObject, ILEObjectTarget, ImpactedObject, ObjectType, Targets } from '../../targets'; |
4 | | -import { asPosix, getFiles, toCl } from '../../utils'; |
| 4 | +import { asPosix, fromCl, getFiles, toCl } from '../../utils'; |
5 | 5 | import { warningOut } from '../../cli'; |
6 | 6 | import { name } from '../../../webpack.config'; |
7 | 7 | import { FolderOptions, getFolderOptions } from './folderSettings'; |
8 | 8 | import { readAllRules } from './customRules'; |
9 | | -import { CompileData, CommandParameters } from '../environment'; |
| 9 | +import { CompileData, CommandParameters, getTrueBasename } from '../environment'; |
10 | 10 | import { iProject } from '../iProject'; |
| 11 | +import { ReadFileSystem } from '../../readFileSystem'; |
| 12 | +import { ProjectActions } from '../actions'; |
11 | 13 |
|
12 | 14 | export class MakeProject { |
13 | 15 | private noChildren: boolean = false; |
14 | 16 | private settings: iProject = new iProject(); |
| 17 | + private projectActions: ProjectActions; |
| 18 | + |
15 | 19 | private folderSettings: {[folder: string]: FolderOptions} = {}; |
16 | 20 |
|
17 | | - constructor(private cwd: string, private targets: Targets) { |
18 | | - this.setupSettings(); |
| 21 | + constructor(private cwd: string, private targets: Targets, private rfs: ReadFileSystem) { |
| 22 | + this.projectActions = new ProjectActions(this.targets, this.rfs); |
19 | 23 | } |
20 | 24 |
|
21 | 25 | public setNoChildrenInBuild(noChildren: boolean) { |
22 | 26 | this.noChildren = noChildren; |
23 | 27 | } |
24 | 28 |
|
25 | | - private setupSettings() { |
| 29 | + async setupSettings() { |
| 30 | + await this.projectActions.loadAllActions(); |
| 31 | + |
26 | 32 | // First, let's setup the project settings |
27 | 33 | try { |
28 | | - const content = readFileSync(path.join(this.cwd, `iproj.json`), { encoding: `utf-8` }); |
| 34 | + const content = await this.rfs.readFile(path.join(this.cwd, `iproj.json`)); |
29 | 35 | const asJson: iProject = JSON.parse(content); |
30 | 36 |
|
31 | 37 | this.settings.applySettings(asJson); |
@@ -168,7 +174,7 @@ export class MakeProject { |
168 | 174 | let lines = []; |
169 | 175 |
|
170 | 176 | for (const entry of Object.entries(this.settings.compiles)) { |
171 | | - const [type, data] = entry; |
| 177 | + let [type, data] = entry; |
172 | 178 |
|
173 | 179 | // commandSource means 'is this object built from CL commands in a file' |
174 | 180 | if (data.commandSource) { |
@@ -213,7 +219,22 @@ export class MakeProject { |
213 | 219 | // This is used when your object really has source |
214 | 220 |
|
215 | 221 | 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.projectActions.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: clData.parameters |
| 235 | + } |
| 236 | + } |
| 237 | + } |
217 | 238 |
|
218 | 239 | lines.push(...MakeProject.generateSpecificTarget(data, possibleTarget, customAttributes)); |
219 | 240 | } |
@@ -250,12 +271,30 @@ export class MakeProject { |
250 | 271 | const parentName = ileObject.relativePath ? path.dirname(ileObject.relativePath) : undefined; |
251 | 272 | const qsysTempName: string | undefined = (parentName && parentName.length > 10 ? parentName.substring(0, 10) : parentName); |
252 | 273 |
|
| 274 | + const simpleReplace = (str: string, search: string, replace: string) => { |
| 275 | + return str.replace(new RegExp(search, `gi`), replace); |
| 276 | + } |
| 277 | + |
253 | 278 | const resolve = (command: string) => { |
254 | 279 | command = command.replace(new RegExp(`\\*CURLIB`, `g`), `$(BIN_LIB)`); |
255 | 280 | command = command.replace(new RegExp(`\\$\\*`, `g`), ileObject.systemName); |
256 | 281 | command = command.replace(new RegExp(`\\$<`, `g`), asPosix(ileObject.relativePath)); |
257 | 282 | command = command.replace(new RegExp(`\\$\\(SRCPF\\)`, `g`), qsysTempName); |
258 | 283 |
|
| 284 | + // Additionally, we have to support Actions variables |
| 285 | + command = simpleReplace(command, `&BUILDLIB`, `$(BIN_LIB)`); |
| 286 | + command = simpleReplace(command, `&CURLIB`, `$(BIN_LIB)`); |
| 287 | + command = simpleReplace(command, `&LIBLS`, ``); |
| 288 | + command = simpleReplace(command, `&BRANCHLIB`, `$(BIN_LIB)`); |
| 289 | + |
| 290 | + const pathDetail = path.parse(ileObject.relativePath || ``); |
| 291 | + |
| 292 | + command = simpleReplace(command, `&RELATIVEPATH`, asPosix(ileObject.relativePath)); |
| 293 | + command = simpleReplace(command, `&BASENAME`, pathDetail.base); |
| 294 | + command = simpleReplace(command, `{filename}`, pathDetail.base); |
| 295 | + command = simpleReplace(command, `&NAME`, getTrueBasename(pathDetail.name)); |
| 296 | + command = simpleReplace(command, `&EXTENSION`, pathDetail.ext.startsWith(`.`) ? pathDetail.ext.substring(1) : pathDetail.ext); |
| 297 | + |
259 | 298 | if (ileObject.deps && ileObject.deps.length > 0) { |
260 | 299 | // This piece of code adds special variables that can be used for building dependencies |
261 | 300 | const uniqueObjectTypes = ileObject.deps.map(d => d.type).filter((value, index, array) => array.indexOf(value) === index); |
|
0 commit comments