How to create own autogenerated files by composer - symfony

I'm working on project in Symfony 2. In this project, there's file named parameters.yml.dist which is base for composer to create parameters.yml. We have two environments (prod, dev), each one has own parameters file (for dev it's parameters_dev.yml).
My problem is that, some users and servers have different dev configuration, but file exists in repository - that makes deployment and work a little bit uncomfortable.
Is there a way to make that parameters_dev.yml file be autogenerated same as parameters for prod? I tried to create this *.dist file but that's not worked, maybe I have to do something else?

I found the solution. Parameters are managed by this bundle: https://github.com/Incenteev/ParameterHandler
That's how part of my composer.json file looks now:
"incenteev-parameters": [
{
"file": "app/config/parameters.yml"
},
{
"file": "app/config/parameters_dev.yml"
}
],
Funny, I searched composer.json in first place but didn't found anything.

Related

VS Code SCSS auto compiling to CSS

I am total beginner in programming and just started to learn HTML/CSS.
For coding I started to use VS Code. And I really like it.
Only problem so far, what I got, is auto compiling of SCSS to CSS.
I have searched and read many solutions, and the best what I found was with ruby + sass + code in VS Code terminal sass --watch . It is watching my project and creating new CSS when new SCSS is created. And it is watching for changes in SCSS. But problem is that this code must be entered each time I am starting VS Code.
Tried also solution with Gulp file and package.json, but also could not make it start automatically. And it has to be made for each project separately.
I tried also Atom, and it has sass-autocompile package, and it works perfectly. So, simplest way for me would be to use Atom and forget. But I would like to use VS Code though.
So, generally question is if there would be possibility to create extension for VS Code to automate SCSS compilation to CSS (similar to Atom's package, which would be the best IMO). Or maybe somebody could explain me other way how to solve this problem.
You will need two things:
tasks.json file
Blade Runner extension for VS CODE
Start by creating .vscode folder in your project.
Then in it create tasks.json file with the following content:
{
"version": "0.1.0",
"command": "sass",
"isShellCommand": true,
"args": ["--watch", "."],
"showOutput": "always"
}
Now, after opening the project you can run the task by clicking Ctrl+Shift+B.
To automate the process use Blade Runner extension - https://marketplace.visualstudio.com/items?itemName=yukidoi.blade-runner
Blade Runner will run the task automatically after opening the project :)
A solution without additional extensions
With sass
Assuming you have sass installed globally with for instance:
npm install -g sass
Open the folder and create a task.json file under .vscode containing
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Watch Sass",
"type": "shell",
"command": "sass --watch src/style.sass styles/style.css --style=compressed",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
"runOptions": {
"runOn": "folderOpen"
}
}]
}
With node-sass
Replace sass with node-sass in the above.
In both cases make sure the source/destination filename, location and extension are correct (in my case src/style.scss and style/style.css)
With a Workspace file
Or copy the section in your .vscode-workspace file to avoid clutter of .json files.
Make sure to change the sass source and destination files to your personal needs.
Setup VSCode
[EDIT] whith the current version this is asked the first time you open the workspace file and the following steps are no longer needed.
To a llow automatic run tasks
Ctrl+Shift+P
select Manage automatic Tasks and
select Allow Automatic Tasks in Folder and
close and reopen your folder (or Workspace)
The sass compiler will be called and starts watching all your edits with a reassuring:
Compiled css\src\style.sass to css\style.css.
Sass is watching for changes. Press Ctrl-C to stop.
or with error messages when compilation failed.:
Error: semicolons aren't allowed in the indented syntax.
╷
7 │ padding: 0;
│ ^
╵
css\src\_base.sass 7:12 #import
css\src\style.sass 1:9 root stylesheet
Or use Easy Compile - it will auto compile on save.
https://marketplace.visualstudio.com/items?itemName=refgd.easy-compile
There already is an official document out there
https://code.visualstudio.com/docs/languages/css#_step-3-create-tasksjson
Only tip we can consider here is put an argument of --watch just not to build manually by hitting ctrl+shift+b every time.
// Sass configuration
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sass Compile",
"type": "shell",
"command": "sass --watch styles.scss styles.css",
"group": "build"
}
]
}
Without any plugins, you can create .vscode folder in your project and just write some tasks.json
Easy Compile or Live SASS Compiler extensions for Visual Studio Code.
The Live SASS Compiler can recompile all sources, whereas Easy Compile just compiles a single file.
Easy Compile compiles when you save a file, whereas Live SASS Compiler can be made to watch your code and compile when it sees a change. You must manually start it every time, whereas Easy Compile runs out of the box.

.Net Core 1.0 Relative Project Dependencies Not Found

I have the project structure:
/src
- common
- common-x
+ project.json
- module-a
- project-a
+ project.json
- project-a-tests
+ project.json
+ global.json
I'm trying to include the common-x project using relative file paths in the global.json file.
The global.json file in the module-a directory is as follows:
{
"projects": [
"project-a",
"project-a-tests",
"../common/common-x"
]
}
and the project.json file in project-a is
{
// Default config options are also in this...
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"common-x": {
"target": "project"
}
}
}
project-a-tests has no problem referencing project-a since they are in the same directory, but project-a can't find the common-x project. I receive a "Unable to resolve ..." error from dotnet restore.
I have tried using absolute paths but that doesn't work either. The closest solution so far is to use symlinks but that is not preferable.
Note: This is all being run on Ubuntu 16.04.
You should only need to specify top level folders in your global.json file, since sub-folders will be scanned automatically. Global.json reference.
So your global.json should look like this.
{
"projects": [ "src" ]
}
If you are still getting any dependencies issues that might related to compatibility problems between projects/modules, however I would need to see the exact output you are getting to troubleshoot that.
UPDATE
A few tips that might be useful:
Delete old project.json.lock files
Add a .sln solution file if you don't have one created.
UPDATE 2
As per your comment, the working solution was to move global.json into src folder, and list your top-level folders in the projects array.

