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

Improve WP Project detection #41

Merged
merged 6 commits into from
Jan 23, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ jobs:

- name: Build
run: pnpm build

- name: Bundle
run: pnpm bundle:all
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "module",
"scripts": {
"build": "wireit",
"bundle:all": "wpdev bundle --all",
"bundle:changed": "wireit",
"dev": "wireit",
"dev:cleanup": "wireit",
Expand Down
2 changes: 0 additions & 2 deletions plugins/wptelegram-comments/wpdev.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* @type {import("@wpsocio/wpdev").ProjectConfig['getProjectInfo']}
*/
export const getProjectInfo = () => ({
title: 'WP Telegram Comments',
key: 'wptelegram_comments',
slug: 'wptelegram-comments',
textDomain: 'wptelegram-comments',
});

export { getBundleConfig } from '../wpdev.base.project.js';
2 changes: 0 additions & 2 deletions plugins/wptelegram-login/wpdev.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* @type {import("@wpsocio/wpdev").ProjectConfig['getProjectInfo']}
*/
export const getProjectInfo = () => ({
title: 'WP Telegram Login',
key: 'wptelegram_login',
slug: 'wptelegram-login',
textDomain: 'wptelegram-login',
});

export { getBundleConfig } from '../wpdev.base.project.js';
2 changes: 0 additions & 2 deletions plugins/wptelegram-widget/wpdev.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* @type {import("@wpsocio/wpdev").ProjectConfig['getProjectInfo']}
*/
export const getProjectInfo = () => ({
title: 'WP Telegram Widget',
key: 'wptelegram_widget',
slug: 'wptelegram-widget',
textDomain: 'wptelegram-widget',
});

export { getBundleConfig } from '../wpdev.base.project.js';
2 changes: 0 additions & 2 deletions plugins/wptelegram/wpdev.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* @type {import("@wpsocio/wpdev").ProjectConfig['getProjectInfo']}
*/
export const getProjectInfo = () => ({
title: 'WP Telegram',
key: 'wptelegram',
slug: 'wptelegram',
textDomain: 'wptelegram',
});

export { getBundleConfig } from '../wpdev.base.project.js';
18 changes: 10 additions & 8 deletions tools/wpdev/src/base-commands/WithProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PROJECT_CONFIG_FILE_NAME,
ROOT_CONFIG_FILE_NAME,
} from '../utils/config.js';
import { WPProject, getStandalonePackage } from '../utils/tools.js';
import { WPProject, getStandaloneProject } from '../utils/projects.js';
import { WPMonorepo } from '../utils/wp-monorepo.js';
import { WithRootDirAsCwd } from './WithRootDirAsCwd.js';

Expand Down Expand Up @@ -65,7 +65,7 @@ export abstract class WithProjects<

const expectedPkgJsonConfig =
this.cliConfig.operationMode === 'wp-monorepo'
? 'wpdev.belongsTo'
? 'wpdev.projectType'
: 'wpdev.isRoot';

messages.push(
Expand Down Expand Up @@ -99,13 +99,13 @@ export abstract class WithProjects<

if (this.cliConfig.operationMode === 'wp-monorepo') {
if (this.flags['from-changeset']) {
this.projects = this.wpMonorepo.getProjectsToRelease(
this.projects = await this.wpMonorepo.getProjectsToRelease(
this.flags['changeset-json'],
);
} else if (this.flags.all) {
this.projects = this.wpMonorepo.getManagedProjects();
this.projects = await this.wpMonorepo.getManagedProjects();
} else if (argv.length) {
this.projects = this.wpMonorepo.getProjectsByName(
this.projects = await this.wpMonorepo.getProjectsByName(
argv as Array<string>,
);
} else {
Expand All @@ -117,16 +117,18 @@ export abstract class WithProjects<
}

protected async detectProject() {
const project = await getStandalonePackage(this.commandCwd);
const project = await getStandaloneProject(this.commandCwd);

if (!project) {
throw new Error('Could not detect project.');
}

this.log('🔍 Detected project: ', chalk.bold(project.packageJson.name));

if (project.packageJson.wpdev?.belongsTo) {
this.projects = new Map([[project.packageJson.name, project]]);
if (project.wpdev?.projectType) {
this.projects = new Map([
[project.packageJson.name, project as WPProject],
]);

return;
}
Expand Down
8 changes: 5 additions & 3 deletions tools/wpdev/src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
} from '../utils/i18n.js';
import { copyFiles, getDistIgnorePattern, zipDir } from '../utils/misc.js';
import {
WPProject,
getNextVersion,
getProjectConfig,
getProjectBundleConfig,
runScript,
} from '../utils/projects.js';
import { updateRequirements } from '../utils/requirements.js';
import { minifyStyles } from '../utils/styles.js';
import { WPProject } from '../utils/tools.js';
import { updateVersion } from '../utils/versions.js';

type TaskWrapper = Parameters<ListrTask['task']>[1];
Expand Down Expand Up @@ -146,7 +146,9 @@ export default class Bundle extends WithProjects<typeof Bundle> {
async prepareForDist(project: WPProject, task: TaskWrapper) {
const version = this.getVersion(project, task);

const { projectInfo, bundle } = await getProjectConfig(project, version);
const projectInfo = project.wpdev;

const bundle = await getProjectBundleConfig(project, { version });

const outDir = this.getOutputDir(project);

Expand Down
6 changes: 4 additions & 2 deletions tools/wpdev/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export default class Clean extends WithConfig {

// It's possible that the connected project may be a git repo
// So the above git commands won't work for nested git repos
const connectedProjects = wpMonorepo.getProjects({ connected: true });
const connectedProjects = await wpMonorepo.getProjects({
connected: true,
});

for (const [name, project] of connectedProjects) {
const files = child_process.execSync(
Expand All @@ -263,7 +265,7 @@ export default class Clean extends WithConfig {

// We do not want to delete any of the project directories in the monorepo.
filesToSkip = new Set(
[...wpMonorepo.getAllProjects()].map(([name, project]) => {
[...(await wpMonorepo.getAllProjects())].map(([name, project]) => {
return (
// We need posix paths for git
pathToPosix(project.relativeDir)
Expand Down
4 changes: 2 additions & 2 deletions tools/wpdev/src/commands/project-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export default class ProjectInfo extends WithProjects<typeof ProjectInfo> {
public async run(): Promise<void> {
try {
const projects = [...this.projects].map(
([name, { relativeDir, dir, packageJson }]) => {
([name, { relativeDir, dir, packageJson, wpdev }]) => {
return {
name,
version: packageJson.version,
relativeDir,
dir,
wpdev: packageJson.wpdev,
wpdev,
};
},
);
Expand Down
Loading