@wpmoo/odoo 0.8.68 → 0.9.0

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 (46) hide show
  1. package/bin/wpmoo.js +10 -0
  2. package/package.json +11 -44
  3. package/LICENSE +0 -22
  4. package/README.md +0 -510
  5. package/dist/addons-yaml.js +0 -59
  6. package/dist/args.js +0 -259
  7. package/dist/cli.js +0 -1002
  8. package/dist/cockpit/command-palette.js +0 -19
  9. package/dist/cockpit/command-registry.js +0 -91
  10. package/dist/cockpit/daily-prompts.js +0 -177
  11. package/dist/cockpit/menu.js +0 -88
  12. package/dist/cockpit/safety.js +0 -22
  13. package/dist/compose-layout.js +0 -118
  14. package/dist/daily-actions.js +0 -190
  15. package/dist/doctor.js +0 -519
  16. package/dist/environment-context.js +0 -10
  17. package/dist/environment-version.js +0 -5
  18. package/dist/environment.js +0 -136
  19. package/dist/external-assets.js +0 -153
  20. package/dist/external-templates.js +0 -86
  21. package/dist/git.js +0 -98
  22. package/dist/github.js +0 -87
  23. package/dist/help.js +0 -151
  24. package/dist/menu-navigation.js +0 -67
  25. package/dist/module-actions.js +0 -114
  26. package/dist/odoo-versions.js +0 -1
  27. package/dist/path-validation.js +0 -50
  28. package/dist/prompt-copy.js +0 -8
  29. package/dist/prompt-repositories.js +0 -34
  30. package/dist/repo-actions.js +0 -158
  31. package/dist/repo-url.js +0 -27
  32. package/dist/repository-preflight.js +0 -46
  33. package/dist/safe-reset.js +0 -217
  34. package/dist/scaffold.js +0 -161
  35. package/dist/source-actions.js +0 -65
  36. package/dist/source-manifest.js +0 -338
  37. package/dist/status.js +0 -239
  38. package/dist/templates.js +0 -754
  39. package/dist/types.js +0 -1
  40. package/dist/update-check.js +0 -106
  41. package/dist/version.js +0 -19
  42. package/docs/assets/patreon-donate.png +0 -0
  43. package/docs/assets/wpmoo-banner.png +0 -0
  44. package/docs/external-resources.md +0 -136
  45. package/docs/generated-environment-verification.md +0 -140
  46. package/docs/handoff.md +0 -29
