DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

Building Cordova packages for UWP using VSTS and Sparrowdo

Cordova and UWP

Cordova is a framework for mobile application development. It is a cross platform tool, you can create packages for various platforms ( Windows/Android/Apple ). Let's create UWP package for cordova application, it is really easy.

VSTS and Sparrowdo

We are going to use VSTS as a CICD framework and Sparrowdo as a code generator for our builds.

We are going to use so called YAML build definitions to create build scenario. This approach allows us to keep build logic in source code and treat build as a code.

We use Sparrowdo as high level Perl6 API to generate YAML build definition, instead of create those ones manually.

Generate build defintition

First of all let's install Sparrowdo and related Sparrowdo::VSTS::YAML::* dependencies, these are Perl6 modules:


$ zef install Sparrowdo Sparrowdo::VSTS::YAML::Build Sparrowdo::VSTS::YAML::Cordova VSTS::YAML::Artifact

Enter fullscreen mode Exit fullscreen mode

Then let create Sparrowdo scenario to build build definition:

$ nano cicd/Builds/uwp/sparrowfile
Enter fullscreen mode Exit fullscreen mode
#!perl6

module_run "VSTS::YAML::Build", %(
  build-dir => "cicd/Builds/uwp",
  queue => "Q-one",
  timeout => 20,
);

module_run "VSTS::YAML::Cordova", %(
  build-dir => "cicd/Builds/uwp",
  build-configuration => "debug",
);

module_run "VSTS::YAML::Artifact", %(
  build-dir => "cicd/Builds/uwp",
  artifact-name => "drop",
  path => "platforms/windows/AppPackages",
  publish-location => "Container"
);

Enter fullscreen mode Exit fullscreen mode

This high level code generates all necessary build infrastructure, we are all set up:

$ sparrowdo --localhost --no_sudo --sparrowfile=builds/uwp/sparrowfile

