microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.36k stars 1.14k forks source link

[0.76] Update RNW CLI to preserve and re-use `init-windows` arguments #14060

Closed jonthysell closed 2 weeks ago

jonthysell commented 3 weeks ago

This PR backports #13988 to 0.76.

Description

This PR updates the RNW CLI to preserve and re-use the arguments passed to init-windows when the project was created.

Type of Change

Why

The RNW CLI should be smart enough to change its command's behaviors based on the template used by the project.

Closes #13927 Closes #13926 Closes #13937 Closes #13174

What

As per #13927:

  1. The init-windows command will now stamp the template, name, and namespace arguments to the project's package.json file as follows: json { "react-native-windows": { "init-windows": { "name": "testcli", "namespace": "testcli", "template": "cpp-app", }, }, }
  2. The config command (and therefore all other CLI commands) will now contain the contents of this new react-native-windows section in a new rnwConfig property.

Then, as per #13937:

  1. The init-windows command will now use the previously saved arguments if they're available (and not otherwise overwritten by passed-in arguments)
  2. If the template arg is missing (as it will be for all previously created projects) the config command will try to determine which template was used and inject it

Additionally, as per #13926:

  1. The autolink-windows command will now use the template information to use the correct files when autolinking

Bonus, as per #13174:

  1. The autolink-windows command will now include both the CPP and H file (the H file wasn't being regenerated before)

Screenshots

N/A

Testing

Verified new projects contain the new information.

Changelog

Should this change be included in the release notes: yes

Update RNW CLI to preserve and re-use init-windows arguments

Microsoft Reviewers: Open in CodeFlow