Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

Add new tutorial draft #412

Merged
merged 9 commits into from Nov 15, 2017
Merged

Add new tutorial draft #412

merged 9 commits into from Nov 15, 2017

Conversation

caldav
Copy link
Contributor

@caldav caldav commented Nov 14, 2017

This is a draft.
How to snap a website with Electron. Ready for review.

Demo: http://tutorials.ubuntu.com-pr-412.run.demo.haus/tutorial/snap-a-website

Note that this tutorial is not relying on the electron-builder snap integration since it doesn't use cleanbuild and produces broken snaps on 17.10.

@webteam-app
Copy link

Starting demo at: http://tutorials.ubuntu.com-pr-412.run.demo.haus/

@caldav caldav requested a review from evilnick November 14, 2017 14:12
## Overview
Duration: 1:00

Turning your website into a desktop integrated app is a relatively simple thing to do, but distributing it as such and making it noticeable in app stores is another story. This tutorial will show you how to leverage Electron and snaps to create a website-based desktop app from scratch and publish it on a multi-million users app store shared between many Linux distributions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publish it on a multi-million user
Also, do we want to say 'app store', I think just 'store would do fine

cd app
```

With the `npm` command, we can install electron and electron-builder inside the current directory. They will provide the framework and tooling to build our app binary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that 'electron' here is used as the name of the package - maybe it would make more sense to italicise these?

summary: Destroy your opponent's castle to win!
description: |
Play online or against a bot, click and drag cards to your side of the field
to deploy powerful building and units to attack your ennemy.
Copy link
Contributor

@evilnick evilnick Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildings? enemy?

plugin: nodejs
```

A part needs a `source`, to declare where to pull its code from, relatively to our project directory. In this case: `app/`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative


A part needs a `source`, to declare where to pull its code from, relatively to our project directory. In this case: `app/`.

The `plugin` is the type of part we are building: it's a `nodejs` app. Which means snapcraft will use `nodejs` when building the snap, and bundle it (among other related dependencies) in the final snap package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means snapcraft...

summary: Destroy your opponent's castle to win!
description: |
Play online or against a bot, click and drag cards to your side of the field
to deploy powerful building and units to attack your ennemy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as previously 😄


### Icon and desktop file

The last bit of packaging we need is an icon and a `<app>.desktop` file so desktop environments recognize our app as such. The icon and the desktop file will be picked up by snapcraft and handled accordingly by putting them in a `snap/gui/` directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can either have "so desktop environments will" or "so that desktop environments..."


Some details about the output you are now looking at:

