@dotpi/tools 1.3.3 → 2.3.2

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.
Files changed (106) hide show
  1. package/.editorbackup/NOTES.md~ +974 -0
  2. package/.editorbackup/PIPEWIRE.md~ +42 -0
  3. package/.editorbackup/README.md~ +335 -0
  4. package/BACKUP-SANDO.command +61 -0
  5. package/BACKUP-SISIDO.command +61 -0
  6. package/NOTES.md +41 -1
  7. package/README.md +3 -13
  8. package/dotpi_root/bin/dotpi +1 -0
  9. package/dotpi_root/bin/dotpi_prepare_sd_card +34 -22
  10. package/dotpi_root/bin/dotpi_prepare_system +113 -68
  11. package/dotpi_root/bin/package.json +6 -0
  12. package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor.service +1 -5
  13. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_install +21 -0
  14. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_uninstall +17 -0
  15. package/dotpi_root/dist/@dotpi/avahi_monitor/package.json +10 -0
  16. package/dotpi_root/dist/@dotpi/javascript/bash.js +103 -0
  17. package/dotpi_root/dist/@dotpi/javascript/echo.js +13 -0
  18. package/dotpi_root/dist/@dotpi/javascript/filesystem.js +25 -0
  19. package/dotpi_root/dist/@dotpi/javascript/package.json +12 -0
  20. package/dotpi_root/dist/@dotpi/javascript/service.js +49 -0
  21. package/dotpi_root/dist/@dotpi/javascript/system.js +36 -0
  22. package/dotpi_root/dist/@dotpi/javascript/template.js +13 -0
  23. package/dotpi_root/dist/@dotpi/javascript/user.js +32 -0
  24. package/dotpi_root/dist/@dotpi/module/LICENSE +28 -0
  25. package/dotpi_root/dist/@dotpi/module/bin/dotpi_module +13 -0
  26. package/dotpi_root/dist/@dotpi/module/dotpi_install +52 -0
  27. package/dotpi_root/dist/@dotpi/module/dotpi_uninstall +50 -0
  28. package/dotpi_root/dist/@dotpi/module/package.json +22 -0
  29. package/dotpi_root/dist/@dotpi/module/src/configuration.js +43 -0
  30. package/dotpi_root/dist/@dotpi/module/src/createConfig.js +108 -0
  31. package/dotpi_root/dist/@dotpi/module/src/definition.js +7 -0
  32. package/dotpi_root/dist/@dotpi/module/src/index.js +0 -0
  33. package/dotpi_root/dist/@dotpi/module/src/install.js +145 -0
  34. package/dotpi_root/dist/@dotpi/module/src/uninstall.js +180 -0
  35. package/dotpi_root/etc/dotpi_environment_default.bash +16 -0
  36. package/dotpi_root/etc/dotpi_init.d/.gitkeep +0 -0
  37. package/dotpi_root/etc/dotpi_modules.json +8 -0
  38. package/dotpi_root/lib/package.json +6 -0
  39. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +7 -6
  40. package/dotpi_root/share/dotpi_audio_bluetooth/package.json +6 -0
  41. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +12 -26
  42. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +2 -2
  43. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +6 -2
  44. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +11 -0
  45. package/dotpi_root/share/dotpi_functions/dotpi_functions_user.bash +28 -0
  46. package/dotpi_root/share/dotpi_functions.bash +4 -4
  47. package/dotpi_root/share/dotpi_init.bash +10 -1
  48. package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +86 -0
  49. package/dotpi_root/share/dotpi_pipewire/dotpi_install +24 -0
  50. package/dotpi_root/share/dotpi_pipewire/package.json +9 -0
  51. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire.service +22 -0
  52. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire_command +29 -0
  53. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +2 -6
  54. package/dotpi_root/share/wireplumber/wireplumber.conf.d/dotpi-wireplumber-config.conf +8 -0
  55. package/lerna.json +4 -0
  56. package/package.json +12 -2
  57. package/projects/asterismes.tgz +0 -0
  58. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_001.bash~ +4 -0
  59. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_002.bash~ +3 -0
  60. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_project.bash~ +46 -0
  61. package/projects/example-bluetooth/configuration/dotpi_instance_001.bash +3 -0
  62. package/projects/example-bluetooth/configuration/dotpi_instance_002.bash +3 -0
  63. package/projects/example-bluetooth/configuration/dotpi_project.bash +48 -0
  64. package/projects/example-development/configuration/.editorbackup/dotpi_project.bash~ +59 -0
  65. package/projects/example-development/configuration/dotpi_instance_114.bash +4 -0
  66. package/projects/example-headphones/configuration/.editorbackup/dotpi_project.bash~ +18 -0
  67. package/projects/example-hifiberry/configuration/.editorbackup/dotpi_instance_012.bash~ +4 -0
  68. package/projects/example-hifiberry/configuration/.editorbackup/dotpi_project.bash~ +18 -0
  69. package/projects/example-network/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  70. package/projects/led-test/.dotpi +3 -0
  71. package/projects/led-test/README.md +16 -0
  72. package/projects/led-test/dotpi_project.bash +29 -0
  73. package/projects/old/bad/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  74. package/projects/old/bad/.editorbackup/dotpi_environment_project.bash~ +26 -0
  75. package/projects/old/bad/.editorbackup/dotpi_project.bash~ +33 -0
  76. package/projects/old/bad/.editorbackup/dotpi_tmp.bash~ +3 -0
  77. package/projects/old/bad/.editorbackup/wpa_supplicant.conf~ +37 -0
  78. package/projects/old/bad/dotpi_project.bash +20 -0
  79. package/projects/old/bluetooth/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  80. package/projects/old/bluetooth/.editorbackup/dotpi_environment_project.bash~ +26 -0
  81. package/projects/old/bluetooth/.editorbackup/dotpi_project.bash~ +21 -0
  82. package/projects/old/bluetooth/.editorbackup/dotpi_tmp.bash~ +3 -0
  83. package/projects/old/bluetooth/.editorbackup/wpa_supplicant.conf~ +37 -0
  84. package/projects/old/bluetooth/dotpi_project.bash +29 -0
  85. package/projects/old/dev.zip +0 -0
  86. package/projects/old/example/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  87. package/projects/old/example/.editorbackup/dotpi_environment_project.bash~ +26 -0
  88. package/projects/old/example/.editorbackup/dotpi_project.bash~ +21 -0
  89. package/projects/old/example/.editorbackup/dotpi_tmp.bash~ +3 -0
  90. package/projects/old/example/.editorbackup/wpa_supplicant.conf~ +37 -0
  91. package/projects/old/example/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  92. package/projects/old/example/configuration/dotpi_project.bash +21 -0
  93. package/projects/qsddsqsd/.dotpi +3 -0
  94. package/projects/qsddsqsd/README.md +16 -0
  95. package/projects/qsddsqsd/dotpi_project.bash +29 -0
  96. package/src/constants.js +4 -4
  97. package/src/create-project.js +124 -56
  98. package/src/templates/dotpi_project.bash +5 -7
  99. package/src/utils.js +2 -2
  100. package/test/create-project.test.js +0 -1
  101. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +0 -18
  102. package/dotpi_root/share/jackd/dotpi_jackd_command +0 -26
  103. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +0 -21
  104. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +0 -17
  105. package/dotpi_root/share/jackd/jackd.service +0 -22
  106. /package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor_command +0 -0
