@dotpi/tools 1.4.0 → 2.3.3

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 (150) hide show
  1. package/NOTES.md +41 -1
  2. package/README.md +3 -13
  3. package/dotpi_root/bin/dotpi +1 -0
  4. package/dotpi_root/bin/dotpi_prepare_sd_card +34 -22
  5. package/dotpi_root/bin/dotpi_prepare_system +108 -68
  6. package/dotpi_root/bin/package.json +6 -0
  7. package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor.service +1 -5
  8. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_install +21 -0
  9. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_uninstall +17 -0
  10. package/dotpi_root/dist/@dotpi/avahi_monitor/package.json +10 -0
  11. package/dotpi_root/dist/@dotpi/javascript/bash.js +103 -0
  12. package/dotpi_root/dist/@dotpi/javascript/echo.js +13 -0
  13. package/dotpi_root/dist/@dotpi/javascript/filesystem.js +25 -0
  14. package/dotpi_root/dist/@dotpi/javascript/package.json +12 -0
  15. package/dotpi_root/dist/@dotpi/javascript/service.js +49 -0
  16. package/dotpi_root/dist/@dotpi/javascript/system.js +36 -0
  17. package/dotpi_root/dist/@dotpi/javascript/template.js +13 -0
  18. package/dotpi_root/dist/@dotpi/javascript/user.js +32 -0
  19. package/dotpi_root/dist/@dotpi/module/bin/dotpi_module +13 -0
  20. package/dotpi_root/dist/@dotpi/module/dotpi_install +52 -0
  21. package/dotpi_root/dist/@dotpi/module/dotpi_uninstall +50 -0
  22. package/dotpi_root/dist/@dotpi/module/package.json +21 -0
  23. package/dotpi_root/dist/@dotpi/module/src/configuration.js +43 -0
  24. package/dotpi_root/dist/@dotpi/module/src/createConfig.js +108 -0
  25. package/dotpi_root/dist/@dotpi/module/src/definition.js +7 -0
  26. package/dotpi_root/dist/@dotpi/module/src/index.js +0 -0
  27. package/dotpi_root/dist/@dotpi/module/src/install.js +145 -0
  28. package/dotpi_root/dist/@dotpi/module/src/uninstall.js +180 -0
  29. package/dotpi_root/etc/dotpi_environment_default.bash +16 -0
  30. package/dotpi_root/etc/dotpi_init.d/.gitkeep +0 -0
  31. package/dotpi_root/etc/dotpi_modules.json +8 -0
  32. package/dotpi_root/lib/package.json +6 -0
  33. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +7 -6
  34. package/dotpi_root/share/dotpi_audio_bluetooth/package.json +6 -0
  35. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +12 -26
  36. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +2 -2
  37. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +6 -2
  38. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +11 -0
  39. package/dotpi_root/share/dotpi_functions/dotpi_functions_user.bash +28 -0
  40. package/dotpi_root/share/dotpi_functions.bash +4 -4
  41. package/dotpi_root/share/dotpi_init.bash +7 -1
  42. package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +7 -6
  43. package/dotpi_root/share/dotpi_pipewire/dotpi_install +1 -1
  44. package/dotpi_root/share/dotpi_pipewire/package.json +9 -0
  45. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +2 -6
  46. package/dotpi_root/share/wireplumber/wireplumber.conf.d/dotpi-wireplumber-config.conf +8 -0
  47. package/lerna.json +4 -0
  48. package/package.json +12 -2
  49. package/projects/led-test/.dotpi +3 -0
  50. package/projects/led-test/README.md +16 -0
  51. package/projects/led-test/dotpi_project.bash +29 -0
  52. package/projects/qsddsqsd/.dotpi +3 -0
  53. package/projects/qsddsqsd/README.md +16 -0
  54. package/projects/qsddsqsd/dotpi_project.bash +29 -0
  55. package/src/constants.js +4 -4
  56. package/src/create-project.js +124 -56
  57. package/src/templates/dotpi_project.bash +5 -7
  58. package/src/utils.js +2 -2
  59. package/test/create-project.test.js +0 -1
  60. package/PIPEWIRE.md +0 -280
  61. package/dotpi_root/bin/.editorbackup/dotpi_firstrun.bash~ +0 -149
  62. package/dotpi_root/bin/.editorbackup/dotpi_firstrun~ +0 -177
  63. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card.bash~ +0 -425
  64. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card~ +0 -620
  65. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system.bash~ +0 -82
  66. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system~ +0 -100
  67. package/dotpi_root/bin/.editorbackup/dotpi~ +0 -61
  68. package/dotpi_root/bin/.editorbackup/prepare_sd_card.bash~ +0 -252
  69. package/dotpi_root/etc/.editorbackup/dotpi_environment_default.bash~ +0 -49
  70. package/dotpi_root/etc/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  71. package/dotpi_root/etc/.editorbackup/dotpi_environment_project.bash~ +0 -33
  72. package/dotpi_root/etc/.editorbackup/dotpi_tarignore~ +0 -4
  73. package/dotpi_root/share/.editorbackup/coucou~ +0 -1
  74. package/dotpi_root/share/.editorbackup/dotpi_environment.bash~ +0 -9
  75. package/dotpi_root/share/.editorbackup/dotpi_functions.bash~ +0 -11
  76. package/dotpi_root/share/.editorbackup/dotpi_functions_configuration.bash~ +0 -420
  77. package/dotpi_root/share/.editorbackup/dotpi_functions_connection.bash~ +0 -358
  78. package/dotpi_root/share/.editorbackup/dotpi_init.bash~ +0 -18
  79. package/dotpi_root/share/dotpi_audio_alsa/dotpi_audio_alsa.service +0 -15
  80. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth.service~ +0 -24
  81. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_command~ +0 -80
  82. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_start_command~ +0 -26
  83. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_stop_command~ +0 -30
  84. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_bluetooth_audio.service~ +0 -21
  85. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_bluetooth.bash~ +0 -256
  86. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_device.bash~ +0 -287
  87. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_bluetooth_audio.bash~ +0 -7
  88. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_configuration.bash~ +0 -428
  89. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_connection.bash~ +0 -194
  90. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_daemon.bash~ +0 -26
  91. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcard.bash~ +0 -287
  92. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcards.bash~ +0 -12
  93. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_system.bash~ +0 -158
  94. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_utils.bash~ +0 -152
  95. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_bluetooth.bash~ +0 -20
  96. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_command~ +0 -17
  97. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_headphones.bash~ +0 -20
  98. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_hifiberry.bash~ +0 -16
  99. package/dotpi_root/share/jackd/.editorbackup/jackd.conf~ +0 -5
  100. package/dotpi_root/share/jackd/.editorbackup/jackd.service~ +0 -15
  101. package/dotpi_root/share/jackd/.editorbackup/jackd_headphones.conf~ +0 -5
  102. package/dotpi_root/share/jackd/dotpi_jack_simple_client.service +0 -23
  103. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +0 -18
  104. package/dotpi_root/share/jackd/dotpi_jackd_command +0 -26
  105. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +0 -21
  106. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +0 -17
  107. package/dotpi_root/share/jackd/jackd.service +0 -22
  108. package/dotpi_root/share/wireplumber/.editorbackup/8zzz-dotpi-wireplumber-config.lua~ +0 -1
  109. package/projects/old/dev.bak/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  110. package/projects/old/dev.bak/.editorbackup/dotpi_environment_project.bash~ +0 -33
  111. package/projects/old/dev.bak/.editorbackup/wpa_supplicant.conf~ +0 -37
  112. package/projects/old/dev.bak/dotpi_environment_instance.bash +0 -1
  113. package/projects/old/dev.bak/dotpi_environment_project.bash +0 -46
  114. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI-A114.nmconnection~ +0 -24
  115. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI.nmconnection~ +0 -24
  116. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +0 -24
  117. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/onze.nmconnection~ +0 -22
  118. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/welcome.nmconnection~ +0 -23
  119. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI-A114.nmconnection +0 -23
  120. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI.nmconnection +0 -23
  121. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/Livebox-97C6_wifi_invite.nmconnection +0 -24
  122. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/onze.nmconnection +0 -24
  123. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/welcome.nmconnection +0 -23
  124. package/projects/old/dev.bak/network/.editorbackup/DOTPI-A114.nmconnection~ +0 -24
  125. package/projects/old/dev.bak/network/.editorbackup/DOTPI.nmconnection~ +0 -24
  126. package/projects/old/dev.bak/network/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +0 -24
  127. package/projects/old/dev.bak/network/.editorbackup/onze.nmconnection~ +0 -22
  128. package/projects/old/dev.bak/network/.editorbackup/welcome.nmconnection~ +0 -23
  129. package/projects/old/dev.bak/network/AccueilCie.nmconnection +0 -24
  130. package/projects/old/dev.bak/network/DOTPI-A114.nmconnection +0 -23
  131. package/projects/old/dev.bak/network/DOTPI.nmconnection +0 -23
  132. package/projects/old/dev.bak/network/Livebox-97C6_wifi_invite.nmconnection +0 -25
  133. package/projects/old/dev.bak/network/onze.nmconnection +0 -24
  134. package/projects/old/dev.bak/network/welcome.nmconnection +0 -23
  135. package/projects/old/dev.bak/network/wifi-access-point.nmconnection +0 -23
  136. package/projects/old/dev.bak/network/wifi-internet.nmconnection +0 -24
  137. package/projects/old/dev.bak/network/wifi-ircam-public.nmconnection +0 -24
  138. package/projects/old/dev.bak/network/wifi-local.nmconnection +0 -22
  139. package/projects/old/dev.bak/network/wifi-welcome.nmconnection +0 -24
  140. package/projects/old/dev.bak/wpa_supplicant.conf +0 -43
  141. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_instance.bash~ +0 -1
  142. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_project.bash~ +0 -26
  143. package/projects/old/example-complete.bak/.editorbackup/dotpi_project.bash~ +0 -21
  144. package/projects/old/example-complete.bak/.editorbackup/dotpi_tmp.bash~ +0 -3
  145. package/projects/old/example-complete.bak/.editorbackup/wpa_supplicant.conf~ +0 -37
  146. package/projects/old/example-complete.bak/configuration/.editorbackup/dotpi_project.bash~ +0 -21
  147. package/projects/old/example-complete.bak/configuration/dotpi_project.bash +0 -21
  148. package/projects/old/example-complete.bak/configuration/jackd/.editorbackup/dotpi_jackd.bash~ +0 -14
  149. package/projects/old/example-complete.bak/configuration/jackd/dotpi_jackd.bash +0 -14
  150. /package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor_command +0 -0
