@@ -6,6 +6,8 @@ const fs = require('fs');
6
6
const path = require ( 'path' ) ;
7
7
const uuid = require ( 'uuid' ) ;
8
8
const yeoman = require ( 'yeoman-generator' ) ;
9
+ const username = require ( 'username' ) ;
10
+ const os = require ( 'os' ) ;
9
11
10
12
const REACT_NATIVE_PACKAGE_JSON_PATH = function ( ) {
11
13
return path . resolve (
@@ -43,25 +45,32 @@ module.exports = yeoman.Base.extend({
43
45
writing : function ( ) {
44
46
const projectGuid = uuid . v4 ( ) ;
45
47
const packageGuid = uuid . v4 ( ) ;
46
- const currentUser = childProcess . execSync ( 'powershell $env: username' )
48
+ const currentUser = username . sync ( ) ; // Gets the current username depending on the platform.
47
49
const templateVars = { name : this . name , ns : this . options . ns , certificateThumbprint : null , projectGuid, packageGuid, currentUser } ;
48
50
49
- const certGenCommand = [
50
- `$cert = New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject "CN=${ currentUser } " -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}Subject Type:End Entity") -CertStoreLocation "Cert:\\CurrentUser\\My"` ,
51
- `$pwd = ConvertTo-SecureString -String password -Force -AsPlainText` ,
52
- `Export-PfxCertificate -Cert "cert:\\CurrentUser\\My\\$($cert.Thumbprint)" -FilePath ${ path . join ( 'windows' , this . name , this . name ) } _TemporaryKey.pfx -Password $pwd` ,
53
- `$cert.Thumbprint`
54
- ] ;
55
-
56
51
console . log ( `Generating self-signed certificate...` ) ;
57
- const certGenProcess = childProcess . spawnSync ( 'powershell' , [ '-command' , certGenCommand . join ( ';' ) ] ) ;
58
-
59
- if ( certGenProcess . status === 0 ) {
60
- const certGenProcessOutput = certGenProcess . stdout . toString ( ) . trim ( ) . split ( '\n' ) ;
61
- templateVars . certificateThumbprint = certGenProcessOutput [ certGenProcessOutput . length - 1 ] ;
62
- console . log ( chalk . green ( "Self-signed certificate generated successfully." ) ) ;
52
+ if ( os . platform ( ) === 'win32' ) {
53
+ const certGenCommand = [
54
+ `$cert = New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject "CN=${ currentUser } " -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}Subject Type:End Entity") -CertStoreLocation "Cert:\\CurrentUser\\My"` ,
55
+ `$pwd = ConvertTo-SecureString -String password -Force -AsPlainText` ,
56
+ `Export-PfxCertificate -Cert "cert:\\CurrentUser\\My\\$($cert.Thumbprint)" -FilePath ${ path . join ( 'windows' , this . name , this . name ) } _TemporaryKey.pfx -Password $pwd` ,
57
+ `$cert.Thumbprint`
58
+ ] ;
59
+ const certGenProcess = childProcess . spawnSync ( 'powershell' , [ '-command' , certGenCommand . join ( ';' ) ] ) ;
60
+
61
+ if ( certGenProcess . status === 0 ) {
62
+ const certGenProcessOutput = certGenProcess . stdout . toString ( ) . trim ( ) . split ( '\n' ) ;
63
+ templateVars . certificateThumbprint = certGenProcessOutput [ certGenProcessOutput . length - 1 ] ;
64
+ console . log ( chalk . green ( "Self-signed certificate generated successfully." ) ) ;
65
+ } else {
66
+ console . log ( chalk . yellow ( 'Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.' ) ) ;
67
+ this . fs . copy (
68
+ this . templatePath ( path . join ( 'keys' , 'MyApp_TemporaryKey.pfx' ) ) ,
69
+ this . destinationPath ( path . join ( 'windows' , this . name , this . name + '_TemporaryKey.pfx' ) )
70
+ ) ;
71
+ }
63
72
} else {
64
- console . log ( chalk . yellow ( 'Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.' ) ) ;
73
+ console . log ( chalk . yellow ( 'Using Default Certificate. Use Visual Studio to renew it.' ) ) ;
65
74
this . fs . copy (
66
75
this . templatePath ( path . join ( 'keys' , 'MyApp_TemporaryKey.pfx' ) ) ,
67
76
this . destinationPath ( path . join ( 'windows' , this . name , this . name + '_TemporaryKey.pfx' ) )
0 commit comments