Skip to content

Commit

Permalink
fix: EEXIST after first 'npx projen'
Browse files Browse the repository at this point in the history
Unlink the `projen` symlink after requiring `.projenrc.js`.

Fixes projen#20
Elad Ben-Israel committed Jul 29, 2020
1 parent 0652d06 commit a4bf22c
Showing 2 changed files with 23 additions and 11 deletions.
29 changes: 19 additions & 10 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -6,14 +6,6 @@ import * as yargs from 'yargs';
const projenfile = path.resolve(PROJEN_RC);
const projen = path.dirname(require.resolve('../package.json'));

// now in order to run, projen needs to be able to "require('projen')". this will
// work if we already installed our modules, but will fail miserably when we
// bootstrap a checked out (or empty) repo.
const symlink = path.join('node_modules', 'projen');
if (!fs.existsSync(symlink)) {
fs.mkdirpSync('node_modules');
fs.symlinkSync(projen, symlink);
}

const args = yargs
.commandDir('cmds')
@@ -29,7 +21,24 @@ if (args._.length === 0) {
process.exit(1);
}

// eslint-disable-next-line @typescript-eslint/no-require-imports
require(projenfile);
// now in order to run, projen needs to be able to "require('projen')". this will
// work if we already installed our modules, but will fail miserably when we
// bootstrap a checked out (or empty) repo.
let unlink;
const symlink = path.join('node_modules', 'projen');
if (!fs.existsSync(symlink)) {
fs.mkdirpSync('node_modules');
fs.symlinkSync(projen, symlink);
unlink = symlink;
}

try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require(projenfile);
} finally {
if (unlink) {
fs.unlinkSync(symlink);
}
}
}

5 changes: 4 additions & 1 deletion src/cmds/new.ts
Original file line number Diff line number Diff line change
@@ -84,7 +84,10 @@ class Command implements yargs.CommandModule {
}

public async handler(args: any) {
console.log({args});
console.log(`Invalid project type ${args.projectType}. Supported types:`);
for (const pjid of inventory.discover().map(x => x.pjid)) {
console.log(` ${pjid}`);
}
}
}

0 comments on commit a4bf22c

Please sign in to comment.