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

Make installation available from other branches than the Infinum repo #824

Closed
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
17 changes: 16 additions & 1 deletion setup/create-wp-project/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ To make sure you use the latest version of npx command you can add `@latest` fla

## Specify version to create

If you want to specify a version of Eightshift Libs or Frontend Libs to use, you can use add two additional attributes to this command to specify a branch or release to use:
If you want to specify a version of Eightshift Libs, Frontend Libs or repository to use, you can use add two additional attributes to this command to specify a branch, release or repository to use:

```
--eightshiftLibsRepo
--eightshiftLibsBranch
--eightshiftFrontendLibsBranch
--eightshiftFrontendLibsUrl

```

Example:
Expand All @@ -56,6 +59,18 @@ You can also specify the version of the create-wp-project script like this:
npx [email protected] --eightshiftLibsBranch="release/6.0.0" --eightshiftFrontendLibsBranch="develop"
```

You can also specify the repo of the create-wp-project script like this:

```
npx create-wp-project --eightshiftLibsRepo="https://github.com/example-repository/eightshift-libs.git"
```

You can also specify the repo of the create-wp-project script like this:

```
npx create-wp-project -eightshiftFrontendLibsBranch="develop" --eightshiftFrontendLibsRepoUrl="https://github.com/example-repository/eightshift-frontend-libs.git"
```


## Use a different repository

Expand Down
14 changes: 14 additions & 0 deletions setup/create-wp-project/src/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ const scriptArguments = {
type: 'text',
skipPrompt: true,
},
eightshiftLibsRepo: {
name: 'eightshiftLibsRepo',
describe: 'Custom repository URL for the eightshift-libs (e.g., github.com/user/eightshift-libs).',
type: 'text',
default: 'infinum/eightshift-libs', // Setting default to ensure backward compatibility
skipPrompt: true,
},
eightshiftLibsBranch: {
name: 'eightshiftLibsBranch',
describe: 'Use this to override which infinum/eightshift-libs version is loaded (mainly used for testing).',
Expand All @@ -67,6 +74,13 @@ const scriptArguments = {
type: 'text',
skipPrompt: true,
},
eightshiftFrontendLibsRepoUrl: {
name: 'eightshiftFrontendLibsRepoUrl',
describe: 'Custom repository URL for the eightshift-frontend-libs (e.g., github.com/user/eightshift-frontend-libs).',
type: 'text',
default: 'infinum/eightshift-frontend-libs', // Setting default to ensure backward compatibility
skipPrompt: true,
},
};

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions setup/create-wp-project/src/commands/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.handler = async (argv) => {
if (argv.eightshiftFrontendLibsBranch) {
await installStep({
describe: `Installing Node packages`,
thisHappens: installModifiedNodeDependencies(projectPath, argv.eightshiftFrontendLibsBranch),
thisHappens: installModifiedNodeDependencies(projectPath, argv.eightshiftFrontendLibsBranch, argv.eightshiftFrontendLibsRepoUrl),
});
} else {
await installStep({
Expand All @@ -84,7 +84,7 @@ exports.handler = async (argv) => {
if (argv.eightshiftLibsBranch) {
await installStep({
describe: `Installing Composer packages`,
thisHappens: installModifiedComposerDependencies(projectPath, argv.eightshiftLibsBranch),
thisHappens: installModifiedComposerDependencies(projectPath, argv.eightshiftLibsBranch, argv.eightshiftLibsRepo),
});
} else {
await installStep({
Expand Down
18 changes: 11 additions & 7 deletions setup/create-wp-project/src/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
const { installNodePackage, installComposerPackage } = require('./basics/command-line');

const eightshiftLibsName = '';
const eightshiftLibsRepo = 'infinum/eightshift-libs';
const defaultEightshiftLibsRepo = 'infinum/eightshift-libs';
const eightshiftFrontendLibsRepo = 'infinum/eightshift-frontend-libs';
const eightshiftFrontendLibsRepoUrl = 'https://github.com/infinum/eightshift-frontend-libs';
const defaultEightshiftFrontendLibsRepoUrl = 'https://github.com/infinum/eightshift-frontend-libs';

/**
* Check if we need to modify dependencies (if user passed an alternative branch for any dependency
* Check if we need to modify dependencies (if user passed an alternative branch or repo for any dependency
* as argument)
*
* @param {object} argv List of CLI arguments.
*/
const areDependenciesModified = (argv) => {
return argv.eightshiftLibsBranch || argv.eightshiftFrontendLibsBranch;
return argv.eightshiftLibsBranch || argv.eightshiftFrontendLibsBranch || argv.eightshiftLibsRepo || argv.eightshiftFrontendLibsRepoUrl;
};

/**
* Installs node packages and modifies the frontendLibs to a specific branch.
*
* @param {string} projectPath Path to the project.
* @param {array} branch Name of the branch to pull from.
* @param {string} repo Custom repository to use if provided.
*/
const installModifiedNodeDependencies = async (projectPath, branch) => {
const installModifiedNodeDependencies = async (projectPath, branch, repo) => {
const eightshiftFrontendLibsRepoUrl = repo || defaultEightshiftFrontendLibsRepoUrl;
return installNodePackage(projectPath, `${eightshiftFrontendLibsRepoUrl}#${branch} --save`);
};

/**
* Installs composer packages and modifies the libs to a specific branch.
* Installs composer packages and modifies the libs to a specific branch or repo.
*
* @param {string} projectPath Path to the project.
* @param {array} branch Name of the branch to pull from.
* @param {string} repo Custom repository to use if provided.
*/
const installModifiedComposerDependencies = async (projectPath, branch) => {
const installModifiedComposerDependencies = async (projectPath, branch, repo) => {
const eightshiftLibsRepo = repo || defaultEightshiftLibsRepo;
return installComposerPackage(projectPath, `${eightshiftLibsRepo}:dev-${branch}`);
};

Expand Down
Loading