Skip to content

Commit

Permalink
fix: path and executable issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
enxg committed Oct 8, 2021
1 parent f69ae95 commit f317d7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createComponent(component: string, name: string, config: any, configLoc
if (!projectLanguage) return reject(new Error("There is no 'projectLanguage' field in .sapphirerc.json"));
const template = `${component.toLowerCase()}.${projectLanguage}.sapphire`;

const corePath = `${componentsFolder.pathname}${template}`;
const corePath = `${componentsFolder}${template}`;
const userPath = config.customFileTemplates.enabled ? join(configLoc, config.customFileTemplates.location, template) : null;
const target = join(configLoc, config.locations.base, '%L%', `${name}.${projectLanguage}`);
const params = { name: basename(name) };
Expand Down
2 changes: 1 addition & 1 deletion src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function editPackageJson(location: string, name: string) {
}

function installDeps(location: string, pm: string, verbose: boolean) {
const pmp = spawn(pm.toLowerCase(), ['install'], {
const pmp = spawn(process.platform === 'win32' ? `${pm.toLowerCase()}.cmd` : pm.toLowerCase(), ['install'], {
stdio: verbose ? 'inherit' : undefined,
cwd: `./${location}/`
});
Expand Down
12 changes: 8 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { URL } from 'url';
import { URL, fileURLToPath } from 'url';

export const rootFolder = new URL('../', import.meta.url);
export const templatesFolder = new URL('./templates/', rootFolder);
export const componentsFolder = new URL('./components/', templatesFolder);
const rootURL = new URL('../', import.meta.url);
const templatesURL = new URL('./templates/', rootURL);
const componentsURL = new URL('./components/', templatesURL);

export const rootFolder = fileURLToPath(rootURL);
export const templatesFolder = fileURLToPath(templatesURL);
export const componentsFolder = fileURLToPath(componentsURL);
export const repoUrl = 'https://github.com/sapphiredev/examples.git';
2 changes: 1 addition & 1 deletion src/functions/CreateFileFromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function CreateFileFromTemplate(
component = false
) {
return new Promise(async (resolve, reject) => {
const location = custom ? template : `${templatesFolder.pathname}${template}`;
const location = custom ? template : `${templatesFolder}${template}`;

const output = {} as {
f: string;
Expand Down

0 comments on commit f317d7f

Please sign in to comment.