Skip to content

Commit

Permalink
Decouple link user dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ramraphael authored and marlon-wiprud committed Jan 25, 2019
1 parent b9857c4 commit 306825a
Show file tree
Hide file tree
Showing 10 changed files with 1,068 additions and 100 deletions.
6 changes: 6 additions & 0 deletions lib/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
const { exec } = require('child_process');
const path = require('path');
const rimraf = require('rimraf');
const { linkUserDeps, unlinkUserDeps } = require('../utils');

const ribbitConfig = require(path.join(process.env.PWD, '/ribbit.config.js'));

function build() {
linkUserDeps(ribbitConfig.dependencies, process.env.PWD);
const child = exec(
`npm run start-server ${process.env.PWD}`,
{
cwd: __dirname
},
() => {
const TEMP_STATIC_FILE_FOLDER = `${__dirname}/../../dist`;
unlinkUserDeps(ribbitConfig.dependencies, process.env.PWD);
rimraf(TEMP_STATIC_FILE_FOLDER, error => {
if (error) process.stdout(error);
process.kill(process.pid, 'SIGINT');
Expand Down
10 changes: 7 additions & 3 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const prettifyJS = require('./prettifyJS');
const linkUserDeps = require('./linkUserDeps');
const unlinkUserDeps = require('./unlinkUserDeps');

module.exports = {
prettifyJS(obj) {
return JSON.parse(JSON.stringify(obj, null, 2));
}
prettifyJS,
linkUserDeps,
unlinkUserDeps
};
3 changes: 1 addition & 2 deletions server/helpers/linkUserDeps.js → lib/utils/linkUserDeps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const fs = require('fs');
const path = require('path');

const linkUserDeps = (ribbitConfig, appDir) => {
const deps = ribbitConfig.dependencies;
const linkUserDeps = (deps, appDir) => {
for (const dep of deps) {
const pathToRibbitDep = path.join(`${__dirname}/../../node_modules/${dep}`);
const pathToUserDep = `${appDir}/node_modules/${dep}`;
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/prettifyJS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function prettifyJS(obj) {
return JSON.parse(JSON.stringify(obj, null, 2));
}
module.exports = prettifyJS;
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const fs = require('fs');
const path = require('path');

const unlinkUserDeps = (ribbitConfig, appDir) => {
const deps = ribbitConfig.dependencies;
const unlinkUserDeps = (deps, appDir) => {
for (const dep of deps) {
const pathToRibbitDep = path.join(`${__dirname}/../../node_modules/${dep}`);
if (fs.lstatSync(pathToRibbitDep).isSymbolicLink()) {
Expand Down
Loading

0 comments on commit 306825a

Please sign in to comment.