obfuscate JS before FireBase Deploy - firebase-hosting

I have started using Firebase to host an app I am building in js.
I want to be able to obfuscate my java script code before I deploy it to FireBase.
I couldn't find a way of doing this automatically with firebase, so I downloaded the closure compiler, and started writing a deploy.bat batch file that would....
Copy all my code and assets from my public folder to a deploy folder
Obfuscate the JS
Deploy the site to Firebase.
However now I have found out that you cant have separate folders for dev local hosting e.g. (public - using the emulator) and another folder for what should be deployed to firebase.
Could anyone suggest how I can get around this ?

You can split the folders into a "development" and "production" build. However care should be taken to ensure that your tests pass against your production build as well as the development build.
The following folder structure will allow to deploy your obfuscated code by calling npm run build followed by npm run deploy from the project/dev folder in your terminal.
- /project
- /prod
- .firebaserc
- firebase.json
- /public
- ... (obfuscated files)
- /dev
- .firebaserc
- firebase.json
- package.json
- /public
- ... (source files)
In project/dev/firebase.json, merge in this to get firebase deploy to deliberately crash if accidentally called from inside of project/dev:
"hosting": {
"predeploy": "node -e \"process.exit(1)\""
}
In project/dev/package.json, merge in this so that your code is built/obfuscated into the project/prod directory:
"scripts": {
"build": "npm run build-hosting && ...",
"build-hosting": "INSERT-TOOL-HERE --srcDir ./public --outDir ../prod/public",
"deploy": "npm run deploy-hosting && ...",
"deploy-hosting": "pushd ../prod && firebase deploy --only hosting && popd",
}

Related

Run script and add files to Swift Package via BuildToolPlugin

Context
I recently took over a Swift project which relies on git submodules. One of my first task was to clean up the project, which means removing submodules, using Swift Packages.
On my way doing this i encounter a tricky submodule. It contains swift files and a WebPack project that's loaded in a WebView. Currently the project that imports this submodule has a custom build phase that runs npm ci + npm build to build the WebPack and copy the files into the app.
Question:
When i switch to using a Swift Package it should manage this custom build phase on its own. Is it possible to run npm ci + npm build in a BuildToolPlugin?
My current state is trying to run a shell script which simply creates a file:
#main
struct TSPlugin: BuildToolPlugin {
func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
let tsPath = context.pluginWorkDirectory
.appending (subpath: target.name)
.appending (subpath: "Seatmap")
print(tsPath)
print("here1")
let scriptPath = context.package.directory.appending(["..", "TSPlugin", "TEst.sh"])
print("here2")
return [
.prebuildCommand(
displayName: "Generating localized strings from source files",
executable: scriptPath,
arguments: [],
outputFilesDirectory: tsPath
)
]
}
}
#!/bin/bash
echo "come on"
touch easypeasy.txt
I rebuilt this in a demo project: https://github.com/Deitsch/SwiftPluginDemo

Unable to run/debug robot tests in vscode - robocorp extensions installed

I have installed Robocorp Code as well as Robot Framework Language Server and have configured them. However, I am still having errors when trying to run the tests via the code lens options.
Repo - A webapi repo with a specific folder containing all tests. Lets call it regression.
RF - 4.1.3
Python - 3.8
This is what happens when I click on Run on the code lens for any of the tests -
`PS C:\git\xxxx\regression> C:; cd 'C:\git\xxxx\regression'; &
'C:\Users\xxxx\AppData\Local\Temp\rf-ls-run\run_env_00_smh5defr.bat'
'-u'
'c:\Users\xxxx.vscode\extensions\robocorp.robotframework-lsp-0.47.2\src\robotframework_debug_adapter\run_robot__main__.py'
'--port' '54331' '--no-debug' '--argumentfile'
'C:\git\xxxx\regression\args-local.txt' '--pythonpath'
'c:\git\xxxx\regression\common\lib' '--variable'
'EXECDIR:C:/git/xxxx/regression'
'--prerunmodifier=robotframework_debug_adapter.prerun_modifiers.FilteringTestsSuiteVisitor'
'c:\git\xxxx\regression\api\api_Test.robot'
[ ERROR ] Parsing'--pythonpath' failed: File or directory to execute does not exist.
However, the test starts if I remove the argumentfile parameter but it, of course, fails because its missing arguments from the file.
Do note that the folder specified in pythopath exists and has some python libraries needed for the tests.

Understanding npm packages inside github actions

Here is my idea: build a static web page template, over time add .md files to a /posts directory and build a CI job to convert the .md files to html (with the showdownjs/showdown package).
Is there a need to install the package on every push? Seems like a waste, but uploading /node-modules is incorrect as well. Is there a way to install the package once, and let github action just work with it (run the md to html converter on newly added files)?
You have 2 options:
Recommened: Use caching action to cache dependencies for your project - using a hash from package-lock.json as a key to make sure it rebuild when depenendencies has changed:
- name: Cache node modules
uses: actions/cache#v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ hashFiles('**/package-lock.json') }}
- name: Install Dependencies
run: npm install
Push your node_modules to Git repository so it's checkout together with everything else
For optimising a need to run your converted you can use this action:
https://github.com/tj-actions/changed-files/
and detect if any files were modified at certain path

Deploying .NET Core Application with Windows Compatibility Pack

I'm busy deploying a .NET Core 2.1 application into our testing environment, but I'm getting the following error.
Error:
An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
package: 'System.Diagnostics.EventLog', version: '4.5.0'
path: 'runtimes/win/lib/netcoreapp2.1/System.Diagnostics.EventLog.dll'
We are using the Windows Compatibility Pack to access the Event Log.
I have the following item in the dependency Json file:
"System.Diagnostics.EventLog/4.5.0": {
"dependencies": {
"Microsoft.Win32.Registry": "4.5.0",
"System.Security.Permissions": "4.5.0",
"System.Security.Principal.Windows": "4.5.0",
"System.Threading.AccessControl": "4.5.0"
},
"runtime": {
"lib/netstandard2.0/System.Diagnostics.EventLog.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp2.0/System.Diagnostics.EventLog.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
}
}
Please advise how one should deploy these dependencies. Also, what is the root folder to this relative path runtimes/win/lib/netcoreapp2.0?
We actually found a solution for our scenario:
- Our situation was that we tried to run a netcoreapp based test project on our test agent
- dotnet test on the project file worked
- dotnet vstest sometimes worked on the project output directory (we are not sure why and on which setup)
- dotnet vstest did run into the above error when run into an other directory & downloaded from CI
- dotnet vstest did run into an AssemblyNotFoundException on the test agent (which didn't make any sense for us)
The solution was to use dotnet publish for our test project and use the "self-contained" output to run on the test agent. dotnet publish copied the required runtimes/win/lib/netcoreappX.X/*.dll files into the publish output directory.
After a lot of testing, the key issue seems to be the "RuntimeIdentifiers". There is a visible option for this when you publish, but in order to use it when just building you need to add a couple of tags to your .csproj file.
The first is:
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
This will cause NuGet to retrieve the correct dlls (change the value depending on your needs). For me I was compiling to platform x86. I don't know what NuGet was getting by default, but whatever it was had different file sizes for the same files.
You also should then add this tag:
<SelfContained>false</SelfContained>
or else your build will default to copying the entire framework.
Also note that using the RuntimeIdentifier tag will cause your default output folder to include the value you specified. For example my subfolder became:
Project\bin\x86\Debug\netcoreapp3.1\win-86\
For publishing you should be able to do something similar; the problem will be to match your RuntimeIdentifier to your platform. You shouldn't need to specify SelfContained unless you specifically need to.

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"
}