Skip to content

Commit

Permalink
Node build tool for 0.97.0
Browse files Browse the repository at this point in the history
Port node build tool to 0.97
  • Loading branch information
Wyqer authored May 11, 2019
2 parents 15c8ec2 + 38bf27e commit 351e7ac
Show file tree
Hide file tree
Showing 12 changed files with 5,368 additions and 2 deletions.
26 changes: 25 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
jobs:
build:
validate:
docker:
- image: acemod/armake:master
steps:
Expand All @@ -11,3 +11,27 @@ jobs:
- run:
name: Validate Config style
command: python tools/config_style_checker.py

build:
docker:
- image: circleci/node
steps:
- checkout
- run:
name: Install dependencies
command: npm install --loglevel=error
working_directory: ~/project/tools/buildtool
- run:
name: Pack PBOs
command: npx gulp
working_directory: ~/project/tools/buildtool
- store_artifacts:
path: ~/project/_build/pbo
destination: 'KP-Liberation'

workflows:
version: 2
build:
jobs:
- build
- validate
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ Temporary Items
.apdisk

# Build directory
build/
_build/
node_modules/
24 changes: 24 additions & 0 deletions tools/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@echo off

rem Check that https://nodejs.org/en/download/ exists before continuing
where /q node
if ERRORLEVEL 1 (
echo node is missing. Ensure it is installed. It can be downloaded from:
echo https://nodejs.org/en/download/
timeout 30
exit /b
)

rem CD into build tool directory
cd %~dp0buildtool

rem Install dependencies and build missions
call npm install --loglevel=error
call npx gulp

cd ..

echo.

pause
exit /b
84 changes: 84 additions & 0 deletions tools/buildtool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# KP Liberation builder

## Requirements

nodejs version >=7.

## Usage

```bash
# Install dependencies
npm install

# Run mission build
npm run build


# Run task with local gulp via npx
npx gulp <task_name>

# With gulp-cli and gulp 4 installed globally
gulp <task_name>

```
| Task | Desc |
| ----------- | ---------------------------------------------- |
| clean | removes `build/` dir |
| build | assembles missionfolder and sets config values |
| pbo | packs missionfolders into PBOs |
| zip | creates release ZIPs |
| __default__ | runs _build_, _pbo_ and _zip_ |

Build files will be outputted to `build/` dir.

## Configuration

### presets.json

This file should contain an JSON __array__ of `Presets`, for every preset one mission file will be built.

Every `Preset` entry should have following structure:
```javascript
{
// Source folder with mission.sqm, relative to <missionsFolder>
// If mission.sqm is in root of <missionsFolder> should be set to empty string
"sourceFolder": "kp_liberation.Altis",

// Name and map is used to build output directory: <missionName>.<map>
// Name different than source allows to build multiple version of mission on same map
// Combination of <missionName> and <map> should be unique for every preset
"missionName": "kp_liberation",
"map": "Altis",

// Keys of <variables> object represent variables in <configFile>.
// These variables values will be set to corresponding value in <variables>
"configFile": "kp_liberation_config.sqf",
"variables": {
"KP_liberation_preset_blufor": 0,
"KP_liberation_preset_opfor": 0,
"KP_liberation_preset_resistance": 0,
"KP_liberation_preset_civilians": 0,
"KP_liberation_arsenal": 0
}
}
```

### gulpfile.ts

`paths` variable in _gulpfile_ holds filesystem paths required to build missions.

```typescript
/**
* Mission folders configuration
*/
const paths: FolderStructureInfo = {
// Folder with mission scripts
frameworkFolder: resolve('..', 'Missionframework'),

// Folder with base mission.sqm folders
missionsFolder: resolve('..', 'Missionbasefiles'),

// Output directory
workDir: resolve("./build")
};
```
10 changes: 10 additions & 0 deletions tools/buildtool/_presets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"sourceFolder": "kp_liberation.Altis",
"missionName": "kp_liberation",
"map": "Altis",
"configFile": "KPLIB_config.sqf",
"variables": {
}
}
]
139 changes: 139 additions & 0 deletions tools/buildtool/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import * as gulp from "gulp";
import * as gulpReplace from "gulp-replace";
import * as gulpPbo from "gulp-armapbo";
import * as gulpZip from "gulp-zip";
import * as vinylPaths from "vinyl-paths";
import * as del from "del";