@@ -1,114 +0,0 @@
1
- import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { addModuleToSourceRepoInAddonsYaml, removeModuleFromSourceRepoInAddonsYaml, } from './addons-yaml.js';
4
- import { readEnvironmentMetadata } from './environment.js';
5
- import { realGit, stageAll } from './git.js';
6
- import { pathUnderBase, validateModuleName, validateRepoPath } from './path-validation.js';
7
- import { readAddonsYaml, writeAddonsYaml } from './repo-actions.js';
8
- const validSourceTypes = ['private', 'oca', 'external'];
9
- function normalizeSourceType(value) {
10
- return validSourceTypes.includes(value) ? value : 'private';
11
- }
12
- function sourceRepoPath(target, sourceType, repoPath) {
13
- return pathUnderBase(join(target, `odoo/custom/src/${sourceType}`), repoPath, 'repo path');
14
- }
15
- function modulePath(target, sourceType, repoPath, moduleName) {
16
- return pathUnderBase(sourceRepoPath(target, sourceType, repoPath), moduleName, 'module name');
17
- }
18
- function titleizeModule(moduleName) {
19
- return moduleName
20
- .split(/[_-]+/)
21
- .filter(Boolean)
22
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
23
- .join(' ');
24
- }
25
- function manifestContent(moduleName, odooVersion) {
26
- return `{
27
- "name": "${titleizeModule(moduleName)}",
28
- "version": "${odooVersion}.1.0.0",
29
- "category": "Productivity",
30
- "summary": "TODO",
31
- "depends": ["base"],
32
- "data": [
33
- "security/ir.model.access.csv",
34
- ],
35
- "installable": True,
36
- "application": False,
37
- "license": "LGPL-3",
38
- }
39
- `;
40
- }
41
- async function writeIfMissing(path, content) {
42
- try {
43
- await readFile(path, 'utf8');
44
- }
45
- catch {
46
- await writeFile(path, content, 'utf8');
47
- }
48
- }
49
- async function usesAddonsYaml(target) {
50
- const metadata = await readEnvironmentMetadata(target);
51
- return metadata?.engine !== 'compose';
52
- }
53
- export async function addModuleToSourceRepo(options, git = realGit) {
54
- const repoPath = validateRepoPath(options.repoPath);
55
- const moduleName = validateModuleName(options.moduleName);
56
- const sourceType = normalizeSourceType(options.sourceType);
57
- const destination = modulePath(options.target, sourceType, repoPath, moduleName);
58
- await mkdir(join(destination, 'models'), { recursive: true });
59
- await mkdir(join(destination, 'security'), { recursive: true });
60
- await mkdir(join(destination, 'views'), { recursive: true });
61
- await writeIfMissing(join(destination, '__init__.py'), 'from . import models\n');
62
- await writeIfMissing(join(destination, '__manifest__.py'), manifestContent(moduleName, options.odooVersion));
63
- await writeIfMissing(join(destination, 'models/__init__.py'), '');
64
- await writeIfMissing(join(destination, 'security/ir.model.access.csv'), 'id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink\n');
65
- await writeIfMissing(join(destination, 'views/.gitkeep'), '');
66
- if (sourceType === 'private' && (await usesAddonsYaml(options.target))) {
67
- const addonsYaml = await readAddonsYaml(options.target);
68
- await writeAddonsYaml(options.target, addModuleToSourceRepoInAddonsYaml(addonsYaml, repoPath, moduleName));
69
- }
70
- if (options.stage) {
71
- await stageAll(git, sourceRepoPath(options.target, sourceType, repoPath));
72
- await stageAll(git, options.target);
73
- }
74
- }
75
- export async function listModulesInSourceRepo(target, repoPath, sourceType) {
76
- const safeRepoPath = validateRepoPath(repoPath);
77
- const resolvedSourceType = normalizeSourceType(sourceType);
78
- try {
79
- const entries = await readdir(sourceRepoPath(target, resolvedSourceType, safeRepoPath), { withFileTypes: true });
80
- const modules = await Promise.all(entries
81
- .filter((entry) => entry.isDirectory())
82
- .map(async (entry) => {
83
- try {
84
- await readFile(join(sourceRepoPath(target, resolvedSourceType, safeRepoPath), entry.name, '__manifest__.py'), 'utf8');
85
- return entry.name;
86
- }
87
- catch {
88
- return undefined;
89
- }
90
- }));
91
- return modules.filter((moduleName) => Boolean(moduleName)).sort();
92
- }
93
- catch {
94
- return [];
95
- }
96
- }
97
- export async function removeModuleFromSourceRepo(options, git = realGit) {
98
- const repoPath = validateRepoPath(options.repoPath);
99
- const moduleName = validateModuleName(options.moduleName);
100
- const sourceType = normalizeSourceType(options.sourceType);
101
- if (sourceType === 'private' && (await usesAddonsYaml(options.target))) {
102
- const addonsYaml = await readAddonsYaml(options.target);
103
- await writeAddonsYaml(options.target, removeModuleFromSourceRepoInAddonsYaml(addonsYaml, repoPath, moduleName));
104
- }
105
- if (options.deleteFiles) {
106
- await rm(modulePath(options.target, sourceType, repoPath, moduleName), { recursive: true, force: true });
107
- }
108
- if (options.stage) {
109
- if (options.deleteFiles) {
110
- await stageAll(git, sourceRepoPath(options.target, sourceType, repoPath));
111
- }
112
- await stageAll(git, options.target);
113
- }
114
- }
@@ -1 +0,0 @@
1
- export const supportedOdooVersions = ['19.0', '18.0', '17.0', '16.0'];
@@ -1,50 +0,0 @@
1
- import { isAbsolute, relative, resolve } from 'node:path';
2
- const windowsDrivePattern = /^[a-zA-Z]:/;
3
- function invalidPathError(label) {
4
- return new Error(`Invalid ${label}: use a single path segment without traversal.`);
5
- }
6
- export function validatePathSegment(value, label) {
7
- const normalized = value.trim();
8
- if (!normalized) {
9
- throw new Error(`Invalid ${label}: value is required.`);
10
- }
11
- if (normalized === '.' ||
12
- normalized === '..' ||
13
- normalized.includes('/') ||
14
- normalized.includes('\\') ||
15
- normalized.includes('\0') ||
16
- normalized.includes(':') ||
17
- isAbsolute(normalized) ||
18
- windowsDrivePattern.test(normalized)) {
19
- throw invalidPathError(label);
20
- }
21
- return normalized;
22
- }
23
- export function isValidPathSegment(value) {
24
- try {
25
- validatePathSegment(value, 'path');
26
- return true;
27
- }
28
- catch {
29
- return false;
30
- }
31
- }
32
- export function validateRepoPath(value) {
33
- return validatePathSegment(value, 'repo path');
34
- }
35
- export function validateModuleName(value) {
36
- return validatePathSegment(value, 'module name');
37
- }
38
- export function validateAddonName(value) {
39
- return validatePathSegment(value, 'addon name');
40
- }
41
- export function pathUnderBase(base, segment, label) {
42
- const safeSegment = validatePathSegment(segment, label);
43
- const resolvedBase = resolve(base);
44
- const destination = resolve(resolvedBase, safeSegment);
45
- const relativePath = relative(resolvedBase, destination);
46
- if (relativePath === '' || relativePath.startsWith('..') || isAbsolute(relativePath)) {
47
- throw invalidPathError(label);
48
- }
49
- return destination;
50
- }
@@ -1,8 +0,0 @@
1
- export function renderRepositorySetupNote(product) {
2
- return [
3
- `Dev repo: ${product}_dev`,
4
- `Source repo: ${product}`,
5
- `Local folder: ./${product}_dev`,
6
- `Submodule path: odoo/custom/src/private/${product}`,
7
- ].join('\n');
8
- }
@@ -1,34 +0,0 @@
1
- import { confirm, isCancel, text } from '@clack/prompts';
2
- import { handlePromptCancel, menuPromptMessage } from './menu-navigation.js';
3
- const defaultPrompt = {
4
- confirm,
5
- text,
6
- };
7
- export async function promptRepositoryUrl({ label, suggestedUrl, placeholder, prompt = defaultPrompt, cancelAction = 'exit', }) {
8
- if (suggestedUrl) {
9
- const useSuggested = await prompt.confirm({
10
- message: `${menuPromptMessage(`Use ${label}? (Y/n)`, cancelAction)}\n${suggestedUrl}`,
11
- active: 'Y',
12
- inactive: 'n',
13
- initialValue: true,
14
- });
15
- if (isCancel(useSuggested)) {
16
- handlePromptCancel(true, cancelAction);
17
- }
18
- if (useSuggested) {
19
- return suggestedUrl;
20
- }
21
- }
22
- const value = await prompt.text({
23
- message: menuPromptMessage(label, cancelAction),
24
- placeholder,
25
- validate: (input) => (input.trim() ? undefined : `Enter the ${label.toLowerCase()}.`),
26
- });
27
- if (isCancel(value)) {
28
- handlePromptCancel(true, cancelAction);
29
- }
30
- if (typeof value === 'string' && value.trim()) {
31
- return value.trim();
32
- }
33
- throw new Error(`${label} is required`);
34
- }
@@ -1,158 +0,0 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { addSourceRepoToAddonsYaml, removeSourceRepoFromAddonsYaml } from './addons-yaml.js';
4
- import { readEnvironmentMetadata, removeSourceRepoMetadata, upsertSourceRepoMetadata } from './environment.js';
5
- import { ensureRemoteHasBranch, ensureSubmodule, hasUncommittedChanges, realGit, removeSubmodule, stageAll, } from './git.js';
6
- import { isValidPathSegment, validateRepoPath } from './path-validation.js';
7
- import { inferRepoPath } from './repo-url.js';
8
- import { removeSourceManifestEntry, upsertSourceManifestEntry } from './source-manifest.js';
9
- export const addonsYamlHeader = `# Addons activated from source submodules.
10
- #
11
- # Source repos are managed as Git submodules under odoo/custom/src/private (product code).
12
- # OCA/external source repos can be placed under odoo/custom/src/oca and odoo/custom/src/external.
13
- # Do not duplicate these same repos in repos.yaml.
14
- `;
15
- const validSourceTypes = ['private', 'oca', 'external'];
16
- function normalizeSourceType(value) {
17
- return validSourceTypes.includes(value) ? value : 'private';
18
- }
19
- function sourceSubmodulePath(sourceType, repoPath) {
20
- return `odoo/custom/src/${sourceType}/${validateRepoPath(repoPath)}`;
21
- }
22
- function resolveSourceTypeFromSubmodulePath(submodulePath) {
23
- const match = /^odoo\/custom\/src\/(private|oca|external)\//.exec(submodulePath);
24
- if (!match)
25
- return undefined;
26
- return match[1];
27
- }
28
- async function listGitmoduleRepos(target) {
29
- try {
30
- const gitmodules = await readFile(join(target, '.gitmodules'), 'utf8');
31
- return [...gitmodules.matchAll(/^\s*path\s*=\s*odoo\/custom\/src\/(private|oca|external)\/(.+)$/gm)]
32
- .map((match) => ({ sourceType: match[1], path: match[2].trim() }))
33
- .filter((entry) => isValidPathSegment(entry.path));
34
- }
35
- catch {
36
- return [];
37
- }
38
- }
39
- async function resolveSubmodulePathFromConfig(target, repoPath, sourceType) {
40
- if (sourceType) {
41
- return sourceSubmodulePath(sourceType, validateRepoPath(repoPath));
42
- }
43
- const repoMatches = (await listGitmoduleRepos(target)).filter((repo) => repo.path === repoPath);
44
- if (repoMatches.length === 1) {
45
- return sourceSubmodulePath(repoMatches[0].sourceType, repoPath);
46
- }
47
- if (repoMatches.length > 1) {
48
- const sorted = repoMatches.map((repo) => repo.sourceType).sort();
49
- throw new Error(`Source repo ${repoPath} exists in multiple source directories: ${sorted.join(', ')}. Provide --source-type to disambiguate.`);
50
- }
51
- return sourceSubmodulePath('private', repoPath);
52
- }
53
- export async function readAddonsYaml(target) {
54
- try {
55
- return await readFile(join(target, 'odoo/custom/src/addons.yaml'), 'utf8');
56
- }
57
- catch {
58
- return `${addonsYamlHeader}\n`;
59
- }
60
- }
61
- export async function writeAddonsYaml(target, content) {
62
- const path = join(target, 'odoo/custom/src/addons.yaml');
63
- await mkdir(join(path, '..'), { recursive: true });
64
- await writeFile(path, content, 'utf8');
65
- }
66
- function composeAddonsPath() {
67
- return '/usr/lib/python3/dist-packages/odoo/addons,/mnt/extra-addons,/mnt/wpmoo-addons';
68
- }
69
- async function isComposeEnvironment(target) {
70
- const metadata = await readEnvironmentMetadata(target);
71
- return metadata?.engine === 'compose';
72
- }
73
- export async function syncComposeOdooConfAddonsPath(target) {
74
- if (!(await isComposeEnvironment(target))) {
75
- return;
76
- }
77
- const configPath = join(target, 'etc/odoo.conf');
78
- let content;
79
- try {
80
- content = await readFile(configPath, 'utf8');
81
- }
82
- catch {
83
- return;
84
- }
85
- const addonsPathLine = `addons_path = ${composeAddonsPath()}`;
86
- const nextContent = /^addons_path\s*=.*$/m.test(content)
87
- ? content.replace(/^addons_path\s*=.*$/m, addonsPathLine)
88
- : `${content.trimEnd()}\n${addonsPathLine}\n`;
89
- if (nextContent !== content) {
90
- await writeFile(configPath, nextContent, 'utf8');
91
- }
92
- }
93
- export async function addModuleRepo(options, git = realGit) {
94
- const repoPath = validateRepoPath(options.repoPath?.trim() || inferRepoPath(options.repoUrl));
95
- const sourceType = normalizeSourceType(options.sourceType);
96
- const submodulePath = sourceSubmodulePath(sourceType, repoPath);
97
- await ensureRemoteHasBranch(git, options.target, options.repoUrl, options.odooVersion, options.initEmptyRepos);
98
- await mkdir(join(options.target, 'odoo/custom/src', sourceType), { recursive: true });
99
- await ensureSubmodule(git, options.target, options.repoUrl, options.odooVersion, submodulePath);
100
- const listedRepos = await listModuleRepos(options.target);
101
- if (!listedRepos.includes(repoPath)) {
102
- throw new Error(`Source repo was added but is not registered in .gitmodules: ${repoPath}`);
103
- }
104
- await upsertSourceRepoMetadata(options.target, {
105
- url: options.repoUrl,
106
- path: repoPath,
107
- addons: [repoPath],
108
- sourceType,
109
- });
110
- await upsertSourceManifestEntry(options.target, {
111
- type: sourceType,
112
- path: repoPath,
113
- url: options.repoUrl,
114
- branch: options.odooVersion,
115
- addons: [repoPath],
116
- });
117
- if (!(await isComposeEnvironment(options.target))) {
118
- const addonsYaml = await readAddonsYaml(options.target);
119
- if (sourceType === 'private') {
120
- await writeAddonsYaml(options.target, addSourceRepoToAddonsYaml(addonsYaml, {
121
- path: repoPath,
122
- addons: [repoPath],
123
- }));
124
- }
125
- }
126
- await syncComposeOdooConfAddonsPath(options.target);
127
- if (options.stage) {
128
- await stageAll(git, options.target);
129
- }
130
- }
131
- export async function listModuleRepos(target) {
132
- return (await listGitmoduleRepos(target)).map((repo) => repo.path).sort();
133
- }
134
- export async function removeModuleRepo(options, git = realGit) {
135
- const repoPath = validateRepoPath(options.repoPath);
136
- const sourceType = options.sourceType ? normalizeSourceType(options.sourceType) : undefined;
137
- const submodulePath = await resolveSubmodulePathFromConfig(options.target, repoPath, sourceType);
138
- const fullSubmodulePath = join(options.target, submodulePath);
139
- const resolvedSourceType = sourceType ?? resolveSourceTypeFromSubmodulePath(submodulePath);
140
- if (await hasUncommittedChanges(git, fullSubmodulePath)) {
141
- throw new Error(`Cannot remove ${repoPath}: submodule has uncommitted changes.`);
142
- }
143
- await removeSubmodule(git, options.target, submodulePath);
144
- await removeSourceRepoMetadata(options.target, repoPath, resolvedSourceType);
145
- if (resolvedSourceType) {
146
- await removeSourceManifestEntry(options.target, resolvedSourceType, repoPath);
147
- }
148
- if (!(await isComposeEnvironment(options.target))) {
149
- const addonsYaml = await readAddonsYaml(options.target);
150
- if (resolvedSourceType === 'private') {
151
- await writeAddonsYaml(options.target, removeSourceRepoFromAddonsYaml(addonsYaml, repoPath));
152
- }
153
- }
154
- await syncComposeOdooConfAddonsPath(options.target);
155
- if (options.stage) {
156
- await stageAll(git, options.target);
157
- }
158
- }
package/dist/repo-url.js DELETED
@@ -1,27 +0,0 @@
1
- import { basename } from 'node:path';
2
- export function normalizeRepositoryUrl(repoUrl) {
3
- const trimmed = repoUrl.trim();
4
- const withoutSuffix = trimmed.replace(/[?#].*$/, '').replace(/\/+$/, '').replace(/\.git$/, '');
5
- const orgPageMatch = withoutSuffix.match(/^https:\/\/github\.com\/orgs\/([^/]+)\/([^/]+)$/);
6
- if (orgPageMatch) {
7
- return `https://github.com/${orgPageMatch[1]}/${orgPageMatch[2]}.git`;
8
- }
9
- return trimmed;
10
- }
11
- export function inferRepoPath(repoUrl) {
12
- const trimmed = normalizeRepositoryUrl(repoUrl).replace(/[?#].*$/, '').replace(/\/+$/, '');
13
- const lastSegment = basename(trimmed);
14
- const withoutGit = lastSegment.replace(/\.git$/, '');
15
- if (!withoutGit) {
16
- throw new Error(`Cannot infer repository path from URL: ${repoUrl}`);
17
- }
18
- return withoutGit;
19
- }
20
- export function inferGitHubOwner(repoUrl) {
21
- const normalized = normalizeRepositoryUrl(repoUrl);
22
- const httpsMatch = normalized.match(/^https:\/\/github\.com\/([^/]+)\//);
23
- if (httpsMatch)
24
- return httpsMatch[1];
25
- const sshMatch = normalized.match(/^git@github\.com:([^/]+)\//);
26
- return sshMatch?.[1];
27
- }
@@ -1,46 +0,0 @@
1
- import { createGitHubRepository, getGitHubRepositoryStatus, githubSlug, isGitHubAuthenticated, isGitHubCliAvailable, realGitHub, } from './github.js';
2
- export function repositoryRequirements(options) {
3
- return [
4
- {
5
- label: 'Dev environment repo',
6
- url: options.devRepoUrl,
7
- defaultVisibility: 'private',
8
- },
9
- ...options.sourceRepos.map((repo) => ({
10
- label: `Source repo: ${repo.path}`,
11
- url: repo.url,
12
- defaultVisibility: 'private',
13
- })),
14
- ];
15
- }
16
- export async function findInaccessibleGitHubRepositories(options, runner = realGitHub) {
17
- return (await checkGitHubRepositories(options, runner)).inaccessible;
18
- }
19
- export async function checkGitHubRepositories(options, runner = realGitHub) {
20
- const accessible = [];
21
- const inaccessible = [];
22
- for (const requirement of repositoryRequirements(options)) {
23
- const status = await getGitHubRepositoryStatus(runner, requirement.url);
24
- if (status.status === 'accessible') {
25
- accessible.push({ ...requirement, slug: status.slug });
26
- }
27
- if (status.status === 'inaccessible') {
28
- inaccessible.push({ ...requirement, slug: status.slug });
29
- }
30
- }
31
- return { accessible, inaccessible };
32
- }
33
- export async function createGitHubRepositories(repositories, visibility, runner = realGitHub) {
34
- for (const repository of repositories) {
35
- await createGitHubRepository(runner, repository.url, visibility);
36
- }
37
- }
38
- export async function repositoryPreflightAvailable(runner = realGitHub) {
39
- return (await isGitHubCliAvailable(runner)) && (await isGitHubAuthenticated(runner));
40
- }
41
- export function manualCreateCommands(repositories) {
42
- return repositories.map((repository) => {
43
- const slug = githubSlug(repository.url) ?? repository.url;
44
- return `gh repo create ${slug} --${repository.defaultVisibility}`;
45
- });
46
- }
@@ -1,217 +0,0 @@
1
- import { chmod, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
2
- import { basename, join } from 'node:path';
3
- import { environmentMetadata, readEnvironmentMetadata } from './environment.js';
4
- import { applyExternalAsset, writeTextFile } from './external-assets.js';
5
- import { plannedExternalAssetOptions, renderComposeEnvExample } from './external-templates.js';
6
- import { realGit, stageAll } from './git.js';
7
- import { isValidPathSegment, validateAddonName, validateRepoPath } from './path-validation.js';
8
- import { readAddonsYaml } from './repo-actions.js';
9
- import { generatedFiles } from './scaffold.js';
10
- import { listGitmoduleSources } from './source-manifest.js';
11
- const safeResetProtectedPaths = [
12
- 'data',
13
- 'backups',
14
- '.env',
15
- '.gitmodules',
16
- 'odoo/custom/src/private',
17
- 'odoo/custom/src/oca',
18
- 'odoo/custom/src/external',
19
- 'odoo/custom/patches',
20
- 'odoo/custom/manifests',
21
- ].map((path) => path.replace(/\/$/, ''));
22
- const safeResetProtectedGeneratedReadmes = new Set([
23
- 'odoo/custom/src/private/README.md',
24
- 'odoo/custom/src/oca/README.md',
25
- 'odoo/custom/src/external/README.md',
26
- 'odoo/custom/patches/README.md',
27
- 'odoo/custom/manifests/README.md',
28
- ]);
29
- function isProtectedGeneratedFile(filePath) {
30
- return safeResetProtectedGeneratedReadmes.has(filePath);
31
- }
32
- function mergeEnvironmentMetadata(target, options) {
33
- const generated = environmentMetadata(options);
34
- return readFile(join(target, '.wpmoo/odoo.json'), 'utf8')
35
- .then((content) => JSON.parse(content))
36
- .then((existing) => {
37
- if (!existing || typeof existing !== 'object' || Array.isArray(existing)) {
38
- return `${JSON.stringify(generated, null, 2)}\n`;
39
- }
40
- return `${JSON.stringify({ ...existing, ...generated, sourceRepos: generated.sourceRepos }, null, 2)}\n`;
41
- })
42
- .catch(() => `${JSON.stringify(generated, null, 2)}\n`);
43
- }
44
- export function renderSafeResetPreview(target, stage) {
45
- return [
46
- 'Safe reset will refresh generated WPMoo environment files.',
47
- '',
48
- 'Target:',
49
- target,
50
- '',
51
- 'Will update:',
52
- '- .wpmoo/odoo.json',
53
- '- moo',
54
- '- .gitignore',
55
- '- .env.example',
56
- '- README.md',
57
- '- AGENTS.md',
58
- '- docs/appstore-release.md',
59
- '- External compose template assets',
60
- '- External agent skill assets when configured',
61
- '',
62
- 'Will not touch:',
63
- '- source repo folders under odoo/custom/src/private',
64
- '- module source code',
65
- '- Git history, remotes, or branches',
66
- '- .env, data, and backups',
67
- '- custom source layout directories (oca, external, patches, manifests)',
68
- '- Legacy compose template files may remain until manually removed: docs/assets/, test/, .github/',
69
- '',
70
- 'Preview-only output; files are not changed until reset is executed.',
71
- '',
72
- stage ? 'Generated changes will be staged with git add .' : 'Generated changes will not be staged.',
73
- ].join('\n');
74
- }
75
- function titleFromTarget(target) {
76
- return basename(target).replace(/_dev$/, '') || 'odoo_sample_module';
77
- }
78
- function safeResetExternalAssetOptions(options) {
79
- return plannedExternalAssetOptions(options).map((assetOptions) => ({
80
- ...assetOptions,
81
- exclude: [
82
- ...(assetOptions.exclude ?? []),
83
- ...safeResetProtectedPaths,
84
- ],
85
- }));
86
- }
87
- function parseAddonsForRepo(addonsYaml, repoPath) {
88
- const safeRepoPath = validateRepoPath(repoPath);
89
- const lines = addonsYaml.split('\n');
90
- const header = `private/${safeRepoPath}:`;
91
- const start = lines.findIndex((line) => line.trim() === header);
92
- if (start === -1)
93
- return [safeRepoPath];
94
- const addons = [];
95
- for (let index = start + 1; index < lines.length; index += 1) {
96
- const line = lines[index];
97
- if (!line.startsWith(' '))
98
- break;
99
- const match = line.trim().match(/^-\s+(.+)$/);
100
- const addon = match?.[1]?.trim();
101
- if (addon && isValidPathSegment(addon)) {
102
- addons.push(validateAddonName(addon));
103
- }
104
- }
105
- return addons.length ? addons : [safeRepoPath];
106
- }
107
- function parseRepoPathsFromAddonsYaml(addonsYaml) {
108
- return [...addonsYaml.matchAll(/^private\/(.+):$/gm)]
109
- .map((match) => match[1].trim())
110
- .filter((repoPath) => repoPath && isValidPathSegment(repoPath))
111
- .map(validateRepoPath);
112
- }
113
- async function readSubmoduleUrl(target, repoPath, sourceType) {
114
- const safeRepoPath = validateRepoPath(repoPath);
115
- try {
116
- const gitmodules = await readFile(join(target, '.gitmodules'), 'utf8');
117
- const escapedPath = `odoo/custom/src/${sourceType}/${safeRepoPath}`;
118
- const sections = gitmodules.split(/\n(?=\[submodule )/);
119
- const section = sections.find((value) => value.includes(`path = ${escapedPath}`));
120
- const url = section?.match(/^\s*url\s*=\s*(.+)$/m)?.[1]?.trim();
121
- return url || `odoo/custom/src/${sourceType}/${safeRepoPath}`;
122
- }
123
- catch {
124
- return `odoo/custom/src/${sourceType}/${safeRepoPath}`;
125
- }
126
- }
127
- async function pathExists(path) {
128
- try {
129
- await stat(path);
130
- return true;
131
- }
132
- catch {
133
- return false;
134
- }
135
- }
136
- async function inferOptions(target) {
137
- const metadata = await readEnvironmentMetadata(target);
138
- const addonsYaml = await readAddonsYaml(target);
139
- const gitmoduleSources = await listGitmoduleSources(target);
140
- const addonRepos = parseRepoPathsFromAddonsYaml(addonsYaml);
141
- const sourceByKey = new Map();
142
- for (const repo of metadata?.sourceRepos ?? []) {
143
- if (isValidPathSegment(repo.path)) {
144
- const sourceType = repo.sourceType ?? 'private';
145
- const path = validateRepoPath(repo.path);
146
- sourceByKey.set(`${sourceType}:${path}`, { sourceType, path });
147
- }
148
- }
149
- for (const repo of gitmoduleSources) {
150
- sourceByKey.set(`${repo.type}:${repo.path}`, { sourceType: repo.type, path: repo.path });
151
- }
152
- for (const repoPath of addonRepos) {
153
- sourceByKey.set(`private:${repoPath}`, { sourceType: 'private', path: repoPath });
154
- }
155
- const sourceLocations = [...sourceByKey.values()];
156
- const product = metadata?.product ?? sourceLocations[0]?.path ?? titleFromTarget(target);
157
- const sourceRepos = await Promise.all(sourceLocations.map(async ({ sourceType, path }) => ({
158
- path,
159
- sourceType,
160
- url: metadata?.sourceRepos
161
- .find((repo) => repo.path === path && (repo.sourceType ?? 'private') === sourceType)
162
- ?.url.trim() ||
163
- gitmoduleSources.find((repo) => repo.path === path && repo.type === sourceType)?.url ||
164
- (await readSubmoduleUrl(target, path, sourceType)),
165
- addons: parseAddonsForRepo(addonsYaml, path),
166
- })));
167
- return {
168
- product,
169
- odooVersion: metadata?.odooVersion ?? '19.0',
170
- devRepo: metadata?.devRepo ?? basename(target),
171
- devRepoUrl: metadata?.devRepoUrl ?? target,
172
- sourceRepos,
173
- engine: 'compose',
174
- composeTemplateUrl: metadata?.composeTemplateUrl,
175
- composeTemplateRef: metadata?.composeTemplateRef,
176
- agentSkillsTemplateUrl: metadata?.agentSkillsTemplateUrl,
177
- agentSkillsTemplateRef: metadata?.agentSkillsTemplateRef,
178
- postgresVersion: metadata?.postgresVersion,
179
- httpPort: metadata?.httpPort,
180
- geventPort: metadata?.geventPort,
181
- target,
182
- dryRun: false,
183
- initEmptyRepos: false,
184
- stage: false,
185
- skipSubmodules: true,
186
- };
187
- }
188
- export async function safeResetEnvironment(options, git = realGit) {
189
- const scaffoldOptions = await inferOptions(options.target);
190
- const files = generatedFiles(scaffoldOptions);
191
- const externalAssets = safeResetExternalAssetOptions(scaffoldOptions);
192
- for (const file of files) {
193
- if (file.path === '.wpmoo/odoo.json') {
194
- continue;
195
- }
196
- if (isProtectedGeneratedFile(file.path) && (await pathExists(join(options.target, file.path)))) {
197
- continue;
198
- }
199
- if (file.path === 'odoo/custom/src/addons.yaml') {
200
- continue;
201
- }
202
- const destination = join(options.target, file.path);
203
- await mkdir(join(destination, '..'), { recursive: true });
204
- await writeFile(destination, file.content, 'utf8');
205
- if (file.mode !== undefined) {
206
- await chmod(destination, file.mode);
207
- }
208
- }
209
- for (const assetOptions of externalAssets) {
210
- await applyExternalAsset(assetOptions, git);
211
- }
212
- await writeTextFile(join(options.target, '.wpmoo/odoo.json'), await mergeEnvironmentMetadata(options.target, scaffoldOptions));
213
- await writeTextFile(join(options.target, '.env.example'), renderComposeEnvExample(scaffoldOptions));
214
- if (options.stage) {
215
- await stageAll(git, options.target);
216
- }
217
- }