Skip to content

Commit

Permalink
Merge pull request #21 from skevy/preinstall-postinstall
Browse files Browse the repository at this point in the history
Run preinstall and postinstall scripts from package.json
  • Loading branch information
bestander committed Mar 18, 2016
2 parents 24d996c + 481ea29 commit c47c2e3
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/checkout-node-modules.es6
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ module.exports = (cwd, {repo, verbose, crossPlatform, incrementalInstall}) => {
}
log.debug(`Remote ${repo} is in node_modules, checking out ${packageJsonSha1} tag`);
process.chdir(`${cwd}/node_modules`);
return git(`checkout tags/${packageJsonSha1}`, {silent: true})
return git(`rev-list ${packageJsonSha1}`, { silent: true })
.then(() => runNpmScript('preinstall'))
.then(() => git(`checkout tags/${packageJsonSha1}`, {silent: true}))
.then(() => {
log.debug(`Cleanup checked out commit`);
return git(`clean -df`);
Expand All @@ -97,6 +99,7 @@ module.exports = (cwd, {repo, verbose, crossPlatform, incrementalInstall}) => {
return rebuildAndIgnorePlatformSpecific();
}
})
.then(() => runNpmScript('postinstall'))
.catch(installPackagesTagAndPushToRemote);
})
.then(() => {
Expand Down Expand Up @@ -188,6 +191,17 @@ module.exports = (cwd, {repo, verbose, crossPlatform, incrementalInstall}) => {
return npmRunCommands(npmCommand, [args], {silent});
}

function runNpmScript(scriptName) {
return readFilePromise(`${cwd}/package.json`, `utf-8`)
.then((packageJsonContent) => {
let packageJson = JSON.parse(packageJsonContent);
if (packageJson.scripts && packageJson.scripts[scriptName]) {
log.debug(`Running ${scriptName} script...`);
return npmRunCommand(`run`, scriptName);
}
});
}

function groupPackages(packages) {
var groups = [[]];
packages.forEach((pkg) => {
Expand Down Expand Up @@ -259,12 +273,27 @@ module.exports = (cwd, {repo, verbose, crossPlatform, incrementalInstall}) => {
return delPromise([`**`, `!.git/`]);
}
})
.then(() => {
process.chdir(`${cwd}`);
return Promise.resolve();
})
.then(() => {
if (crossPlatform) {
return runNpmScript('preinstall');
}
return Promise.resolve();
})
.then(() => {
log.debug(`Running 'npm install'`);
log.debug(`This might take a few minutes -- please be patient`);
process.chdir(`${cwd}`);
return npmRunCommand(`install`, crossPlatform ? ['--ignore-scripts'] : []);
})
.then(() => {
if (crossPlatform) {
return runNpmScript('postinstall');
}
return Promise.resolve();
})
.then(() => {
log.debug(`All packages installed, adding files to repo`);
process.chdir(`${cwd}/node_modules`);
Expand Down Expand Up @@ -312,3 +341,4 @@ module.exports = (cwd, {repo, verbose, crossPlatform, incrementalInstall}) => {




0 comments on commit c47c2e3

Please sign in to comment.