1. The container is created (if it's the first time you create an Ubuntu 16.04 container on this computer, an Ubuntu image is downloaded as part of the process)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't codelabs support proper markdown lists? These should all be '1.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codelabs do, I obviously don't :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment

Copy link
Contributor

@evilnick evilnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few more spelling and grammar bits


## What next?

What a journey! If this is the first time you installed a snap or created a LXD container, you may have realized that most of the time spent in this tutorial was looking at downloads! When the tools have been used once, things get much faster, since most of them don't have to be installed or initialized anymore.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realised, initialised

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put here the paragraph about releasing.


Positive
: **What does `--dangerous` mean?**
The `--dangerous` flag indicates that you are acknowledging that this snap could be unsafe to install, this is necessary when the snap didn't went through store security checks. Since you are the developer of the snap, you know it's safe, but the snap command doesn't and would prevent the install if you omitted the flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"when the snap hasn't been through..."


### Icon and desktop file

The last bit of packaging we need is an icon and a `<app>.desktop` file so that desktop environments recognize our app as such. The icon and the desktop file will be picked up by snapcraft and handled accordingly by putting them in a `snap/gui/` directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recognise

* **nodejs**: A JavaScript runtime, that will also provide the `npm` command we are going to use

```bash
sudo apt install curl build-essential libgconf2-4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libgconf2-4 is the only one not explained. I'm left wondering what is it for, so it might be better to explain all of them above.


```bash
npm install electron --save-dev --save-exact
npm install electron-builder --save-dev

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack Error: not found: make <- one missing dependency.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, two: make: g++: Command not found

Copy link
Contributor Author

@caldav caldav Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd, build-essential should have installed make and g++.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, apparently I missed that command. 😔

## Electron metadata (package.json)
Duration: 2:00

Now that we have a working app, we need to turn it into an executable file. To do this, we are going to use a dependency we installed earlier: electron-builder. To build the executable, it requires a `package.json` file containing some basic metadata.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little slow to read. What about:
Now that we have a working app, we are going to turn it into an executable file using a dependency we installed earlier: electron-builder.

}
```

As you can see, all entries are self-explicit. We have a name, a version, the location of our app, how to start the app using the `electron` command and instructions to build a linux executable without packaging (`dir` stands for `directory`).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's self-explanatory, not self-explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, missed this one, thanks

Then we need to provide the following information:

* **The command (or commands) to build the app**:
Since we are using electron-builder and simply calling `electron-builder` in the project will pick up details from our `package.json` file and generate an executable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something wrong in this sentence. Who will pick up the details?


### Let's recap

We have added general metadata to ensure our app appears correctly in stores and parts to ensure it bundles our executable and its dependencies in a confined package. But we are still missing one very important bit: the launcher.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a missing comma here, after "stores"?


## Launcher and desktop integration

To launch the app, the snap needs to know which command to run. This is done within an `apps` section in the `snapcraft.yaml`, where we are going to declare: the name of the app, the command to run and which access we want the app to be granted outside of the snap confinement.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a ":" after declare

```yaml
apps:
castlearena:
command: env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/app/castlearena

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This XDG_RUNTIME_DIR should probably be explained. I have no idea what it does there.


### Icon and desktop file

The last bit of packaging we need is an icon and a `<app>.desktop` file so that desktop environments recognize our app as such. The icon and the desktop file will be picked up by snapcraft and handled accordingly by putting them in a `snap/gui/` directory.
Copy link

@come-maiz come-maiz Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be "an <app>.desktop file", but maybe @kyrofa can confirm.

1. snapcraft pulls the source of each part
1. ...and downloads all the required dependencies
1. Each part is built following our instructions
1. Snapcraft creates a staging directory where the content of our snap is curated based on instructions and parts plugin declarations

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"based on instructions" sounds bad. Why don't you just drop "instructions"?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably call it the "stage directory", not staging.

1. ...and downloads all the required dependencies
1. Each part is built following our instructions
1. Snapcraft creates a staging directory where the content of our snap is curated based on instructions and parts plugin declarations
1. The staging directory is packed into a snap

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not completely accurate. The one that is packed is the prime directory.


`castlearena_0.1_amd64.snap`

Congrats, you made a snap!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^_^ so exciting!


```bash
sudo apt install curl build-essential libgconf2-4
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, no idea what this command is doing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for the awesome node snap! nodejs/installer#54
(leave your thumbs up in there :)

`snap try squashfs-root` will mount the directory as if it was an installed snap.
You can then run the snap and edit its content at the same time.
* Enter a shell with the same confinement as the snap to inspect its environment, paths, and see what it sees:
`snap run --shell <snap>`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be better as a link to a tutorial that explains each of them?

Copy link

@come-maiz come-maiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice work @caldav, thanks!

@caldav
Copy link
Contributor Author

caldav commented Nov 15, 2017

Thanks all!

@caldav caldav merged commit 1399068 into master Nov 15, 2017
@3DJetengine
Copy link

3DJetengine commented Nov 16, 2017

@caldav is there any chance - when you say:

  • Some command line experience required.

we could link to https://linuxjourney.com/ - command line as a ubu.one link or an ubuntu link ?

all of the links seem to remain in-house.

@caldav caldav deleted the packaging-website branch December 19, 2017 16:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants