Asked  8 Months ago    Answers:  5   Viewed   34 times

We're considering creating our own common bundle for entity mapping and services for use within few separate apps. A bundle should be easy to modify, run, include and test. I know about Best Practices for Structuring Bundles, but I don't know what git strategy to use when it comes to development.

Should we create common bundle as a whole project and commit whole repository to our git server, or is it better to start source control only for root of common bundle and push only its contents? I see this approach in bundles available on github, but I don't know easy and comfortable way to develop bundles that way.

 Answers

89

Create a new empty symfony project

php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1
cd demo

Generate a new bundle

(for example src/Company/DemoBundle)

php app/console generate:bundle
cd src/Company/DemoBundle/

Init your github repository in src/Company/DemoBundle

git init
touch README.md
git add .
git commit -m "initial commit"
git remote add origin https://github.com/YourAccount/DemoBundle.git
git push -u origin master

Add a composer.json file

src/Company/DemoBundle/composer.json:

{
    "name" : "company/demobundle",
    "description" : "A demo bundle",
    "type" : "symfony-bundle",
    "authors" : [{
        "name" : "demo",
        "email" : "demo@company.com"
    }],
    "keywords" : [
        "demo bundle"
    ],
    "license" : [
        "MIT"
    ],
    "require" : {
    },
    "autoload" : {
        "psr-0" : {
            "Company\DemoBundle" : ""
        }
    },
    "target-dir" : "Company/DemoBundle",
    "repositories" : [{
    }],
    "extra" : {
    "branch-alias" : {
            "dev-master" : "some_version-dev"
        }
    }
}

Now you have the base structure of your bundle

Use it in another project

composer.json:

    [...]
    "require" : {
        [...]
        "company/demobundle" : "dev-master"
    },
    "repositories" : [{
        "type" : "vcs",
        "url" : "https://github.com/Company/DemoBundle.git"
    }],
    [...]

Do:

curl -sS https://getcomposer.org/installer | php
php composer.phar update company/demobundle

app/AppKernel:

new CompanyDemoBundleCompanyDemoBundle(),

Work on it

  • You can clone your DemoBundle in the src/Company folder, then manually install it
  • You can use symlink

Conclusion

You can develop and test your bundle in your first project and use it with github and composer in your second project.

Wednesday, March 31, 2021
 
Neysor
answered 8 Months ago
95

The files under vendor/ aren't supposed to be tracked, i.e. it's supposed to be in your .gitignore file. Instead, the composer utility should be used to download the packages and install them.

In your case I would suggest to:

  1. Unpack the project into a temporary directory,
  2. Run composer install
  3. Deploy the temporary directory contents.
Saturday, May 29, 2021
 
Angolao
answered 5 Months ago
89

You can also use GIT SUBMODULES within your project A to refer to project B and then add

GIT_SUBMODULE_STRATEGY: recursive

to the gitlab-ci.yml file in project A.

This also enables you to specifically include a specific branch or commit from your subproject.

https://docs.gitlab.com/ce/ci/git_submodules.html

Tuesday, August 17, 2021
 
muffe
answered 3 Months ago
56

Turns out this is not yet supported, scheduled for v1.1

Sunday, September 19, 2021
 
TuomasR
answered 1 Month ago
83

More than one of the approaches in my question will work. Some will not, some do not currently due to defects in Angular 2. Here's the approach I'm currently using:


WebPack + require.js

angular2-webpack-config.js

var config = {
    entry: {
        app: inputFile
    },
    externals: [
        /^@angular//,
        /^rxjs//
    ],
    output: {
        libraryTarget: "amd",
        path: __dirname,
        filename: './' + outputName
    },
    plugins: [
        new require('webpack').optimize.UglifyJsPlugin()
    ]
};

I only tell it what are externals and what pseudo-standard mechanism will load them at runtime via libraryTarget (AMD/RequireJS, CommonJs/node, UMD). My setting simply causes external library references to be wrapped in define().

Note that I don't do anything with paths in WebPack. In my software, anything in the node_modules folder has a similar reference mechanism both in my software and in third party modules, internally. Both my code and third-party libraries expect to find RxJS at rxjs (e.g. rather than ../rxjs or 'node_modules/rxjs`). At runtime, both need to be mapped, but since we aren't allowing WebPack to reach into third party modules (we're using pre-built UMD's), WebPack isn't the place to do that mapping. It would only map my code. Instead, we should do that in our runtime loader:

index.htm

<script src="https://npmcdn.com/core-js/client/shim.min.js"></script>
<script src="https://npmcdn.com/zone.js@0.6.12/dist/zone.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reflect-metadata/0.1.3/Reflect.min.js"></script>
<script>
    var require = (function(){
        var versions = {
            'router-deprecated': '@@2.0.0-rc.2',
            'forms': '@@0.1.1',
            'angular': '@@2.0.0-rc.4',
            'rxjs': '@@5.0.0-beta.10'
        }

        var paths = {
            'rxjs': "https://npmcdn.com/rxjs" + versions.rxjs + "/bundles/Rx.umd.min"
        };
        [
            'core',
            'http',
            'common',
            'compiler',
            'platform-browser',
            'router-deprecated',
            'platform-browser-dynamic'
        ].forEach(function (submodule) {
            var module = '@@angular/' + submodule
            paths[module] = 'https://npmcdn.com/' + module + (versions[submodule] || versions.angular) + '/bundles/' + submodule + '.umd.min';
        });

        var rxmap = {};
        [
            'Rx',
            'Observable',
            'Subject',
            'observable/PromiseObservable',
            'operator/toPromise'
        ].forEach(function (submodule) {
            rxmap['rxjs/' + submodule] = 'rxjs';
        })

        return {
            paths: paths,
            map: {
                '*': rxmap
            }
        };
    })();
</script>
<script data-main="../assets/compiled/a2.webpack.js" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>

Also, since if you are using WebPack and UMDs you probably care about resulting file sizes and times. This sub-app's Angular 2 build process went from about 24 seconds to 1 second. Its publish changed-size went from over 2MB to about 100k.

Here are wire load sizes of the cached dependencies for reference. Strangely they are currently a few KB smaller in the UMD version than the wire-size increase of an integrated, WebPack pruned, bundle.

 KB
27.5 shim
 6.8 zone
 8.0 require
 3.3 platform-browser-dynamic
36.8 http
 8.7 core
20.8 common
16.5 router
98.5 compiler
27.9 platform-browser
39.0 Rx

Obviously my public site load times after updates are drastically reduced (down to 1 second from about 10-20 seconds), but those numbers are pretty variable based on connection.

Wednesday, September 22, 2021
 
MannfromReno
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share