Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fabric: Add `windows` script to new cpp-app template",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
9 changes: 8 additions & 1 deletion vnext/templates/cpp-app/template.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const util = require('util');

const glob = util.promisify(require('glob'));

const templateUtils = require('../templateUtils');

async function preInstall(config = {}, options = {}) {}

async function getFileMappings(config = {}, options = {}) {
Expand Down Expand Up @@ -104,7 +106,12 @@ async function getFileMappings(config = {}, options = {}) {
return fileMappings;
}

function postInstall(config = {}, options = {}) {
async function postInstall(config = {}, options = {}) {
// Update package.json with new scripts
await templateUtils.updateProjectPackageJson(config, options, {
scripts: {windows: 'react-native run-windows'},
});

console.log(chalk.white.bold('To run your new windows app:'));
console.log(chalk.white(' npx react-native run-windows'));
}
Expand Down
29 changes: 29 additions & 0 deletions vnext/templates/templateUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* @ts check
* @format
*/

const pkgUtils = require('@react-native-windows/package-utils');

async function updateProjectPackageJson(config = {}, options = {}, props = {}) {
const projectPath = config?.root ?? process.cwd();
const projectPackage = await pkgUtils.WritableNpmPackage.fromPath(
projectPath,
);

if (!projectPackage) {
throw new Error(
`The directory '${projectPath}' is not the root of an npm package`,
);
}

if (options?.logging) {
console.log('Modifying project package.json...');
}
await projectPackage.mergeProps(props);
}

module.exports = {updateProjectPackageJson};