How do I copy a file from a gem to my rails application using rake - rake

I have a gem with a default configuration YAML file, some_config.yml. I want to create a rake task to copy that file into the config/ directory of my rails application. How can I achieve this?

If we assume the target gem is in your Gemfile and you want to include the Rake task in your Rails Rakefile, then you could try something like:
namespace :config do
# desc "Copy the config"
task :copy do
source = File.join(Gem.loaded_specs["myGem"].full_gem_path, "config", "config.yml")
target = File.join(Rails.root, "config", "myGemConfig.yml")
FileUtils.cp_r source, target
end
end

Related

No lintable files found at paths SwiftLint

I tried to install SwiftLint using CocoaPods and I add in Build phases the following script :
"${PODS_ROOT}/SwiftLint/swiftlint"
SwiftLint is installed correctly and I get many errors and warnings in the project.
Then, I create the swiftLint.yml file in which I modify some rules but they are not token into consideration and the same number of errors and warnings persist in Xcode project.
When I run this command to confirm the application of the rules :
./swiftlint lint --config .swiftlint.yml
I get the error :
No lintable files found at paths : ''
How can I solve this issue please?
It happens also if you rename the directory of your app, make sure you report the change in the .swiftlint.yml too at first lines :
included: # paths to include during linting
- My_App_Directory
For those of you who used 0.42.0 before and updated to 0.43.0 (or higher?).
They made a change and now interpret included and excluded as relative paths.
Configuration files now consistently have their included/excluded
relative file paths applied relative to their location in the file
system. Previously the root configuration file applied these relative
to the current working directory, but nested configurations applied
these to their location in the file system.
From the release notes of 0.43.0: Clothes Line Interface.
if you are using swiftLint with CocoaPods : try "${PODS_ROOT}/SwiftLint/swiftlint" --config .swiflint.yml in your SwiftLint Run Script in your project build phases.
make sure your .swiflint.yml config file is in the root of your project directory ( beside .xcodeproj file ).
make sure the paths included on your .swiflint.yml (in included: and excluded: sections ) is valid paths
make sure your .swiflint.yml file is valid yaml
don't escape the directory paths in your config file
dont do : - some\ Directorybut do - some Directory without escape character.
If you installed it using Cocoapods this can help you.
I will just merely improve the above answers, to put clarity on how to resolve the issue of SwiftLint not finding the path.
Things to lookout for.
Make sure your swiftlint.yml file is valid.
Make sure the swiftlint.yml is in the same level as your .xcodeproj
Don't specify --path and also add an entry under included: inside your yml file, choose one, either specify the --path or add an entry don't use both otherwise SwiftLint will ignore the --path param, and if the entry specified inside included: is wrong you will get the "no lintable file found" error
In your script.
The gihub page of SwiftLint recommends just using "${PODS_ROOT}/SwiftLint/swiftlint" but that didn't work for me, I had to specify the --path see below for the full script.
"${PODS_ROOT}/SwiftLint/swiftlint" --path "${SRCROOT}/Classes" --config "directory-of-your-config"
The --path param should be your own --path "${SRCROOT}/Classes"
Finally inside the yml file.
Make sure your included and excluded file specification is correct, see how I did mine below.
included:
- Your-Project-Name
excluded:
- Pods
One Important thing to note is if you add directories under included: the --path param will be ignored, and you might possibly get the "no lintable files found" error if the directory is wrong.
First of all, you do not need to add explicitly the--config file if the yml file is in the running directory (from where you are running the command) and name is .swiftlint.yml.
Secondly, you need to specify the path for your source with --path. Below command will work fine in your case,
swiftlint lint --path SourcePath
For swiftlint from version 0.41 the following code worked for me in the build phase (workspace with several projects. Depending on the project configuration, it may be that "../" has to be removed from the path information):
cd ${PROJECT_DIR}/../
"${PODS_ROOT}/SwiftLint/swiftlint" --config "${PROJECT_DIR}/../.swiftlint.yml"
Here is a screenshot of the build phase entry:
Replace autocorrect with --fix
export PATH="$PATH:/opt/homebrew/bin" //This line is only for Apple Silicon chips
if which swiftlint > /dev/null; then
swiftlint --fix && swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
For M1, don't go for swift lint installation VIA PODS instead use Brew.
For installation run below command in Terminal
brew install swiftlint
and add below scripts into RunScript into build phase of your target.
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
If you using pod file then follow this steps:
Run Script: "${PODS_ROOT}/SwiftLint/swiftlint"
This worked for me
if which "${PODS_ROOT}/SwiftLint/swiftlint" >/dev/null; then
${PODS_ROOT}/SwiftLint/swiftlint --fix && ${PODS_ROOT}/SwiftLint/swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

Symfony4 Deployment with Encore

