How to include folder but excluding some files inside that folder when packaging for serverless? - serverless-framework

I want to include node_modules, but exclude the .bin dir, and the .cache and .yarn-integrity files since they take up space on the lambda.
exclude:
- ./**
- '!node_modules/**'
- node_modules/.cache
- node_modules/.bin
- node_modules/.yarn-integrity
Like wise, I would like to include the 'server' folder, but exclude the tests and eslint config files:
exclude:
- ./**
- '!server/**'
- server/**/*.test.js
- server/.eslintrc.js
But neither work, and the files are not excluded. What's the correct way to do this?

You can include the node_modules/ dir while excluding the node_modules/.bin dir like this:
package:
exclude:
- node_modules/.bin/**
By default only these directories are excluded:
.git/**
.gitignore
.DS_Store
npm-debug.log
.serverless/**
.serverless_plugins/**
So you do not need to specify that node_modules/ and server/ are to be included - they will be be default. Just specify which sub-directories inside them you want to exclude.
Source: https://serverless.com/framework/docs/providers/aws/guide/packaging/

Related

Configure node-sass in PhpStorm

I have the following directory structure:
-dir
--css
--scss
--main.scss
Now after compiling a file I have:
-dir
--css
--scss
--main.scss
-main.css
My File Watcher settings for node-sass:
How can I compile all .scss files into css folder?
-dir
--css
--main.css
--scss
main.scss
It can be smth like:
Arguments: $FileName$ --source-map=true -o $ProjectFileDir$/css
Output paths to refresh: $ProjectFileDir$/css/$FileNameWithoutExtension$.css:$ProjectFileDir$/css/$FileNameWithoutExtension$.css.map
Working directory: $FileDir$
Here is the solution if you need to navigate to the parent folder
Arguments: $FileName$ $FileParentDir$\css\$FileNameWithoutExtension$.css
Output: $ProjectFileDir$/css/$FileNameWithoutExtension$.css:$ProjectFileDir$/css/$FileNameWithoutExtension$.css.map

How to exclude files from the packaging in serverless.yaml?

I have the following configuration in my serverless.yaml file:
provider:
package:
exclude:
- ./**
include:
- src/**
But anyways all the folders in my root are being included in the service .zip file.
What am I missing here?
Move the package outside provider
provider:
package:
exclude:
- ./**
include:
- src/**
And if you have multiple lambdas in same file then you can add the package as such
functions:
Function1:
handler: functions_folder/.Function1.handler
package:
include:
- functions_folder/Function1.js

cmake - How to change compile_commands.json output location

Here's an example C++ project structure:
- {root}
- CMakeLists.txt
- build/
- compile_commands.json <-- This file gets generated
- src/
- CMakeLists.txt
- files here
- compile_commands.json <-- This is where I want compile_commands.json to be built to
If I build the project, it creates a "compile_commands.json" file in the "build" folder. But I actually want it underneath "{root}". Is there a way to specify the location of compile_commands.json? Or do I have to just copy it manually?
These are the command(s) that I typically use to build a project
(If cd'ed into {root})
cmake . -B build
alternative:
cd {root}/build && cmake ..
In both cases, compile_commands.json is added to the build folder
Is there a way to specify the location of compile_commands.json?
There is no way. I believe the path for compile_commands.json generated when CMAKE_EXPORT_COMPILE_COMMANDS is set is hardcoded to be inside CMAKE_BINARY_DIR.
Just create a symlink compile_commands.json -> ./build/compile_commands.json.

How to run eslint in different folders

I came into a eslint problem.
Generally, we have src folder side by side with package.json, like this:
|-projectName
|- src
|- .eslintrc.js
|- package.json
|- vue.config.js
Then i want to take compiling scripts and business code apart into different folders, and to enable them to be linted, i put two '.eslintrc.js' files in each, like this:
|- projectName
|- runtime
|- babel.config.js
|- .eslintrc.js
|- package.json
|- vue.config.js
|- business
|- .eslintrs.js
|- src
|- main.js
|- index.html
|- ...
Then i found eslint turns into chaos:
When i ran 'npm run build', eslint firstly linted files in 'runtime' folder as '.eslintrc.js' in it,
and then vue-cli-service came into building stage, which called eslint again as '.eslintrc.js' in 'template' folder,
but at last the vue-cli-service still finished building even if eslint throws errors, which should stopped building.
The output was like this:
✖ 7 problems (4 errors, 3 warnings)
3 errors and 3 warnings potentially fixable with the `--fix` option.
# ../template/src/store/index.js 14:0-34 18:10-14
# ../template/src/main.js
# multi ../template/src/main.js
...
File Size Gzipped
../template/build/apps/local/0/js/chun 174.42 KiB 58.47 KiB
k-vendors.9db3f582.js
...
DONE Build complete. The ../template/build directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
I don't know why this happened? Is there someting wrong with eslint config? I just put two '.eslintrc.js' files generated by 'vue craete' command in two different folders , and configure right paths in vue.config.js, like this:
// vue.config.js
...
outputDir: path.resolve(__dirname, '../template/build'),
pages:{
index: {
entry: path.resolve(__dirname, '../template/src/main.js')
}
}
...

CPack Source archive empty on Travis CI but not locally

I am using CPack to create source archives:
cmake --build . --config Release --target package_source
This works fine on my local Ubuntu machine, but the resulting archives are empty when build on Travis CI. There are no error messages. I have checked the CPack logs when --debug is enabled and do not see any differences except the files are not being copied to the temporary install space. The source and destination paths are correct, but the files are not being found.
Why are the archives empty when built on some machines but not others?
After being stuck with the same issue for 10+ hours I finally figured it out. Maybe it's the same for you. It's the most logical thing actually after excluding all other causes: The files are being ignored!
I was skipping the "build" directory within my source from package_source:
# exclude build directories like /build/, /build-* and /build_*
list(APPEND CPACK_SOURCE_IGNORE_FILES "/build[\\-_/]")
However the path on travis is /home/travis/build/AlexanderLanin/ccache
Option 1
I'm no regex expert, but this should put you on the right path at least:
list(APPEND CPACK_SOURCE_IGNORE_FILES "^((?!/home/travis/).*|/home/travis/.+)/build[\\-_/]")
Explained # https://regex101.com/r/DJfeDi/1
Option 2
Slightly simpler assuming you are within CMakeLists.txt:
list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/build[\\-_/]")
list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_BINARY_DIR}")