GithubHelp home page GithubHelp logo

npm start -- setup about camp HOT 11 CLOSED

gr2m avatar gr2m commented on May 14, 2024
npm start -- setup

from camp.

Comments (11)

gr2m avatar gr2m commented on May 14, 2024 1

Nobody will ever tell you do go away as long as you are nice to us :) it's all yours! Let us know if you need any help! Welcome at Hoodie :)

from camp.

klazich avatar klazich commented on May 14, 2024 1

Good to hear! I'll get started.

from camp.

klazich avatar klazich commented on May 14, 2024 1

I'll hopefully have something in the next few days. It's been a busy work week so I haven't had much time to look at it.

from camp.

gr2m avatar gr2m commented on May 14, 2024

Ignore the issue history above, this issue is up for grabs again :)

from camp.

klazich avatar klazich commented on May 14, 2024

I'd like to give this a shot. This would be my first time working on a project outside of a online courses and challenges. If there is a different issue better suited for a beginner i'll claim that one. Or, just tell me to go the hell away and i'll understand :) Good luck with hoodie!

from camp.

gr2m avatar gr2m commented on May 14, 2024

No worries, keep us posted :)

from camp.

klazich avatar klazich commented on May 14, 2024

So, here is what I have so far:

// a-script.js
// writes to parent package.json. Used here to set a "start" script
#!/usr/bin/env node

var fs = require('fs');
var fileName = '../../package.json';
var file = require(fileName);

file.scripts = file.scripts || {};
file.scripts["start"] = "echo \"success\"";

fs.writeFile(fileName, JSON.stringify(file, null, 2), function(err) {
    if (err) return console.log(err);
});

With this script set to run on package "install" (or any "install" lifecycle event) I can set the parent package.json "start" script.

I was thinking of using this to set the "prestart" hook to run a file that listens to process.argv for passed commands (or process.env for lifecycle events). So npm start setup can still set "start" to "hoodie" and still allow for additional "start" commands in the future.

Does that sound like the direction you want to go?

from camp.

gr2m avatar gr2m commented on May 14, 2024

Yeah that sounds good! I just realized that the idea of npm start -- setup to set the package.json’s start script doesn’t make much sense because unless it’s set we can’t run npm start 🤦 :) Sorry for the confusion. So I think you pretty much work on this issue and #3 at the same time, which is graet

I would suggest we run your script in postinstall. Three

  1. var fileName = '../../package.json'; won’t work on windows, try to avoid to hard code path separators. Please use path.join instead
  2. Check if the user run npm install --save hoodie or npm install -S hoodie, and only run the setup then.
  3. Maybe add a console.log('Start your Hoodie app with "npm start"') to the end?

from camp.

klazich avatar klazich commented on May 14, 2024

So use path like this?:

path.join('..','..','package.json')

Sorry, still fairly new to Node.

Also, will the package.json we want to target always be 2 above where the script executes? I was hoping there would be some other way to get the project root but didn't find anything.

from camp.

gr2m avatar gr2m commented on May 14, 2024

yes that looks right.

Your comment is right though, there might be edge cases where the target is not exactly 2 directories above the Hoodie code. Alternatively you can also do path.join(process.cwd(), 'package.json'). process.cwd() returns the full path of the directory you run the npm install command from, so it acchieves the same thing. Maybe let’s use that?

from camp.

gr2m avatar gr2m commented on May 14, 2024

Also no need to excuse, happy to help :)

from camp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.