candy icon indicating copy to clipboard operation
candy copied to clipboard

Candy should have an easier way to install and use via package management

Open who opened this issue 9 years ago • 8 comments

I have an existing web application which uses npm+bower+grunt, I and would like to add Candy to it. I found that this was not easy, and I believe this process could be greatly simplified.

If you want to include Candy in an existing node+grunt app, you have to something like the following:

1. Add Candy to your package.json Add "candy": "candy-chat/candy#3bad2bc2ca" to your package.json. This will cause npm to download the github repo when npm install is performed. I used commit #3bad2bc2ca as a tag.

2. Install Candy's node modules and run Candy's grunt build Because there are no dist assets in the github repo, you have to run npm install and grunt build on behalf of Candy inside ./node_modules/candy. For the npm install, you can use grunt-auto-install, and for the grunt build, you can use grunt-subgrunt.

After you add and configure grunt-auto-install, whenever you run npm install at your root application's scope, npm install will also be run inside the ./node_modules/candy folder for you. This will install the node modules required by Candy in preparation for the grunt build.

After you add and configure sub-grunt, you can configure a grunt task at your root application's scope to trigger grunt jobs in the ./node_modules/candy folder. This will build all of the JS bundles that Candy needs.

2.1 Install and configure grunt-auto-install

Install the package

npm install grunt-auto-install --save-dev

Configure your Gruntfile.js

grunt.initConfig({
  auto_install: {
    local:{},
    run: {
        options: {
            cwd: './node_modules/candy',
            stdout: true,
            stderr: true,
            failOnError: true,
            npm: true
        }
    }
  },
});

grunt.loadNpmTasks('grunt-auto-install');

Then, at your application root, you can test this by invoking the grunt command grunt auto_install:run. Candy's node modules should then be installed in ./node_modules/candy/node_modules

2.2 Install and configure grunt-auto-install

Install the package

npm install grunt-subgrunt --save-dev

Configure your Gruntfile.js

grunt.initConfig({
  subgrunt: {
    run: {
      projects: {
        'node_modules/candy': ['build']
      }
    }
  }
});

grunt.loadNpmTasks('grunt-subgrunt');

Then, at your application root, you can test this by invoking the grunt command grunt subgrunt:run. Candy's JS files will then be generated.

Conclusion & Recommendation This is probably more complex than it should be. Step 2, 2.1, and 2.2 above could be completely removed if Candy would include pre-built or "dist" assets in it's repo. I recommend that Candy publish pre-built assets as a part of each build pushed to Github.

who avatar Sep 22 '15 18:09 who

if Candy would include pre-built or "dist" assets in it's repo. I recommend that Candy publish pre-built assets as a part of each build pushed to Github.

We explicitly do not do this because it is not a sensible approach to distributing software. Something along the lines of "subgrunt" or preferably a standard approach for packaging Javascript modules, is consistent with the requirements of developing, building and distributing software. Unfortunately Javascript has a very immature ecosystem, so these things are still being (re-)invented.

For now, I would recommend contributing the above as documentation.

benlangfeld avatar Sep 22 '15 20:09 benlangfeld

have a look at other packages needs to build. such as bootstrap. just don't directly point at github repo. but a pre-compiled one.

and could you don't specific jquery version in dependence? many websites already using jquery 2.x, and will cause problem.

again, look at other packages, such as bootstrap, it says "jquery": ">= 1.9.1"

zh99998 avatar Oct 14 '15 14:10 zh99998

We do not bundle any jQuery, @zh99998, you can use whatever version you like.

benlangfeld avatar Oct 14 '15 15:10 benlangfeld

just release a compiled tar.gz format package here will help a lot. npm support tarball url as dependency, but not support zip

zh99998 avatar Nov 25 '16 07:11 zh99998

Like the tarballs at https://github.com/candy-chat/candy/releases, @zh99998?

benlangfeld avatar Nov 25 '16 13:11 benlangfeld

@benlangfeld yes I'm talking about here https://github.com/candy-chat/candy/releases

now only released COMPILED package in zip format, no tar.gz

zh99998 avatar Nov 25 '16 14:11 zh99998

The release config is at https://github.com/candy-chat/candy/blob/master/Gruntfile.js#L215-L259. Would you be able to prep a PR which releases compiled tarballs too, @zh99998?

benlangfeld avatar Nov 25 '16 14:11 benlangfeld

sorry I tried several times but can't build it..... seems due to this https://github.com/dylang/grunt-notify/issues/118

zh99998 avatar Dec 05 '16 04:12 zh99998