import { resolve } from "path";

import { MissionPaths } from "./src";
import { Preset, FolderStructureInfo } from "./src";

const ROOT_DIR = resolve('..', '..');

const presets: Preset[] = require('./_presets.json');

/**
* Mission folders configuration
*/
const paths: FolderStructureInfo = {
frameworkFolder: resolve(ROOT_DIR, 'Missionframework'),
missionsFolder: resolve(ROOT_DIR, 'Missionbasefiles'),
workDir: resolve(ROOT_DIR, "_build")
};


/**
* Create gulp tasks
*/
let taskNames: string[] = [];
let taskNamesPbo: string[] = [];
let taskNamesZip: string[] = [];

for (let preset of presets) {
const mission = new MissionPaths(preset, paths);
const taskName = [preset.missionName, preset.map].join('.');


taskNames.push('mission_' + taskName);

gulp.task('mission_' + taskName, gulp.series(
/** Copy mission framework to output dir */
function copyFramework() {
return gulp.src(mission.getFrameworkPath().concat('/**/*'))
.pipe(gulp.dest(mission.getOutputDir()));
},

/** Copy mission.sqm to output dir */
function copyMissionSQM() {
return gulp.src(mission.getMissionSqmPath())
.pipe(gulp.dest(mission.getOutputDir()));
},

/** Replace variables values in configuration file */
function replaceVariables() {
let src = gulp.src(mission.getMissionConfigFilePath());

const variables = Object.getOwnPropertyNames(preset.variables);
for (let variable of variables) {
// https://regex101.com/r/YknC8r/1
const regex = new RegExp(`(${variable} += +)(?:\\d+|".+")`, 'ig');
const value = JSON.stringify(preset.variables[variable]);

// replace variable value
src = src.pipe(gulpReplace(regex, `$1${value}`));
}

return src.pipe(gulp.dest(mission.getOutputDir()));
}
));

/**
* Pack PBOs
*/
taskNamesPbo.push('pack_' + taskName);

gulp.task('pack_' + taskName, () => {
return gulp.src(mission.getOutputDir() + '/**/*')
.pipe(gulpPbo({
fileName: mission.getFullName() + '.pbo',
progress: false,
verbose: false,
// Do not compress (SLOW)
compress: true ? [] : [
'**/*.sqf',
'mission.sqm',
'description.ext'
]
}))
.pipe(gulp.dest(mission.getWorkDir() + '/pbo'));
});

/**
* Create ZIP files
*/
taskNamesZip.push('zip_' + taskName);

gulp.task('zip_' + taskName, () => {
return gulp.src([
resolve(ROOT_DIR, 'LICENSE'),
resolve(ROOT_DIR, 'CHANGELOG.md'),
resolve(ROOT_DIR, 'README.md')
], {
base: ROOT_DIR // Change base dir to have correct relative paths in ZIP
})
.pipe(
gulp.src(
resolve(mission.getWorkDir(), 'pbo', mission.getFullName() + '.pbo'), {
base: resolve(mission.getWorkDir(), 'pbo') // Change base dir to have correct relative paths in ZIP
})
)
.pipe(gulpZip(
mission.getFullName() + '.zip'
))
.pipe(gulp.dest(mission.getWorkDir()))
});


}

// Main tasks
gulp.task('clean', () => {
return gulp.src(paths.workDir)
.pipe(vinylPaths(del));
});

gulp.task('build', gulp.series(taskNames));

gulp.task('pbo', gulp.series(taskNamesPbo));

gulp.task('zip', gulp.series(taskNamesZip));

gulp.task('default',
gulp.series(
gulp.task('build'),
gulp.task('pbo'),
// gulp.task('zip'),
)
);
Loading

0 comments on commit 351e7ac

Please sign in to comment.