Scripted editing of Symfony 2 YAML file breaks the formatting and produces errors - bash

I'm trying to script out our entire installation process of new Symfony 2.1 projects including adding and configuring all our bundles and their dependencies. The end result should be one command that sets up everything so the developer is both forced into our best practices setup, and does not have to spend time on this.
So far this is fairly successful since it is now possible to go from 0 to fully installed CMS in about an hour (mostly due to composer installs). You can see the result here: https://github.com/Kunstmaan/KunstmaanSandbox/blob/feature/update-to-2.1/README.md
The next fase of this project is modifying the Symfony config YAML files. But here I'm stuck.
For the parameters.yml I did this with a ruby script, here is the relevant extract, the full script can be found here: https://github.com/Kunstmaan/KunstmaanSandbox/blob/feature/update-to-2.1/app/Resources/docs/scripts/sandboxinstaller.rb
parametersymlpath = ARGV[1]
projectname = ARGV[2]
parametersyml = YAML.load_file(parametersymlpath)
params = parametersyml["parameters"]
params["searchport"] = 9200
params["searchindexname"] = projectname
params["sentry.dsn"] = "https://XXXXXXXX:XXXXXXXX#app.getsentry.com/XXXX"
params["cdnpath"] = ""
params["requiredlocales"] = "nl|fr|de|en"
params["defaultlocale"] = "nl"
params["websitetitle"] = projectname.capitalize
File.open(parametersymlpath, 'w') {|f| f.write(YAML.dump(parametersyml)) }
So far so good, but the same type of script fails on the config.yml due to these lines:
imports:
- { resource: #KunstmaanMediaBundle/Resources/config/config.yml }
- { resource: #KunstmaanAdminBundle/Resources/config/config.yml }
- { resource: #KunstmaanFormBundle/Resources/config/config.yml }
- { resource: #KunstmaanSearchBundle/Resources/config/config.yml }
- { resource: #KunstmaanAdminListBundle/Resources/config/config.yml }
The # is a reserved character according to the YAML spec and Ruby throws an error.
So I switched to php and the Symfony yaml component since at this point in the install there is a full symfony install and i came up with this standalone command: https://gist.github.com/3526251
But when reading and dumping the config.yml file the lines above for example would turn into
imports:
-
resource: #KunstmaanMediaBundle/Resources/config/config.yml
-
resource: #KunstmaanAdminBundle/Resources/config/config.yml
-
resource: #KunstmaanFormBundle/Resources/config/config.yml
-
resource: #KunstmaanSearchBundle/Resources/config/config.yml
-
resource: #KunstmaanAdminListBundle/Resources/config/config.yml
Which looks like crap and i'm not entirely sure this will even work.
So at this point i'm looking at moving the fully modified config.yml files to the install script and just overwriting the originals. I would rather not go there, since it will take constant maintenance if something changes in the symfony-standard project.
I'm wondering if there is another way?

These two forms are semantically equivalent. They are called the Inline and Indented Blocks, respectively.

Related

Can't make code_ownership and code_teams gems to work

The gems code_teams, code_ownership should allow one to tag files/whole folders by team name but after adding them to my project, running bundle install etc, I still encounter the same error
Passed `nil` into T.must
sample team file (placed in config/teams as advised) is as following
name: Smurfs
owned_globs:
- folder/folder2/**/*
The code where I try to use the info is :
x = CodeOwnership.for_backtrace(e.backtrace)
Turns out the path was not in the format expected.
The path should not end with /*

Minima theme build shows "Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences"

Here's a link to my website Facey's Thoughts and here's a link to the GitHub Pages project.
Cloning the (working) repository to my local machine and trying to run jekyll build fails with this error:
Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: social-icons/.svg Valid syntax: {% include file.ext param='value' param2='value' %} in assets/minima-social-ico.html
The Jekyll version is still the same as what's specified in my Gemfile:
jekyll 4.3.1. I have no idea what's changed.
I've tried removing the minima-social-ico.svg file; I've tried removing the posts that I was trying to add; I've tried searching Online for something similar to this issue without luck.
I tried jekyll build with local files, cloning my GitHub pages repo to a new directory, and that repo for sure built last night, and I've tried removing any new .markdown files that I made since the last time it successfully built.
I tried the following:
If I comment out social_links from my _config.yml file, it will build, I assume because it's not using the minima_social_icons.svg file. Why did it work and now it doesn't?
The problem is more with using the remote theme without locking to a specific commit/tag. (Since the v3.0 is still in development, any breaking change added to the main branch will break the build as well, if we refer to the latest changes always.)
One can lock to a specific commit/tag as: (in _config.yml file)
remote_theme: jekyll/minima#<insert-commit-hash_or_tag>
This time the breaking change was #686. Using social links more explicitly, as mentioned by Yshmarov should resolve the issue.
minima:
social_links:
- { platform: github, user_url: "https://github.com/jekyll/jekyll" }
- { platform: twitter, user_url: "https://twitter.com/jekyllrb" }
Updating social links to be more explicit solved it for me:
social_links:
- { platform: rss, user_url: "/feed.xml" }
- { platform: github, user_url: "https://github.com/yshmarov/" }
- { platform: twitter, user_url: "https://twitter.com/yarotheslav" }
- { platform: linkedin, user_url: "https://www.linkedin.com/in/yshmarov/" }

Laravel Mix and SASS changing font directory

I'm using Laravel 5.4 and Laravel Mix to output SASS files.
In my font definitions I'm configuring them so that when the CSS is output it will point to files such as public/assets/fnt/font-name/filename.ext but the processor changes the output so that it will instead point to public/fonts/filename.ext. Is there a way to stop it from changing the output paths?
It makes little sense to me that it would do something like this by default.
Edit
I've seen that the defaults they're using in Mix are the culprit:
module.exports.module = {
rules: [
// ...
{
test: /\.(woff2?|ttf|eot|svg|otf)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]?[hash]',
publicPath: '/'
}
}
]
};
I've tried using null-loader instead of file-loader but instead it causes it to fail because it can't find the files in node_modules which is not where it should be looking in the first place.
Removing the rule in question results in a flood of errors from trying to open and evaluate the font files in question:
error in ./public/assets/fnt/fanfare-jf/fanfare-jf.ttf
Module parse failed: DIRECTORY\public\assets\fnt\fanfare-jf\fanfare-jf.ttf Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
# ./~/css-loader!./~/postcss-loader!./~/resolve-url-loader!./~/sass-loader?sourceMap&precision=8!./resources/assets/sass/app.scss 6:2525-2590
# ./resources/assets/sass/app.scss
# multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss
I can at least add emitFiles: false to options to prevent it from making copies of the file, but the paths are still being altered.
I ended up with the following configuration to at least get it to a working state.
let assetDir = 'assets/build';
mix.config.fileLoaderDirs.fonts = `${assetDir}/${mix.config.fileLoaderDirs.fonts}`;
mix.config.fileLoaderDirs.images = `${assetDir}/${mix.config.fileLoaderDirs.images}`;
mix.sass('resources/sass/app.scss', `public/${assetDir}/css`)
.js('resources/js/app.js', `public/${assetDir}/js`);
Updated:
In newer versions this has been made customizable via mix.options() and can be adjusted as below:
let assetDir = 'assets/build';
mix.options({
fileLoaderDirs: {
images: `${assetDir}/img`,
fonts: `${assetDir}/fonts`
}
});
// adjust build commands accordingly, for example:
mix.js('resources/js/app.js', `public/${assetDir}/js`);
The output you got is the intended behaviour due to your configuration.
You are using this configuration to load the file:
options: {
name: 'fonts/[name].[ext]?[hash]',
publicPath: '/'
}
Which says use the publicPath as public and create a file with the name fonts/[name].[ext]?[hash] and webpack knows about what these symbols '/', '.', '?' in the name do.
It just looks for the fonts directory and if there is no any fonts directory it creates a new one and place the files into that directory.
So, you need to use this configuration for your folder structure:
options: {
name: 'assets/fnt/font-name/[name].[ext]?[hash]',
publicPath: '/'
}
This should work for your configuration.
More on file-loader configuration:
https://github.com/webpack-contrib/file-loader#filename-templates
Edit:
Since Laravel Mix uses Webpack in it's background and Webpack doesn't have any knowledge of the fonts file when there is no any appropriate loader added to the configuration. So, the error:
Module parse failed: DIRECTORY\public\assets\fnt\fanfare-jf\fanfare-jf.ttf Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
is occurred.
You need to tell the Webpack to load the fonts to your desired directory and the fonts linked in your SASS file will be linked by the Webpack without any more configurations.

parse.exe not seeing my projects

I am trying to configure my machine to deploy Parse Cloud Code. This requires downloading and running ParseDeploy.exe, followed by parse new.
I am running Win 8.1, and using the latest parse-windows-2.0.7.exe.
The folder structure is correctly created.
After entering my email & password, I am meant to see a list of my apps. Instead I am seeing:
1: results
Select an App:
"results" is not the name of any of my 3 apps.
This is what the PowerShell output looks like:
PS E:\...\demo> parse new
Creating a new project in directory E:\...\demo\parse
Creating directory E:\...\demo\parse\config
Creating config file E:\...\demo\parse\config\global.js
on
Creating directory E:\...\demo\parse\cloud
Writing out sample file E:\...\demo\parse\cloud\main.js
Creating directory E:\...\demo\parse\public
Writing out sample file E:\...\demo\parse\public\index.
html
Email: richard#glowworm.mobi
Password:
1: results
Select an App:
Related post:
Parse: No list of apps from Parse in CTL windows 7
I have used this successfully on previous projects. What has changed?
Some very old versions of the Parse command line utility may run into this issue due to some backend changes. You can get around this issue by making sure you're running the latest version of the command line utility, available at https://parse.com/docs/downloads
I also recommend joining the Parse developer mailing list, where we made an announcement a couple of weeks ago recommending that people make sure they update their command line utility prior to the backend change going into effect: https://groups.google.com/forum/#!topic/parse-developers/WoRnDft4qmE
Update
v2.1.3 fixes this issue, and works correctly on my machine.
What has changed? Parse has made updates, requiring a new version of parse.exe to be downloaded.
Unfortunately the initial new versions do not work.
Workaround
I have rolled back to using v1.4.2 of parse.exe.
It is currently working for deploying projects.
However, it breaks when creating a new project with parse new (as per my question).
The file that breaks is .\config\global.json - it seems to be in a new format, and it tries to reference this non-existent "results" project.
What I have done is to an existing global.json file from an older project, and manually edit it to update the values for my new project. Here is an example:
{
"global": {
"parseVersion": "1.4.2"
},
"applications": {
"<< AppName >>": {
"applicationId": "<< app id >>",
"masterKey": "<< master key >>"
},
"_default": {
"link": "<< AppName >>"
}
}
}
Just update the following fields:
<< AppName >>
<< app id >>
<< master key >>
(works as of 2 June 2015)
Bug Reported
A bug has been opened related to this issue on Facebook Developers:
https://developers.facebook.com/bugs/971635999542789/
The following versions are not running on my machine:
v2.0.7
v2.0.8
v2.0.9
There are other reports on the support forum that these versions are broken for other people as well.

symfony2 assetics yui compressor on windows (path syntax)

I'm trying to get assetics running with the yui compressor and, if this is running, sass. Right now, both don't work. When removing all filters from config.yml and the twig template, it works and php app/console assetic:dump does copy the css and js files.
Now I want to add the yui compressor and my config.yml looks like this:
assetic:
debug: %kernel.debug%
use_controller: false
filters:
yui_js:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
Adding the filter to the template and running assetic:dump again ends in the following error (translation of message by me):
[RuntimeException]
The syntax for filename, directory name or drive name is wrong
I found an article telling me to specify the path to java.exe, so I add this to config.yml:
assetic:
..
java: C:/Program Files (x86)/Java/jre6/bin/java.exe
..
Now assetic:dump tells me:
[RuntimeException]
The COMMAND "C:/Program" is either written wrong or
I tried playing around with both variables (using \ or \ instead of /, adding single or double quotes, working with short alias Progra~1 or Progra~2) in the config, but I didn't get anywhere. The both errors comming up all the time. Maybe someone can point me in the right direction.
Ok, I figured it out. Man, this one was brutal.
Let's start with the easy stuff. A working version of the config.yml can look like this:
assetic:
debug: false
use_controller: false
java: C:\Program Files (x86)\Java\jre6\bin\java.exe
sass: C:\Program Files (x86)\Ruby192\bin\sass.bat
filters:
scss: ~
yui_js:
jar: %kernel.root_dir%\Resources\java\yuicompressor-2.4.6.jar
For some reason, assetic is always importing a whole directory for scss, so I had to make a combine.scss which imports the other scss files in the correct order.
And now it gets ugly, as one have to change the assetics core in order to get this working. The developers of assetic know this bug and I think it is fixed in some development trunk/branch but not the stable one.
The Assetic\Util\ProcessBuilder has to be changed on line 95
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
,line 103
$script .= ' '.implode(' ', array_map('escapeshellarg', $args));
and line 110
return new Process($script, $this->cwd, null, $this->stdin, $this->timeout, $options);
I hope this bug get fixed soon and till then anybody trying to get it working finds this thread... Took me like 8 hours of debuging, reading and trying different approaches.
Answer by Boo Nov 19 at 22:53 did work for me by changing everything he mentioned in Assetic\Util\ProcessBuilder (I ignored line 95 as it looks the same as in my file)
Now it works on windows. Thanks!
Just to confirm. Im using Symfony 2.0.7 and yuicompressor-2.4.7
For other users who use window server 2008 r2 :
Maybe you should change the C:\windows\Temp folder property to 777 (read/write) for the IIS user / or the machine's normal user
please unpack the ruby.7z from rubyinstaller.org , and go to C:\_ruby193\bin , in this unpack position you should exec the CMD prompt , type :
ruby -S gem install sass
so that you will get the sass.bat in that position
It's time to use Boo's best answer , and please notice that in symfony2 dev env maybe it's not necessary to change the use_controller to false (in the config.yml) , because there's another use_controller in the config_dev.yml (set to true) , and in routing_dev.yml there's also a _assetic router , they're perhaps associated.

Resources