Magento 2.0 Unknown module(s): error when enabling custom module from command line

I've read Magento's DevDocs and Googled this problem but the usual missing registration.php answer doesn't apply here.
I'm on the released CE 2.0.0 version and I'm simply trying to enable my first minimum test module in magento/vendor/ but
bin/magento module:enable -c Tchsl_Test
results in:
Unknown module(s): 'Tchsl_Test'
I am basing this on the naming conventions and file positions of modules in vendor/magento/
In vendor/tchsl/module-test/etc/module.xml I have
<config xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Tchsl_Test" />
</config>
In vendor/tchsl/module-test/registration.php I have
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Tchsl_Test',
__DIR__
);
What am I missing?
I had this same problem and after some tinkering, discovered that our Modules actually belong under app/code/Tchsl/Test/. Move your module files there, and running the shell command module:status should show your disabled module.
You don't need to put your module under app/code/. In app/code/ Magento2 will search and find your module's registration.php. In Composer's vendor/ dir it doesn't do that, so we need to trick Composer into loading your module's registration.php.
If you'd check any Magento2 module's composer.json in vendor/magento/module-*, you'll see an "autoload" section which references the registration.php file. So Composer will autoload your module's registration.php which will "tell" Magento2 where your module is located.
This is a fragment from the Magento Checkout module's composer.json:
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\Checkout\\": ""
}
}
So if you have your module in a separate repository and loaded via composer, then that is the way to go. If you do not have it in a separate repository, then your module does not belong on vendor/ but in app/code/.
See also this Magento Stack Exchange post.

Composer - require another package from my package/bundle but it just won't autoload. Solved in two other ways but not clean enough

I'm using Symfony 2.3 and Composer and using Composer to install my bundle from a remote repository. Doing this on its own works fine, but the problem I have is when I try to require another package from my Symfony2 bundle.
My bundle is in the src/ folder.
I've added this to my bundle's composer.json:
"require": {
"rackspace/php-opencloud": "1.10.*"
},
Everything installs but I now need to ensure the classes are autoloaded (registering namespaces I think), but it just won't do it.
I have actually solved this problem in two other ways, but they are not clean enough. I want my bundle to handle the dependency not the app folder or main Symfony2 composer.json.
Solutions that aren't good enough:
(1) If I add the Rackspace package to my symfony2/composer.json then everything works perfectly. But this is poor as the dependency is on my bundle not the whole Symfony2 framework.
(2) If I add these to app/autoload.php then it also works:
$loader->add('OpenCloud', __DIR__.'/../src/rackspace/php-opencloud/lib');
$loader->add('Guzzle\\Http', __DIR__.'/../src/guzzle/http');
$loader->add('Guzzle\\Common', __DIR__.'/../src/guzzle/common');
...but this is messy and again the dependency is on the bundle not the application.
I have tried various variations of this (in my bundle's composer.json) but it just won't work:
"autoload": {
"psr-0": { "OpenCloud": ["rackspace/php-opencloud/lib/", "rackspace/php-opencloud/tests/"] }
}
Normally, only relative paths are required.
"autoload": {
"psr-0": { "OpenCloud": ["lib/", "tests/"] }
}
I did not test with multiple paths for the same prefix. This may not be supported.
You can alternatively use the classmap autoloader, which will go through an entire folder and generate a static map from them. No prefix required.
"autoload": {
"classmap": ["lib/", "tests/"]
}
I rarely saw tests being included in the autoloading for external application however. PHPUnit handles class loading just fine.

Symfony 2.1 own vendor library

I want to put some code that I shall use in different projects outside the app's bundles. I put it in a new folder in the vendor folder but I can't included in the project. Which are the steps?
Should I follow a special structure of folder and namespaces
How do I included in my project.
On Google I found a lot of ambiguous answers. I tried also this but it did not work.
You need to get your library loaded. You do this by telling composer where to find your library.
The best thing would be to set up a git repository for this source code and then use composer to load it, keep it up to date and include it into the autoloader. You may need to get used to composer to do this, but as composer is getting the default dependency management tool for php, the time is not wasted. You can find the docs here: http://getcomposer.org/doc/
If you don't want to do this, you can add a new src code folder to composer. Let's say your folder structure is like this:
symfony2/
vendor/
yourlibrary/
Bla/
Blub/
MyClass.php
First, the MyClass.php should have the namespace Bla/Blub defined. Else Then you can add your library like this to the composer.json file:
"autoload": {
"psr-0": {
"": "src/",
"Bla": "vendor/yourlibrary/"
}
}
You already have autoload defined, so you need to overwrite it!
If your library doesn't have namespaces, you can define composer to load it nonetheless. I am not using this, so I can just link the docs where you can read it up: http://getcomposer.org/doc/04-schema.md#autoload

Resources