@@ -0,0 +1,13 @@
1
+ import fs from 'node:fs/promises';
2
+ import compile from 'template-literal';
3
+
4
+ export async function renderFile(templateFile, data = {}) {
5
+ try {
6
+ const template = await fs.readFile(templateFile, 'utf8');
7
+ const render = compile(template);
8
+ return render(data);
9
+ } catch (error) {
10
+ throw error;
11
+ }
12
+ }
13
+
@@ -0,0 +1,32 @@
1
+ import { $ } from 'execa';
2
+
3
+ // raspberry pi default user (pi)
4
+ export const firstUserID = 1000;
5
+
6
+ const regularUserIdDefault = firstUserID;
7
+
8
+ export function regularUserIdGet() {
9
+ const processUid = process.getuid();
10
+ if (processUid !== 0) {
11
+ return processUid;
12
+ }
13
+
14
+ let regularUserId = parseInt(process.env.SUDO_UID);
15
+ if (!regularUserId) {
16
+ regularUserId = regularUserIdDefault;
17
+ }
18
+
19
+ return regularUserId;
20
+ }
21
+
22
+ export async function regularUserGet() {
23
+ const { stdout } = await $`getent passwd ${regularUserIdGet()}`;
24
+
25
+ return {
26
+ name: stdout.split(':')[0],
27
+ uid: stdout.split(':')[2],
28
+ gid: stdout.split(':')[3],
29
+ home: stdout.split(':')[5],
30
+ shell: stdout.split(':')[6],
31
+ };
32
+ }
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2023-present IRCAM – Centre Pompidou (France, Paris)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice, this
12
+ list of conditions and the following disclaimer in the documentation and/or
13
+ other materials provided with the distribution.
14
+
15
+ * Neither the name of the IRCAM nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+
4
+ import { installCommandDefine } from '../src/install.js';
5
+ import { uninstallCommandDefine } from '../src/uninstall.js';
6
+ import { createConfigCommandDefine } from '../src/createConfig.js';
7
+
8
+ installCommandDefine({ program });
9
+ uninstallCommandDefine({ program });
10
+ createConfigCommandDefine({ program });
11
+
12
+ program.parse();
13
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import fs from 'node:fs/promises';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import { symlink } from '@dotpi/javascript/filesystem.js';
8
+ import * as echo from '@dotpi/javascript/echo.js';
9
+ import {
10
+ dotpiRootGet,
11
+ isRaspberryPi,
12
+ } from '@dotpi/javascript/system.js';
13
+
14
+ if (! await isRaspberryPi() ) {
15
+ echo.info('System is not a Raspberry Pi with dotpi: no installation');
16
+ // no error
17
+ process.exit(0);
18
+ }
19
+
20
+ if (process.getuid() !== 0) {
21
+ echo.error('This script must be run as root');
22
+ process.exit(1);
23
+ }
24
+
25
+ // __filename and __dirname are undefined in module type
26
+ const localFileName = fileURLToPath(import.meta.url);
27
+ const localPath = path.dirname(localFileName);
28
+
29
+ let dotpiRoot;
30
+ try {
31
+ dotpiRoot = await dotpiRootGet();
32
+ const destinationPath = path.resolve(dotpiRoot, 'bin');
33
+ const sourcePath = path.resolve(localPath, 'bin');
34
+ const sourceBaseNames = await fs.readdir(sourcePath);
35
+
36
+ // forEach does not wait: parallel execution
37
+ sourceBaseNames.forEach(async (sourceBaseName) => {
38
+ const sourceFile = path.resolve(sourcePath, sourceBaseName);
39
+ const destinationFile = path.resolve(destinationPath, sourceBaseName);
40
+
41
+ echo.info(`Install ${destinationFile} -> ${sourceFile}`);
42
+ await symlink(sourceFile, destinationFile);
43
+ });
44
+
45
+ } catch (error) {
46
+ echo.error(`Error with '${localFileName}'`, error.message);
47
+ let exitCode = 1;
48
+ if (error && error.cause) {
49
+ exitCode = error.cause.code;
50
+ }
51
+ process.exit(exitCode);
52
+ }
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import fs from 'node:fs/promises';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import * as echo from '@dotpi/javascript/echo.js';
8
+ import {
9
+ dotpiRootGet,
10
+ isRaspberryPi,
11
+ } from '@dotpi/javascript/system.js';
12
+
13
+ if (! await isRaspberryPi() ) {
14
+ echo.info('System is not a Raspberry Pi with dotpi: no uninstallation');
15
+ // no error
16
+ process.exit(0);
17
+ }
18
+
19
+ if (process.getuid() !== 0) {
20
+ echo.error('This script must be run as root');
21
+ process.exit(1);
22
+ }
23
+
24
+ // __filename and __dirname are undefined in module type
25
+ const localFileName = fileURLToPath(import.meta.url);
26
+ const localPath = path.dirname(localFileName);
27
+
28
+ let dotpiRoot;
29
+ try {
30
+ dotpiRoot = await dotpiRootGet();
31
+ const destinationPath = path.resolve(dotpiRoot, 'bin');
32
+ const sourcePath = path.resolve(localPath, 'bin');
33
+ const sourceBaseNames = await fs.readdir(sourcePath);
34
+
35
+ // forEach does not wait: parallel execution
36
+ sourceBaseNames.forEach(async (sourceBaseName) => {
37
+ const destinationFile = path.resolve(destinationPath, sourceBaseName);
38
+
39
+ echo.info(`Uninstall ${destinationFile}`);
40
+ await fs.rm(destinationFile, { recursive: true, force: true });
41
+ });
42
+
43
+ } catch (error) {
44
+ echo.error(`Error with '${localFileName}'`, error.message);
45
+ let exitCode = 1;
46
+ if (error && error.cause) {
47
+ exitCode = error.cause.code;
48
+ }
49
+ process.exit(exitCode);
50
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@dotpi/module",
3
+ "version": "1.6.1",
4
+ "description": "dotpi module management",
5
+ "type": "module",
6
+ "bin": "./bin/dotpi_module",
7
+ "exports": {
8
+ "./*.js": "./src/*.js"
9
+ },
10
+ "scripts": {
11
+ "postinstall": "./dotpi_install",
12
+ "preuninstall": "./dotpi_uninstall"
13
+ },
14
+ "license": "BSD-3-clause",
15
+ "dependencies": {
16
+ "@dotpi/javascript": "^1.5.0",
17
+ "commander": "^12.1.0",
18
+ "execa": "^9.5.2",
19
+ "globby": "^14.0.2"
20
+ },
21
+ "gitHead": "97bacfa304e5b53bc1e16d2efc4aece7ab65baf9"
22
+ }
@@ -0,0 +1,43 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ import { dotpiRootGet } from '@dotpi/javascript/system.js';
5
+ import * as echo from '@dotpi/javascript/echo.js';
6
+
7
+ export async function dotpiConfigurationGet({
8
+ dotpiRoot,
9
+ prefix,
10
+ } = {}) {
11
+ dotpiRoot ??= await dotpiRootGet();
12
+
13
+ try {
14
+ const modulesPath = (prefix
15
+ ? path.resolve(prefix)
16
+ : path.resolve(dotpiRoot, 'lib')
17
+ );
18
+ const modulesConfigurationPath = path.resolve(dotpiRoot, 'etc', 'dotpi_modules.json');
19
+ const modulesConfiguration = JSON.parse(
20
+ await fs.readFile(modulesConfigurationPath)
21
+ );
22
+
23
+ return {
24
+ dotpiRoot,
25
+ modulesPath,
26
+ modulesConfigurationPath,
27
+ modulesConfiguration,
28
+ };
29
+
30
+ } catch (error) {
31
+ echo.error('Error with dotpi configuration:', error.message);
32
+ throw error;
33
+ }
34
+ }
35
+
36
+ export async function moduleConfigurationPathGet({
37
+ module,
38
+ dotpiRoot,
39
+ } = {}) {
40
+ dotpiRoot ??= await dotpiRootGet();
41
+
42
+ return path.resolve(dotpiRoot, 'etc', module.name);
43
+ }
@@ -0,0 +1,108 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ import { $ } from 'execa';
5
+
6
+ import * as echo from '@dotpi/javascript/echo.js';
7
+
8
+ import { dotpiConfigurationGet } from './configuration.js';
9
+ import { definitionGet } from './definition.js';
10
+
11
+ export function createConfigCommandDefine({program}) {
12
+ program
13
+ .command('create-config')
14
+ .summary('create configuration files for installed modules')
15
+ .description('Create configuration files installed modules.')
16
+ .option('-r, --dotpi-root <path>', 'dotpi root path, to initialise environment')
17
+ .option('-p, --prefix <path>', 'look for installed modules in this directory')
18
+ .option('-v, --verbose [full]', 'print verbose output [full]')
19
+ .action((modules, options, command) => createConfig(modules, { ...options, command }));
20
+ ;
21
+
22
+ return program;
23
+ }
24
+
25
+ export async function createConfig({
26
+ dotpiRoot,
27
+ prefix,
28
+ verbose = 'short',
29
+ } = {}) {
30
+
31
+ switch (verbose) {
32
+ case '0':
33
+ case 'false':
34
+ case false:
35
+ verbose = 'none';
36
+ break;
37
+
38
+ case '1':
39
+ case 'true':
40
+ case true:
41
+ verbose = 'short';
42
+ break;
43
+
44
+ case '2':
45
+ verbose = 'full';
46
+ break;
47
+ }
48
+
49
+ let installedModulesPath;
50
+ let installedModulesDefinition;
51
+ let installedModules;
52
+ try {
53
+ if (prefix) {
54
+ installedModulesPath = prefix;
55
+ } else {
56
+ ({ modulesPath: installedModulesPath }
57
+ = await dotpiConfigurationGet({ dotpiRoot, prefix }));
58
+ }
59
+
60
+ installedModulesDefinition = JSON.parse(
61
+ await fs.readFile(path.resolve(installedModulesPath, 'package.json'))
62
+ );
63
+ installedModules = Object.keys(installedModulesDefinition.dependencies);
64
+ } catch (error) {
65
+ echo.error(`Failed to get installed modules: ${error.message}`);
66
+ process.exit(1);
67
+ }
68
+
69
+ // use array to avoid escaping in command
70
+ const dotpiRootOption = (dotpiRoot
71
+ ? ['--dotpi-root', path.resolve(dotpiRoot)]
72
+ : ''
73
+ );
74
+ const projectOption = (prefix
75
+ ? ['--project', path.resolve(prefix)]
76
+ : ''
77
+ );
78
+
79
+ // no parallelisation to create config files
80
+ for (const module of installedModules) {
81
+ try {
82
+ const modulePath = path.resolve(installedModulesPath, 'node_modules', module);
83
+ const moduleDefinition = JSON.parse(await fs.readFile(
84
+ path.resolve(modulePath, 'package.json')
85
+ ));
86
+
87
+ if (moduleDefinition.scripts['create-config']) {
88
+ if(verbose !== 'none') {
89
+ echo.info(`Creating configuration for '${module}' in '${prefix}'`);
90
+ }
91
+
92
+ const output = await $({
93
+ cwd: modulePath,
94
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
95
+ verbose: (verbose === 'full' ? 'full' : 'none'),
96
+ })`npm run create-config -- ${dotpiRootOption} ${projectOption}`;
97
+ } else {
98
+ console.log(`(No configuration file to create for '${module}')`);
99
+ }
100
+
101
+
102
+ } catch (error) {
103
+ echo.error(`Failed to create configuration files for '${module}': ${error.message}`, error);
104
+ process.exit(1);
105
+ }
106
+
107
+ }
108
+ }
@@ -0,0 +1,7 @@
1
+
2
+ import { $ } from 'execa';
3
+
4
+ export async function definitionGet(module) {
5
+ const { stdout } = await $`npm view --json -- ${module}`;
6
+ return JSON.parse(stdout);
7
+ }
File without changes
@@ -0,0 +1,145 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ import { $ } from 'execa';
5
+
6
+ import { symlink } from '@dotpi/javascript/filesystem.js';
7
+ import * as echo from '@dotpi/javascript/echo.js';
8
+
9
+ import { dotpiConfigurationGet } from './configuration.js';
10
+ import { definitionGet } from './definition.js';
11
+
12
+ export function installCommandDefine({program}) {
13
+ program
14
+ .command('install [modules...]')
15
+ .summary('install a list of modules')
16
+ .description('Install a list of modules separated by space.')
17
+ .option('-r, --dotpi-root <path>', 'dotpi root path, to initialise environment')
18
+ .option('-p, --prefix <path>', 'install modules in this directory')
19
+ .option('-v, --verbose [full]', 'print verbose output [full]')
20
+ .action((modules, options, command) => install(modules, { ...options, command }));
21
+ ;
22
+
23
+ return program;
24
+ }
25
+
26
+ export async function install(modules = [], {
27
+ dotpiRoot,
28
+ prefix,
29
+ verbose = 'short',
30
+ } = {}) {
31
+ if (typeof modules === 'string') {
32
+ modules = [modules];
33
+ }
34
+
35
+ switch (verbose) {
36
+ case '0':
37
+ case 'false':
38
+ case false:
39
+ verbose = 'none';
40
+ break;
41
+
42
+ case '1':
43
+ case 'true':
44
+ case true:
45
+ verbose = 'short';
46
+ break;
47
+
48
+ case '2':
49
+ verbose = 'full';
50
+ break;
51
+ }
52
+
53
+ let dotpiModulesDestination;
54
+ let dotpiModulesConfiguration;
55
+ try {
56
+ ({
57
+ modulesPath: dotpiModulesDestination,
58
+ modulesConfiguration: dotpiModulesConfiguration,
59
+ } = await dotpiConfigurationGet({dotpiRoot, prefix}) );
60
+ } catch (error) {
61
+ echo.error(`Failed to get dotpi configuration: ${error.message}`);
62
+ process.exit(1);
63
+ }
64
+
65
+ // no parallelisation to install modules
66
+ let moduleToInstall;
67
+ for (const module of modules) {
68
+ try {
69
+ const moduleRegistered = dotpiModulesConfiguration.moduleSource[module];
70
+ if (moduleRegistered) {
71
+ echo.info(`Module '${module}' is registered as '${moduleRegistered}'`);
72
+ moduleToInstall = moduleRegistered;
73
+ } else {
74
+ moduleToInstall = module;
75
+ }
76
+
77
+ let output;
78
+ let cwd;
79
+
80
+ if(verbose === 'full') {
81
+ console.log(`Getting '${moduleToInstall}' definition`);
82
+ }
83
+ const moduleDefinition = await definitionGet(moduleToInstall);
84
+ const { name: moduleName } = moduleDefinition;
85
+
86
+ // 2-steps install as npm errors when installing from git
87
+ // npm error git dep preparation failed
88
+
89
+ if(verbose !== 'none') {
90
+ echo.info(`Installing module '${moduleToInstall}' in '${dotpiModulesDestination}'`);
91
+ }
92
+ cwd = dotpiModulesDestination;
93
+ output = await $({
94
+ cwd,
95
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
96
+ verbose: (verbose === 'full' ? 'full' : 'none'),
97
+ // minimal install in the modules directory
98
+ })`
99
+ npm --prefix ${cwd}
100
+ install --no-fund
101
+ --install-strategy nested
102
+ --omit dev
103
+ --save
104
+ --ignore-scripts
105
+ --
106
+ ${moduleToInstall}
107
+ `;
108
+
109
+ await symlink(
110
+ path.join('.', 'node_modules'),
111
+ path.join(dotpiModulesDestination, 'dotpi_modules')
112
+ );
113
+
114
+ if(verbose === 'full') {
115
+ echo.info(`Installing ${moduleToInstall} dependencies`)
116
+ }
117
+ cwd = path.resolve(dotpiModulesDestination, 'node_modules', moduleName);
118
+
119
+ // perform a clean install
120
+ await fs.rm(path.resolve(cwd, 'node_modules'), {
121
+ recursive: true,
122
+ force: true,
123
+ });
124
+
125
+ output = await $({
126
+ cwd,
127
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
128
+ verbose: (verbose === 'full' ? 'full' : 'none'),
129
+ // complete install within the module itself
130
+ // be sure to install links for relative dependencies also
131
+ // run postinstall script
132
+ })`
133
+ npm --prefix ${cwd}
134
+ install --no-fund
135
+ --omit dev
136
+ --install-links
137
+ `;
138
+
139
+ } catch (error) {
140
+ echo.error(`Failed to install ${moduleToInstall}: ${error.message}`);
141
+ process.exit(1);
142
+ }
143
+
144
+ }
145
+ }