Skip to content

Commit

Permalink
Create new CLI init-windows command (#12123)
Browse files Browse the repository at this point in the history
* Create new CLI init-windows command

## Description

This PR implements a new, named template-based `react-native
init-windows` command as described by #11920.

Note, this does not change or deprecate the existing
`react-native-windows-init` / `generateWindows` infrastructure or
templates.

### Type of Change
- New feature (non-breaking change which adds functionality)

### Why

This is part of restructuring how users can add RNW support to their RN
projects.

### What

1. Creates a new `init-windows` RN CLI command that creates a new
   windows project based on a given template
2. The first CLI templates under `old/`, which are just wrappers which
   call the existing templating code in `generateWindows`

Closes #12152
Closes #12151
Closes #12150
Closes #12149
Closes #12148
Closes #12147

## Screenshots
N/A

## Testing
Ran existing tests, created base `initWindows` tests.

## Changelog
Should this change be included in the release notes: yes

Created a new `init-windows` command

* fix generateWrapper

* remove sample apps package.json

* update yarn.lock

* Rename old templates
  • Loading branch information
jonthysell authored Sep 21, 2023
1 parent 7c9768c commit de07af9
Show file tree
Hide file tree
Showing 22 changed files with 659 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

# CLI for the new project templates
/vnext/template/** @microsoft/react-native-windows-cli @microsoft/react-native-windows-write
/vnext/templates/** @microsoft/react-native-windows-cli @microsoft/react-native-windows-write

# Ownership by specific files or file types
# This section MUST stay at the bottom of the CODEOWNERS file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Create new CLI init-windows command",
"packageName": "@react-native-windows/cli",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Create new CLI init-windows command",
"packageName": "@react-native-windows/telemetry",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Create new CLI init-windows command",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions packages/@react-native-windows/cli/depcheck.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
// Resolved dynamically from user project
ignoreMatches: [
'@react-native-community/cli',
'@react-native-windows/cli',
'execa',
'react-native',
'react-native-windows'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import * as vstools from '../../utils/vstools';
import * as generatorCommon from '../../generator-common';
import * as configUtils from '../config/configUtils';
import * as pathHelpers from '../../utils/pathHelpers';
import {
getDefaultOptions,
startTelemetrySession,
Expand Down Expand Up @@ -853,12 +854,7 @@ export class AutoLinkWindows {
* @param config project configuration
*/
function resolveRnwRoot(projectConfig: WindowsProjectConfig) {
const rnwPackage = path.dirname(
require.resolve('react-native-windows/package.json', {
paths: [projectConfig.folder],
}),
);
return rnwPackage;
return pathHelpers.resolveRnwRoot(projectConfig.folder);
}

/**
Expand Down Expand Up @@ -1016,7 +1012,7 @@ export async function autolinkWindowsInternal(
*/
export const autolinkCommand: Command = {
name: 'autolink-windows',
description: 'performs autolinking',
description: 'Runs Windows-specific autolinking',
func: autolinkWindows,
options: autolinkOptions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export async function codegenWindowsInternal(
*/
export const codegenCommand: Command = {
name: 'codegen-windows',
description: 'Runs Windows specific codegen',
description: 'Runs Windows-specific codegen',
func: codegenWindows,
options: codegenOptions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

import path from 'path';

const rnDir = path.dirname(
require.resolve('react-native/package.json', {paths: [process.cwd()]}),
);
const cliDir = path.dirname(
require.resolve('@react-native-community/cli/package.json', {paths: [rnDir]}),
);
import * as pathHelpers from '../../utils/pathHelpers';

const rnDir = pathHelpers.resolveRnRoot(process.cwd());
const cliDir = pathHelpers.resolveRnCliRoot(rnDir);

const execaPath = require.resolve('execa', {paths: [cliDir]});
const execa = require(execaPath);

Expand Down Expand Up @@ -53,11 +52,7 @@ function getHealthChecksUnsafe(): HealthCheckCategory[] | undefined {
}

const rnwDepScriptPath = path.join(
path.dirname(
require.resolve('react-native-windows/package.json', {
paths: [process.cwd()],
}),
),
pathHelpers.resolveRnwRoot(process.cwd()),
'Scripts/rnw-dependencies.ps1',
);

Expand Down
Loading

0 comments on commit de07af9

Please sign in to comment.