The current documentation says, that I only need the files under public/build, created with ./node_modules/.bin/encore production, when I want to deploy for production. But also to add public/build to git ignore. Do I have to copy the content of public/build manually?
In Symfony3 my deploy looked like that:
git pull
bin/php bin/console cache:clear --env=prod --no-debug
bin/php bin/console assets:install --env=prod
bin/php bin/console assetic:dump --env=prod --no-debug
FYI, Using assetic was the »old« way, and starting Symfony 2.8 Assetic is not included in the standard framework anymore (but you can still add it).
Regarding public/build you misunderstood it a bit - the actual source files should be somewhere else, for example in assets/css/app.scss and assets/js/app.js. Using Webpack Encore, running ./node_modules/.bin/encore production will minify, uglify, etc (whatever you configure in webpack.config.js) these source files and then copy the generated files to public/build. So public/build will only contain the generated stuff and thus can be safely added to .gitignore (but you also need to run the encore script in production).
Your JavaScript file (i.e. in this case app.js) should include
require('../css/app.scss');
so that the app.scss is actually a dependency of app.js and you only need to tell the webpack.config.js to include the JavaScript file. The basic configuration of webpack.config.js might look like this:
// webpack.config.js
var Encore = require('#symfony/webpack-encore');
Encore
// this will put all your compiled stuff into public/build, that’s
// why you can put this into .gitignore, because you can re-build this
// from the source files.
.setOutputPath('public/build/')
// the public path used by the web server to access the previous directory
.setPublicPath('/build')
// this will create public/build/app.js, and also public/build/app.css
// since the scss file is a dependency of app.js
.addEntry('app', './assets/js/app.js')
// allow sass/scss files to be processed
.enableSassLoader()
[...]
;
// export the final configuration
module.exports = Encore.getWebpackConfig();
You can find some more explanation under https://symfony.com/doc/current/frontend/encore/simple-example.html (first example) or https://symfony.com/doc/current/frontend.html (overview)

How do I configure the output-path of ember-cli as a setting?

I'm using ember as part of a bigger project and so both dev and production build into a subdirectory somewhere else. Can I specify output-path as a setting rather than on the commnad line?
You could modify your package.json and add in the scripts there such as:
"scripts": {
"buildprod": "ember build --environment=production --output-path=yourProdPath",
"builddev": "ember build --output-path=yourDevPath"
}
And just run them in the cli npm buildprod.
Create a file named .ember-cli inside the app folder and mention the output path. Ember will recognize the path automatically when we do "ember build"
{
"outputPath" : "D:/MyApplication/working/ember"
}

How to configure PHPUnit with ZF version 1.12.11

I am using zend framework 1.12.11 and now I want to use PHPunit with it.Pear has stopped it's stopped support for phpunit.Now it's working with composer.
I have install composer and phpunit via composer.But Where I have to put composer json setting file and my project and what should include in my project which automatically take phpunit of composer
Per the PHPUnit documentation for Composer installation, add PHPUnit to the dependencies in your project's composer.json file, something like:
{
"require-dev": {
"phpunit/phpunit": "4.6.*"
}
}
Then run:
composer update -vvv phpunit/phpunit
to actually bring PHPUnit and its dependencies down into your project.
I usually add the -vvv (maximally verbose) flag to see what's going on under the hood. Feel free to omit if you prefer.
Once they are all installed, you can run phpunit the usual way by accessing the executable bin script that PHPUnit and Composer expose for you. From the project root, you should be able to run:
./vendor/bin/phpunit --version
to confirm the install is ok.
Once you have a phpunit.xml config file set up that your test suites and directories, you should be able to run your tests using:
./vendor/bin/phpunit -c /path/to/phpunit.xml

How do you setup heroku_san with Sinatra?

For example how do you push code to specific heroku application using the heroku_san rake shortcut commands, eg.
rake otherapp heroku:push
(taken from http://jqr.github.com/2010/08/27/easy-heroku-deploys-with-heroku-san.html )
I keep getting:
rake aborted!
Don't know how to build task 'otherapp'
I have a config directory under my sinatra app. And this contains a heroku.yml as mentioned in the above guide. The file looks like this
apps:
production: mycoolherokuapp
otherapp: myotherherokuapp
I have otherapp already created on heroku.
heroku_san is Rails specific.
If you look at the lib code it uses: Rails.root.join, RAILS_ENV, Rails.configuration, and Railtie throughout.
I'm working on a fork of heroku_san that will (eventually) remove the coupling between Rails & heroku_san. Right now, I'm working on making a testable class. https://github.com/kmayer/heroku_san -- try it out and send me some feedback.
Ken actually completed the Sinatra compatibility code and just released version 3.0.0 which includes Sinatra support.
Update your Gemfile:
group :development do
gem 'heroku_san'
end
Update your Rakefile:
require "bundler/setup"
require "heroku_san"
config_file = File.join(File.expand_path(File.dirname(__FILE__)), 'config', 'heroku.yml')
HerokuSan.project = HerokuSan::Project.new(config_file, :deploy => HerokuSan::Deploy::Sinatra)
load "heroku_san/tasks.rb"
See documentation at https://github.com/fastestforward/heroku_san