Skip to content

Commit

Permalink
Fix compatibility with Windows (#285)
Browse files Browse the repository at this point in the history
Fix compatibility with Windows (Powershell)
  • Loading branch information
tarcang authored Dec 5, 2023
1 parent 1506208 commit 717551a
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 149 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"posttest": "yarn lint && yarn test:deprecation-policy && yarn test:command-reference",
"precommit": "npm run clean && npm run build && npm run lint && npm run version",
"prepack": "sf-prepack",
"prepare": "rm -f .oclif.manifest.json && yarn run prepack && husky install",
"prepare": "node scripts/prepare.mjs",
"prepublishOnly": "yarn run build && oclif-dev manifest",
"pretest": "sf-compile-test",
"prettier": "prettier --write src/**/**/*.ts && prettier --write src/**/*.ts && prettier --write src/*.ts && prettier --write test/**/*.ts && prettier --write test/**/**/*.ts",
Expand Down
34 changes: 34 additions & 0 deletions scripts/prepare.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import { spawn } from 'child_process';

let command = '';
let shellOptions = {};

switch (os.platform()) {
case 'win32':
command = 'Remove-Item -Force .oclif.manifest.json; yarn run prepack; husky install';
shellOptions = { shell : 'powershell.exe' };
break;
default:
command = 'rm -f .oclif.manifest.json && yarn run prepack && husky install';
shellOptions = { shell : '/bin/sh' };
break;
}

const child = spawn(command, shellOptions);

child.stderr.on('data', (data) => {
// eslint-disable-next-line no-console
process.stderr.write(String(data));
});

child.stdout.on('data', (data) => {
// eslint-disable-next-line no-console
process.stdout.write(String(data));
});
23 changes: 11 additions & 12 deletions src/commands/commerce/examples/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import os from 'os';
import path from 'path';
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
Expand Down Expand Up @@ -88,30 +89,28 @@ export class ExamplesConvert extends SfdxCommand {
await renameRecursive(
[{ name: 'InsertStoreNameHere', value: this.flags['store-name'] as string }],
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`${this.flags.outputdir}/force-app`
path.join(this.flags.outputdir, 'force-app')
);
if (scratchDef.settings.lwc) {
const pathFrom = EXAMPLE_DIR + '/' + scratchDef.edition.toLowerCase() + '/lwc/force-app/main/default';
const pathTo = (this.flags.outputdir as string) + '/force-app/main/default';
const pathFrom = path.join(EXAMPLE_DIR, scratchDef.edition.toLowerCase(), '/lwc/force-app/main/default');
const pathTo = path.join(this.flags.outputdir as string, '/force-app/main/default');

if (scratchDef.settings.lwc.classes)
scratchDef.settings.lwc.classes.forEach((clz) =>
shell(`cp -r ${pathFrom}/classes/${clz} ${mkdirSync(pathTo + '/classes/')}`)
shell(`cp -r ${path.join(pathFrom, 'classes', clz)} ${mkdirSync(path.join(pathTo, 'classes'))}`)
);
if (scratchDef.settings.lwc.lwc)
scratchDef.settings.lwc.lwc.forEach((clz) =>
shell(`cp -r ${pathFrom}/lwc/${clz} ${mkdirSync(pathTo + '/lwc/')}`)
shell(`cp -r ${path.join(pathFrom, 'lwc', clz)} ${mkdirSync(path.join(pathTo, 'lwc'))}`)
);
}
return { convertedExamples: true };
}

private convert(r: string[]): void {
r.map((l) => l.replace('$EXAMPLE_DIR', EXAMPLE_DIR).replace('~', os.homedir())).forEach((dir) =>
shell(
`cd ${this.flags.outputdir as string} && sfdx force:mdapi:convert -r ${dir} -d ${
this.flags.outputdir as string
}/force-app`
)
);
r.map((l) => l.replace('$EXAMPLE_DIR', EXAMPLE_DIR).replace('~', os.homedir())).forEach((dir) => {
shell(`cd ${this.flags.outputdir as string}`);
shell(`sfdx force:mdapi:convert -r ${dir} -d ${path.join(this.flags.outputdir as string, 'force-app')}`);
});
}
}
10 changes: 6 additions & 4 deletions src/commands/commerce/store/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import os from 'os';
import path from 'path';
import { flags, SfdxCommand } from '@salesforce/command';
import { fs, Logger, Messages, Org, SfdxError } from '@salesforce/core';
import chalk from 'chalk';
Expand Down Expand Up @@ -328,7 +329,7 @@ export class StoreCreate extends SfdxCommand {
if ((await this.statusFileManager.getValue('pushedSources')) === 'true') return;
const scratchOrgDir = mkdirSync(SCRATCH_ORG_DIR(BASE_DIR, this.devhubUsername, this.org.getUsername()));
try {
fs.removeSync(scratchOrgDir + '/force-app');
fs.removeSync(path.join(scratchOrgDir, 'force-app'));
} catch (e) {
/* IGNORE */
}
Expand All @@ -347,25 +348,26 @@ export class StoreCreate extends SfdxCommand {
this.ux.setSpinnerStatus(msgs.getMessage('create.using', ['sfdx force:source:push']));
shellJsonSfdx(
appendCommonFlags(
`cd ${scratchOrgDir} && echo y | sfdx force:source:tracking:clear -u "${this.org.getUsername()}"`,
`cd ${scratchOrgDir}; sfdx force:source:tracking:clear -u "${this.org.getUsername()}" -p`,
this.flags,
this.logger
)
);
shellJsonSfdx(
appendCommonFlags(
`cd ${scratchOrgDir} && sfdx force:source:push -f -u "${this.org.getUsername()}"`,
`cd ${scratchOrgDir}; sfdx force:source:push -f -u "${this.org.getUsername()}"`,
this.flags,
this.logger
)
);
} catch (e) {
console.error(e);
if (e.message && JSON.stringify(e.message).indexOf(msgs.getMessage('create.checkInvalidSession')) >= 0) {
this.ux.log(msgs.getMessage('create.preMessageOpeningPageSessinonRefresh', [e.message]));
shell('sfdx force:org:open -u ' + this.org.getUsername()); // todo might puppet this
shellJsonSfdx(
appendCommonFlags(
`cd ${scratchOrgDir} && sfdx force:source:push -f -u "${this.org.getUsername()}"`,
`cd ${scratchOrgDir}; sfdx force:source:push -f -u "${this.org.getUsername()}"`,
this.flags,
this.logger
)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/commerce/store/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class StoreOpen extends SfdxCommand {
this.ux.log('Store id is: ' + storeId);
shell(
appendCommonFlags(
`SFDX_DOMAIN_RETRY=5 sfdx force:org:open -p "/lightning/r/WebStore/${storeId}/view" -u ${this.org.getUsername()}`,
`sfdx force:org:open -p "/lightning/r/WebStore/${storeId}/view" -u ${this.org.getUsername()}`,
this.flags,
this.logger
)
Expand All @@ -56,7 +56,7 @@ export class StoreOpen extends SfdxCommand {
public viewAll(): boolean {
shell(
appendCommonFlags(
`SFDX_DOMAIN_RETRY=5 sfdx force:org:open -u ${this.org.getUsername()} -p _ui/networks/setup/SetupNetworksPage`,
`sfdx force:org:open -u ${this.org.getUsername()} -p _ui/networks/setup/SetupNetworksPage`,
this.flags,
this.logger
)
Expand Down
Loading

0 comments on commit 717551a

Please sign in to comment.