Giter Club home page Giter Club logo

Comments (13)

sindresorhus avatar sindresorhus commented on May 26, 2024

We already have Cheerio for modifying HTML. We also have API methods to add scripts and styles.

How does your helper work? Like how do you modify the app.js reliably?

from generator.

btford avatar btford commented on May 26, 2024

It's not particularly sophisticated; it just looks for some line of code, and inserts a block of code before this other line. It also handles indenting the inserted code based on the context that its inserted.

You can take a look at it here: https://github.com/yeoman/generators/blob/master/lib/generators/angular/util.js

The code is not particularly beautiful, so if you think there's a better way for me to do this, let me know.

from generator.

sindresorhus avatar sindresorhus commented on May 26, 2024

@btford can you expand on what it does? Does it modify HTML or JS? Could Cheerio potentially replace it?

I want it out of the Angular generator in into a more reusable format.

from generator.

kevva avatar kevva commented on May 26, 2024

It's this. Inserts code after a defined context (example), in this case JS.

from generator.

btford avatar btford commented on May 26, 2024

+1 everything @kevva said.

It's language agnostic; it's just doing dumb string searching. Cheerio could replace the HTML portion, but probably not the JS portion. We'd need to use a JS parser for that.

It's also aware of indentation, etc.

from generator.

sindresorhus avatar sindresorhus commented on May 26, 2024

Ok, I think a dumb string searching thing could be useful in addition to Cheerio and an Esprima abstraction.

@btford how about making that one a separate module?

from generator.

btford avatar btford commented on May 26, 2024

Separate npm module?

Super hard question: what should I name it?

from generator.

passy avatar passy commented on May 26, 2024

Super hard question: what should I name it?

That's where most refactoring efforts end.

from generator.

sindresorhus avatar sindresorhus commented on May 26, 2024

@btford create a random module name creator. Though you're still stuck naming that...

from generator.

btford avatar btford commented on May 26, 2024

It's called insertify. You're welcome, Node.js community.

from generator.

sindresorhus avatar sindresorhus commented on May 26, 2024

:)

from generator.

addyosmani avatar addyosmani commented on May 26, 2024

Niiiiice, @btford. Btw, do we want to use Insertify anywhere? Is there anything Cheerio and Esprima can't give the generator core that we could benefit from?

PS: Needs moar README info :)

from generator.

sindresorhus avatar sindresorhus commented on May 26, 2024

@addyosmani it's useful for replacing things and don't have to think about what kind of file it is and how to parse it.

We're not going to include it until it gets tests/docs though.

from generator.

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.