@jtff/miztemplate-lib 3.0.0-rc23 → 3.0.0-rc25

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.
@@ -5,6 +5,7 @@ const path = require("path");
5
5
  const { google } = require("googleapis");
6
6
  const ftpClient = require('ftp');
7
7
  const Mizlib = require("./mizlib");
8
+ const { getInstalledPathSync } = require('get-installed-path')
8
9
 
9
10
  class MizTemplateCI{
10
11
  constructor(config) {
@@ -249,7 +250,7 @@ class MizTemplateCI{
249
250
  }
250
251
 
251
252
  async InjectCiScriptsIntoWorkspace(workspacePath) {
252
- fs.cpSync('node_modules/@jtff/miztemplate-lib/ci',workspacePath + '/.workspace/src/nodejs',{recursive: true});
253
+ fs.cpSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/ci',workspacePath + '/.workspace/src/nodejs',{recursive: true});
253
254
  }
254
255
 
255
256
  async deployCIScriptsFromZipObjectIntoWorkspace(workspacePath, mizObject, mizFilePath) {
package/lib/mizlib.js CHANGED
@@ -5,6 +5,7 @@ const path = require("path");
5
5
  const {format, parse} = require("lua-json");
6
6
  const {promisify} = require("util");
7
7
  const fs = require("fs");
8
+ const {getInstalledPathSync} = require("get-installed-path");
8
9
  const lstat = promisify(fs.lstat);
9
10
 
10
11
  class Mizlib {
@@ -42,7 +43,8 @@ class Mizlib {
42
43
  for (let luaScript of luaScriptsArray) {
43
44
  fs.cpSync(
44
45
  [
45
- 'node_modules/@jtff/miztemplate-lib/lua/',
46
+ getInstalledPathSync('@jtff/miztemplate-lib'),
47
+ '/lua/',
46
48
  folderPath,
47
49
  '/',
48
50
  luaScript
@@ -108,33 +110,33 @@ class Mizlib {
108
110
  return MizFile.loadAsync(mizData);
109
111
  }
110
112
 
111
- async buildMizFileFromMizTemplate(mizPath, copyPath, singleMission= true) {
113
+ async buildMizFileFromMizTemplate(mizPath, copyPath, mizSettingSubFolder= '') {
112
114
  const zipObject = await this.getZipObjectFromMizPath(mizPath);
113
115
  const missionObject = await this.getMissionObjectFromZipObject(zipObject);
114
116
  const strTheatreSettings = missionObject.theatre;
115
- const srcFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/src",{recursive: true})
117
+ const srcFiles = fs.readdirSync(getInstalledPathSync('@jtff/miztemplate-lib') + "/lua/src",{recursive: true})
116
118
  .filter(filename => path.extname(filename).toLowerCase()==='.lua' && !(filename.startsWith('200-')));
117
- const libFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/lib",{recursive: true})
119
+ const libFiles = fs.readdirSync(getInstalledPathSync('@jtff/miztemplate-lib') + "/lua/lib",{recursive: true})
118
120
  .filter(filename => path.extname(filename).toLowerCase()==='.lua');
119
121
  for (let file of srcFiles) {
120
122
  console.log('updating src/' + file + ' from the miztemplate-lib');
121
- fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/src/' + file,
123
+ fs.cpSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/lua/src/' + file,
122
124
  '.workspace/src/' + file,
123
125
  {force: true}
124
126
  );
125
127
  }
126
128
  for (let file of libFiles) {
127
129
  console.log('updating lib/' + file + ' from the miztemplate-lib');
128
- fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/lib/' + file,
130
+ fs.cpSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/lua/lib/' + file,
129
131
  '.workspace/lib/' + file,
130
132
  {force: true}
131
133
  );
132
134
  }
133
- this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/src');
134
- this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/lib');
135
- this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'src');
135
+ this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/src', mizSettingSubFolder);
136
+ this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/lib', mizSettingSubFolder);
137
+ this.injectLuaFilesFromFolderIntoZipObject(zipObject, ['src',mizSettingSubFolder.length > 0 ? '/' + mizSettingSubFolder : ''].join(''), mizSettingSubFolder);
136
138
  await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
137
- this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, singleMission ? '' : strTheatreSettings);
139
+ this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, mizSettingSubFolder.length > 0 ? mizSettingSubFolder : '');
138
140
  await this.injectSoundFoldersIntoZipObject(zipObject);
139
141
  const inputZip = await zipObject.generateAsync({
140
142
  type: 'nodebuffer',
@@ -236,9 +238,9 @@ class Mizlib {
236
238
  return zipStream.file("l10n/DEFAULT/mapResource").async("string");
237
239
  }
238
240
 
239
- injectLuaFilesFromFolderIntoZipObject(zip, folderPath) {
241
+ injectLuaFilesFromFolderIntoZipObject(zip, folderPath, mizSettingSubFolder) {
240
242
  for (let file of fs.readdirSync(folderPath).filter(file => file.endsWith(".lua"))) {
241
- console.log('injecting up2date ' + folderPath + '/' + file + ' file in archive');
243
+ console.log('injecting up2date ' + folderPath + '/' + file + ' file in ' + mizSettingSubFolder + ' archive');
242
244
  this.injectFileIntoZipObject(zip, folderPath + "/" + file);
243
245
  };
244
246
  }
@@ -308,10 +310,10 @@ class Mizlib {
308
310
  this.injectMissionObjectIntoZipObject(zip, {mission: mission_object});
309
311
  }
310
312
 
311
- injectSettingsLuaFilesFromFolderIntoZipObject(zip, strTheatre) {
312
- for (let file of fs.readdirSync(['settings',strTheatre.length > 0 ? '/' + strTheatre : ''].join('')).filter(file => path.extname(file).toLowerCase()==='.lua')) {
313
- console.log(['updating settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file,' file in miz file'].join(''));
314
- this.injectFileIntoZipObject(zip, ['settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file].join(''));
313
+ injectSettingsLuaFilesFromFolderIntoZipObject(zip, settingsSubFolder) {
314
+ for (let file of fs.readdirSync(['settings',settingsSubFolder.length > 0 ? '/' + settingsSubFolder : ''].join('')).filter(file => path.extname(file).toLowerCase()==='.lua')) {
315
+ console.log(['updating settings',settingsSubFolder.length > 0 ? '/' + settingsSubFolder : '','/',file,' file in miz file'].join(''));
316
+ this.injectFileIntoZipObject(zip, ['settings',settingsSubFolder.length > 0 ? '/' + settingsSubFolder : '','/',file].join(''));
315
317
  }
316
318
  }
317
319
 
@@ -349,14 +351,14 @@ class Mizlib {
349
351
  ].join(""), {recursive: true});
350
352
  }
351
353
  if (
352
- fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) &&
353
- fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
354
+ fs.existsSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/resources/sounds/' + folderString) &&
355
+ fs.lstatSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/resources/sounds/' + folderString).isDirectory()) {
354
356
  fs.mkdirSync([
355
357
  workspacePath,
356
358
  "/.workspace/resources/sounds/",
357
359
  folderString
358
360
  ].join(""), {recursive: true});
359
- fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString,[
361
+ fs.cpSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/resources/sounds/' + folderString,[
360
362
  workspacePath,
361
363
  "/.workspace/resources/sounds/",
362
364
  folderString
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtff/miztemplate-lib",
3
- "version": "3.0.0-rc23",
3
+ "version": "3.0.0-rc25",
4
4
  "description": "JTFF mission template library",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -32,6 +32,7 @@
32
32
  "homepage": "https://github.com/JTFF-mission-scripts/miztemplate-lib#readme",
33
33
  "dependencies": {
34
34
  "ftp": "^0.3.10",
35
+ "get-installed-path": "^4.0.8",
35
36
  "googleapis": "^92.0.0",
36
37
  "jszip": "^3.10.1",
37
38
  "lodash": "^4.17.21",
package/scripts/build.js CHANGED
@@ -7,7 +7,7 @@ function build(jtffci) {
7
7
  await jtffci.mizlib.buildMizFileFromMizTemplate(
8
8
  missionTemplate.filename,
9
9
  jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
10
- (jtffci.config.missionTemplates.length > 1) ? false : true);
10
+ (jtffci.config.missionTemplates.length > 1) ? missionTemplate.theatre : '');
11
11
  } else {
12
12
  await jtffci.mizlib.buildMizFileFromMizTemplate([
13
13
  [missionTemplate.prefix,
@@ -15,7 +15,7 @@ function build(jtffci) {
15
15
  ".miz"
16
16
  ].join(""),
17
17
  jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
18
- false);
18
+ missionTemplate.theatre);
19
19
  }
20
20
  let publicationConfig = {
21
21
  theatre: missionTemplate.theatre,
@@ -2,6 +2,7 @@ const fs = require('fs');
2
2
  const path = require("path");
3
3
  const prompt = require('prompt');
4
4
  let _ = require('lodash');
5
+ const {getInstalledPathSync} = require("get-installed-path");
5
6
 
6
7
  function injectScripts(jtffci, env_mission) {
7
8
  const workspacePath = [
@@ -472,7 +473,7 @@ function injectScripts(jtffci, env_mission) {
472
473
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_radio_presets)) {
473
474
  // injection des preset radio
474
475
  fs.mkdirSync(workspacePath + '/resources/radios/' + missionObject.theatre,{recursive: true});
475
- fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/radios/' + missionObject.theatre,workspacePath + '/resources/radios/' + missionObject.theatre,{recursive: true})
476
+ fs.cpSync(getInstalledPathSync('@jtff/miztemplate-lib') + '/resources/radios/' + missionObject.theatre,workspacePath + '/resources/radios/' + missionObject.theatre,{recursive: true})
476
477
  console.log(destinationMizFilePath + ": injecting radio presets declared in resources/radios/" + missionObject.theatre);
477
478
  await jtffci.mizlib.injectRadioPresetsFromFolderIntoZipObject(mizObject, workspacePath + '/resources/radios/' + missionObject.theatre);
478
479
  }
@@ -3,43 +3,61 @@ const fs = require("fs");
3
3
  function templateUpdate(jtffci) {
4
4
  fs.mkdirSync(jtffci.config.general.missionFolder, { recursive: true });
5
5
  jtffci.config.missionTemplates.map(async missionTemplate => {
6
- await this.mizlib.buildMizFileFromMizTemplate([
7
- missionTemplate.prefix,
8
- '_',
9
- missionTemplate.theatre,
10
- ".miz"
11
- ].join(""), [
12
- missionTemplate.prefix,
13
- '_',
14
- missionTemplate.theatre,
15
- "-new.miz"
16
- ].join(""), missionTemplate.theatre);
17
- if (fs.existsSync([
18
- missionTemplate.prefix,
19
- '_',
20
- missionTemplate.theatre,
21
- ".miz"
22
- ].join(""))) {
23
- fs.unlinkSync([
6
+ if (missionTemplate.filename) {
7
+ await jtffci.mizlib.buildMizFileFromMizTemplate(
8
+ missionTemplate.filename,
9
+ [ missionTemplate.filename,
10
+ "-new.miz"
11
+ ].join(""),
12
+ (jtffci.config.missionTemplates.length > 1) ? missionTemplate.theatre : '');
13
+ if (fs.existsSync(missionTemplate.filename)) {
14
+ fs.unlinkSync(missionTemplate.filename);
15
+ }
16
+ fs.renameSync(
17
+ [ missionTemplate.filename,
18
+ "-new.miz"
19
+ ].join(""),
20
+ missionTemplate.filename);
21
+ } else {
22
+ await this.mizlib.buildMizFileFromMizTemplate(
23
+ [ missionTemplate.prefix,
24
+ '_',
25
+ missionTemplate.theatre,
26
+ ".miz"
27
+ ].join(""),
28
+ [ missionTemplate.prefix,
29
+ '_',
30
+ missionTemplate.theatre,
31
+ "-new.miz"
32
+ ].join(""),
33
+ missionTemplate.theatre);
34
+ if (fs.existsSync([
24
35
  missionTemplate.prefix,
25
36
  '_',
26
37
  missionTemplate.theatre,
27
38
  ".miz"
28
- ].join(""));
39
+ ].join(""))) {
40
+ fs.unlinkSync([
41
+ missionTemplate.prefix,
42
+ '_',
43
+ missionTemplate.theatre,
44
+ ".miz"
45
+ ].join(""));
46
+ }
47
+ fs.renameSync([
48
+ missionTemplate.prefix,
49
+ '_',
50
+ missionTemplate.theatre,
51
+ "-new.miz"
52
+ ].join(""),
53
+ [
54
+ missionTemplate.prefix,
55
+ '_',
56
+ missionTemplate.theatre,
57
+ ".miz"
58
+ ].join("")
59
+ );
29
60
  }
30
- fs.renameSync([
31
- missionTemplate.prefix,
32
- '_',
33
- missionTemplate.theatre,
34
- "-new.miz"
35
- ].join(""),
36
- [
37
- missionTemplate.prefix,
38
- '_',
39
- missionTemplate.theatre,
40
- ".miz"
41
- ].join("")
42
- );
43
61
  });
44
62
  }
45
63