@@ -0,0 +1,49 @@
1
+ import { $ } from 'execa';
2
+
3
+ export async function install({
4
+ user = false,
5
+ file,
6
+ } = {}) {
7
+ if (process.getuid() !== 0) {
8
+ // even a user service must be installed by root
9
+ throw new Error('Only the root user can install a service');
10
+ }
11
+
12
+ try {
13
+ const output = await $({
14
+ shell: '/bin/bash', // for dotpi environment
15
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
16
+ all: true, // interleave stdout and stderr
17
+ })`dotpi service-install ${user ? '--user' : ''} ${file}`;
18
+
19
+ return output;
20
+
21
+ } catch (error) {
22
+ throw error;
23
+ }
24
+
25
+ }
26
+
27
+ export async function uninstall({
28
+ user = false,
29
+ name,
30
+ } = {}) {
31
+ if (process.getuid() !== 0) {
32
+ // even a user service must be installed by root
33
+ throw new Error('Only the root user can uninstall a service');
34
+ }
35
+
36
+ try {
37
+ const output = await $({
38
+ shell: '/bin/bash', // for dotpi environment
39
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
40
+ all: true, // interleave stdout and stderr
41
+ })`dotpi service-uninstall ${user ? '--user' : ''} ${name}`;
42
+
43
+ return output;
44
+
45
+ } catch (error) {
46
+ throw error;
47
+ }
48
+
49
+ }
@@ -0,0 +1,36 @@
1
+ import fs from 'node:fs/promises';
2
+ import{ $ } from 'execa';
3
+
4
+ import { regularUserIdGet } from './user.js';
5
+ import { variableRead } from './bash.js';
6
+
7
+ export const dotpiRootDefault = '/opt/dotpi';
8
+
9
+ export async function dotpiRootGet() {
10
+
11
+ let dotpiRoot = process.env.DOTPI_ROOT;
12
+ if (!dotpiRoot) {
13
+ const uid = regularUserIdGet();
14
+ dotpiRoot = await variableRead({ uid, variable: 'DOTPI_ROOT' });
15
+ }
16
+
17
+ if (!dotpiRoot) {
18
+ try {
19
+ await fs.access(dotpiRootDefault);
20
+ dotpiRoot = dotpiRootDefault;
21
+ } catch (error) {
22
+ throw new Error(`DOTPI_ROOT not set and ${dotpiRootDefault} not found`);
23
+ }
24
+ }
25
+
26
+ return dotpiRoot;
27
+ }
28
+
29
+ export async function isRaspberryPi() {
30
+ try {
31
+ const output = await $`dotpi system_is_raspberry_pi`;
32
+ return output.exitCode === 0;
33
+ } catch (error) {
34
+ return false;
35
+ }
36
+ }
@@ -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,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,21 @@
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
+ }
@@ -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
+ }