@jtff/miztemplate-lib 3.0.0-rc15 → 3.0.0-rc17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@ class MizTemplateCI{
59
59
  return newVersionObject;
60
60
  }
61
61
 
62
- getDestinationMizFilePaths() {
62
+ getDestinationMizFilePathArrayFromConfig() {
63
63
  const returnArray = this.config.missionTemplates.map(missionTemplate => {
64
64
  return this.config.general.missionFolder + '/'
65
65
  + this.config.general.missionPrefix + '_'
@@ -70,6 +70,16 @@ class MizTemplateCI{
70
70
  return returnArray;
71
71
  }
72
72
 
73
+ getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate) {
74
+ const destinationMizPath = [this.config.general.missionFolder + '/',
75
+ this.config.general.missionPrefix + '_',
76
+ missionTemplate.theatre + '_',
77
+ this.config.general.missionSuffix.length > 0 ? this.config.general.missionSuffix + '_' : '',
78
+ this.config.general.missionVersion + '.miz'].join('')
79
+ ;
80
+ return destinationMizPath;
81
+ }
82
+
73
83
  getGeneratedMizFilePaths() {
74
84
  return fs.readdirSync(this.config.general.missionFolder + '/')
75
85
  .filter(file => file.endsWith((".miz")))
@@ -193,8 +203,8 @@ class MizTemplateCI{
193
203
  return {
194
204
  "general": {
195
205
  "missionFolder": "dist",
196
- "missionPrefix": filename,
197
- "missionSuffix": "JTFF",
206
+ "missionPrefix": path.parse(filename).name,
207
+ "missionSuffix": "",
198
208
  "missionVersion": "1.0.0-snapshot"
199
209
  },
200
210
  "google": {
package/lib/mizlib.js CHANGED
@@ -107,16 +107,33 @@ class Mizlib {
107
107
  return MizFile.loadAsync(mizData);
108
108
  }
109
109
 
110
- async buildMizFileFromMizTemplate(mizPath, copyPath) {
110
+ async buildMizFileFromMizTemplate(mizPath, copyPath, singleMission= true) {
111
111
  const zipObject = await this.getZipObjectFromMizPath(mizPath);
112
112
  const missionObject = await this.getMissionObjectFromZipObject(zipObject);
113
113
  const strTheatreSettings = missionObject.theatre;
114
- // TODO: D'abord mettre à jour les fichiers src et lib depuis la miztemplate sauf 200-mission.lua
114
+ const srcFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/src",{recursive: true})
115
+ .filter(filename => path.extname(filename).toLowerCase()==='.lua' && !(filename.startsWith('200-')));
116
+ const libFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/lib",{recursive: true})
117
+ .filter(filename => path.extname(filename).toLowerCase()==='.lua');
118
+ for (let file of srcFiles) {
119
+ console.log('updating src/' + file + ' from the miztemplate-lib');
120
+ fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/src/' + file,
121
+ 'src/' + file,
122
+ {force: true}
123
+ );
124
+ }
125
+ for (let file of libFiles) {
126
+ console.log('updating lib/' + file + ' from the miztemplate-lib');
127
+ fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/lib/' + file,
128
+ 'lib/' + file,
129
+ {force: true}
130
+ );
131
+ }
115
132
  this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'src');
116
133
  this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'lib');
117
134
  await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
118
- this.mizUpdateSettingsLuaFiles(zipObject, strTheatreSettings);
119
- await this.mizUpdateSoundFolders(zipObject);
135
+ this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, singleMission ? '' : strTheatreSettings);
136
+ await this.injectSoundFoldersIntoZipObject(zipObject);
120
137
  const inputZip = await zipObject.generateAsync({
121
138
  type: 'nodebuffer',
122
139
  streamFiles: true,
@@ -290,15 +307,14 @@ class Mizlib {
290
307
  this.mizUpdateMissionDataFile(zip, {mission: mission_object});
291
308
  }
292
309
 
293
- mizUpdateSettingsLuaFiles(zip, strTheatre) {
294
- for (let file of fs.readdirSync('settings/' + strTheatre).filter(file => file.endsWith(".lua"))) {
295
- console.log('updating settings/' + strTheatre + '/' + file + ' file in miz file');
296
- this.injectFileIntoZipObject(zip, 'settings/' + strTheatre + '/' + file);
310
+ injectSettingsLuaFilesFromFolderIntoZipObject(zip, strTheatre) {
311
+ for (let file of fs.readdirSync(['settings',strTheatre.length > 0 ? '/' + strTheatre : ''].join('')).filter(file => path.extname(file).toLowerCase()==='.lua')) {
312
+ console.log(['updating settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file,' file in miz file'].join(''));
313
+ this.injectFileIntoZipObject(zip, ['settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file].join(''));
297
314
  }
298
- ;
299
315
  }
300
316
 
301
- async mizUpdateSoundFolders(zip) {
317
+ async injectSoundFoldersIntoZipObject(zip) {
302
318
  if (fs.existsSync('resources/sounds') && fs.lstatSync('resources/sounds').isDirectory()) {
303
319
  const folderArray = fs.readdirSync('resources/sounds');
304
320
  for (const folder of folderArray) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtff/miztemplate-lib",
3
- "version": "3.0.0-rc15",
3
+ "version": "3.0.0-rc17",
4
4
  "description": "JTFF mission template library",
5
5
  "main": "index.js",
6
6
  "files": [
package/scripts/build.js CHANGED
@@ -6,32 +6,16 @@ function build(jtffci) {
6
6
  if (missionTemplate.filename) {
7
7
  await jtffci.mizlib.buildMizFileFromMizTemplate(
8
8
  missionTemplate.filename,
9
- [
10
- jtffci.config.general.missionFolder + '/' + jtffci.config.general.missionPrefix,
11
- '_',
12
- missionTemplate.theatre,
13
- '_',
14
- jtffci.config.general.missionSuffix,
15
- '_',
16
- jtffci.displayVersion(jtffci.getVersion()),
17
- ".miz"
18
- ].join(""));
9
+ jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
10
+ (jtffci.config.missionTemplates.length > 1) ? false : true);
19
11
  } else {
20
12
  await jtffci.mizlib.buildMizFileFromMizTemplate([
21
- missionTemplate.prefix,
22
- '_',
23
- missionTemplate.theatre,
24
- ".miz"
25
- ].join(""), [
26
- jtffci.config.general.missionFolder + '/' + jtffci.config.general.missionPrefix,
27
- '_',
28
- missionTemplate.theatre,
29
- '_',
30
- jtffci.config.general.missionSuffix,
31
- '_',
32
- jtffci.displayVersion(jtffci.getVersion()),
33
- ".miz"
34
- ].join(""));
13
+ [missionTemplate.prefix,
14
+ missionTemplate.theatre].join('_'),
15
+ ".miz"
16
+ ].join(""),
17
+ jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
18
+ false);
35
19
  }
36
20
  let publicationConfig = {
37
21
  theatre: missionTemplate.theatre,
@@ -49,7 +33,6 @@ function build(jtffci) {
49
33
  };
50
34
  fs.writeFileSync(jtffci.config.general.missionFolder + '/' + missionTemplate.theatre + '.pub.json', JSON.stringify(publicationConfig, null, 4));
51
35
  });
52
-
53
36
  }
54
37
 
55
- module.exports = build
38
+ module.exports = build;