Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignores in addon generator and workspaces info #5235

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/generator-volto/generators/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,21 @@ module.exports = class extends Generator {
// const packageJSON = JSON.parse(fs.readFileSync(pkgJson, 'utf8'));
const name = this.globals.name;

packageJSON.addons = [...(packageJSON.addons || []), name];
if (!packageJSON.addons) {
packageJSON.addons = [];
}

if (!packageJSON.addons.includes(name)) {
packageJSON.addons = [...(packageJSON.addons || []), name];
}

if (!packageJSON.workspaces) {
packageJSON.workspaces = [];
}

if (!packageJSON.workspaces.includes(`src/addons/${this.globals.name}`)) {
packageJSON.workspaces.push(`src/addons/${this.globals.name}`);
}

fs.writeFileSync(pkgJson, `${JSON.stringify(packageJSON, null, 2)}`);
};
Expand All @@ -68,6 +82,10 @@ module.exports = class extends Generator {
`${JSON.stringify({ ...mrsDeveloperJson, ...template }, null, 2)}`,
);
};

this.addToIgnoreFile = async function (ignoreFile) {
fs.appendFileSync(ignoreFile, `\n!src/addons/${this.globals.name}`);
};
}

async prompting() {
Expand Down Expand Up @@ -146,6 +164,9 @@ Run "npm install -g @plone/generator-volto" to update.`,
return;
}

const gitIgnore = path.join(process.cwd(), '.gitignore');
const eslintIgnore = path.join(process.cwd(), '.eslintignore');
const prettierIgnore = path.join(process.cwd(), '.prettierignore');
const pkgJson = path.join(process.cwd(), 'package.json');
const mrsDeveloperJson = path.join(process.cwd(), 'mrs.developer.json');

Expand All @@ -159,6 +180,9 @@ Run "npm install -g @plone/generator-volto" to update.`,
return;
}

await this.addToIgnoreFile(gitIgnore);
await this.addToIgnoreFile(eslintIgnore);
await this.addToIgnoreFile(prettierIgnore);
// Modifies project package.json and wires the new addon
await this.addAddonToPackageJSON(pkgJson);
// Modifies project mrs.developer.json and wires the new addon localy
Expand Down
1 change: 1 addition & 0 deletions packages/generator-volto/news/5235.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ignores in addon generator and workspaces info @sneridagh