Enter fullscreen mode Exit fullscreen mode
running sparrow tasks on 127.0.0.1 ...
target OS is - centos7
enter module <VSTS::YAML::Build> ...
push [task] delete directory cicd/Builds/uwp/files OK
push [task] delete directory cicd/Builds/uwp/.cache OK
push [task] create directory cicd/Builds/uwp/.cache OK
push [task] create directory cicd/Builds/uwp/files OK
push [task] create template cicd/Builds/uwp/build.yaml OK
enter module <VSTS::YAML::Cordova> ...
push [task] create directory cicd/Builds/uwp/.cache OK
push [task] create directory cicd/Builds/uwp/files OK
push [task] create file cicd/Builds/uwp/files/npm-install.cmd OK
push [task] create file cicd/Builds/uwp/files/npm-install-cordova.cmd OK
push [task] create file cicd/Builds/uwp/files/platform-add.cmd OK
push [task] create file cicd/Builds/uwp/files/set-version.pl OK
push [task] create file cicd/Builds/uwp/files/prepare.cmd OK
push [task] create file cicd/Builds/uwp/files/clean-build-dir.cmd OK
push [task] create template cicd/Builds/uwp/files/build.cmd OK
push [task] create template cicd/Builds/uwp/.cache/build.yaml.sample OK
push [task] run bash: cat cicd/Builds/uwp/.cache/build.yaml.sample >> ci ... OK
enter module <VSTS::YAML::Artifact> ...
push [task] create directory cicd/Builds/uwp/.cache OK
push [task] create directory cicd/Builds/uwp/files OK
push [task] create template cicd/Builds/uwp/.cache/build.yaml.sample OK
push [task] run bash: cat cicd/Builds/uwp/.cache/build.yaml.sample >> ci ... OK
SPL file /opt/sparrow/sparrow.list is empty
get index updates from SparrowHub ... OK
set up task box file - /home/gimy/.sparrowdo//opt/sparrow/task-box.json - OK
public@directory is uptodate (0.1.6)
public@templater is uptodate (0.0.13)
Installing modules using /opt/sparrow/plugins/public/templater/cpanfile
Complete! Modules were installed into /opt/sparrow/plugins/public/templater/local
public@file is uptodate (0.0.6)
public@bash is uptodate (0.1.8)
running task box from /opt/sparrow/sparrow-cache/task-box.json ...
2018-08-13 20:48:23 : [task] delete directory cicd/Builds/uwp/files [path] modules/delete/
2018-08-13 20:48:23 : [task] delete directory cicd/Builds/uwp/.cache [path] modules/delete/
2018-08-13 20:48:24 : [task] create directory cicd/Builds/uwp/.cache [path] modules/create/
2018-08-13 20:48:24 : [task] create directory cicd/Builds/uwp/files [path] modules/create/
2018-08-13 20:48:24 : [task] create template cicd/Builds/uwp/build.yaml [path] modules/generate-content/
2018-08-13 20:48:24 : [task] create template cicd/Builds/uwp/build.yaml [path] / [msg] updated ok
2018-08-13 20:48:25 : [task] create directory cicd/Builds/uwp/.cache [path] modules/create/
2018-08-13 20:48:25 : [task] create directory cicd/Builds/uwp/files [path] modules/create/
2018-08-13 20:48:25 : [task] create file cicd/Builds/uwp/files/npm-install.cmd [path] /
2018-08-13 20:48:25 : [task] create file cicd/Builds/uwp/files/npm-install-cordova.cmd [path] /
2018-08-13 20:48:26 : [task] create file cicd/Builds/uwp/files/platform-add.cmd [path] /
2018-08-13 20:48:26 : [task] create file cicd/Builds/uwp/files/set-version.pl [path] /
2018-08-13 20:48:27 : [task] create file cicd/Builds/uwp/files/prepare.cmd [path] /
2018-08-13 20:48:27 : [task] create file cicd/Builds/uwp/files/clean-build-dir.cmd [path] /
2018-08-13 20:48:27 : [task] create template cicd/Builds/uwp/files/build.cmd [path] modules/generate-content/
2018-08-13 20:48:28 : [task] create template cicd/Builds/uwp/files/build.cmd [path] / [msg] updated ok
2018-08-13 20:48:28 : [task] create template cicd/Builds/uwp/.cache/build.yaml.sample [path] modules/generate-content/
2018-08-13 20:48:28 : [task] create template cicd/Builds/uwp/.cache/build.yaml.sample [path] / [msg] updated ok
2018-08-13 20:48:28 : [task] run bash: cat cicd/Builds/uwp/.cache/build.yaml.sample >> ci ... [path] modules/bash-command/ [params] envvars:
2018-08-13 20:48:29 : [task] create directory cicd/Builds/uwp/.cache [path] modules/create/
2018-08-13 20:48:29 : [task] create directory cicd/Builds/uwp/files [path] modules/create/
2018-08-13 20:48:30 : [task] create template cicd/Builds/uwp/.cache/build.yaml.sample [path] modules/generate-content/
2018-08-13 20:48:30 : [task] create template cicd/Builds/uwp/.cache/build.yaml.sample [path] / [msg] updated ok
2018-08-13 20:48:30 : [task] run bash: cat cicd/Builds/uwp/.cache/build.yaml.sample >> ci ... [path] modules/bash-command/ [params] envvars:

Enter fullscreen mode Exit fullscreen mode

Now we just commit changes and run VSTS build:

$ echo .cache >> .gitignore
$ git add cicd
$ git commit -a -m "my UWP build"
$ git push
Enter fullscreen mode Exit fullscreen mode

Conclusion

VSTS provides programmatic approach called YAML build scenarios to codify build logic. But developing in YAML is tedious. Instead of creating YAML build definitions manually we use Sparrowdo task runner to express build logic in high level and more flexible way using powerful Perl6 language.

For more details in the topic read Sparrowdo::VSTS::YAML::Cordova documentation.

Thanks

Alexey

Oldest comments (0)