Skip to content

Commit

Permalink
feat: initial capacitor plugin integration
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonos committed Dec 6, 2023
1 parent 6e74bc8 commit 99ed858
Show file tree
Hide file tree
Showing 166 changed files with 21,649 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
36 changes: 36 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Continuous deployment
on:
push:
branches:
- main

permissions:
contents: read # for checkout

jobs:
cd:
runs-on: macos-12
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
40 changes: 40 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Continuous integration
on:
push:
branches:
- dev

env:
JAVA_VERSION: 17

jobs:
ci:
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Set up Xcode
run: sudo xcode-select --switch /Applications/Xcode_14.2.app

- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'zulu'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Verify
run: yarn verify
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
dist
example/www
example/ios
example/android
24 changes: 24 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
{
"path": "@semantic-release/npm",
"npmPublish": true,
"pkgRoot": "."
},
{
"path": "@semantic-release/git",
"assets": [
"package.json",
"yarn.lock",
"CHANGELOG.md"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
}
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.8
21 changes: 21 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
excluded:
- 'node_modules'
- 'ios/Pods'

opt_in_rules:
- 'implicitly_unwrapped_optional'
- 'file_name_no_space'
- 'force_unwrapping'
- 'function_default_parameter_at_end'
- 'lower_acl_than_parent'
- 'modifier_order'
- 'overridden_super_call'
- 'unowned_variable_capture'
- 'unused_import'

line_length:
warning: 150
ignores_function_declarations: true
ignores_comments: true
ignores_interpolated_strings: true
ignores_urls: true
15 changes: 15 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"recommendations": [
"adam-bender.commit-message-editor",
"angular.ng-template",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"gruntfuggly.todo-tree",
"ionic.ionic",
"streetsidesoftware.code-spell-checker",
"vscjava.vscode-java-pack",
"mpotthoff.vscode-android-webview-debug",
"nisargjhaveri.ios-debug",
"vknabel.vscode-swiftformat"
]
}
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "android-webview",
"request": "attach",
"name": "Attach to Android WebView",
"application": "com.example.plugin.nordicdfu",
"webRoot": "${workspaceFolder}/example"
}
]
}
33 changes: 33 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// General editor settings
"editor.formatOnSave": true,
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.eol": "\n",
"files.insertFinalNewline": true,
"terminal.integrated.scrollback": 10000,

// Todo tree settings
"todo-tree.general.tags": ["BUG", "HACK", "FIXME", "TODO", "INFO"],
"todo-tree.highlights.defaultHighlight": {
"type": "tag-and-comment",
"foreground": "#000000"
},
"todo-tree.highlights.customHighlight": {
"TODO": { "background": "#FFFF00" },
"FIXME": { "background": "#FF0000" },
"INFO": { "background": "#FFA500" }
},
"todo-tree.regex.regex": "(//|#|<!--|;|/\\*|\\*|/\\*\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)",

// Prettier settings
"prettier.singleQuote": true,
"prettier.printWidth": 120,

// Code spell checker ignored words
"cSpell.words": ["Bootloader", "Buttonless", "Softdevice"],
"[swift]": {
"editor.defaultFormatter": "vknabel.vscode-swiftformat"
}
}
124 changes: 123 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,125 @@
# Contributing

TODO
This guide provides instructions for contributing to this Capacitor plugin.

## Developing

### Requirements

#### Android studio

Download and install [Android studio](https://developer.android.com/studio). The code has been developed using `Android Studio Giraffe | 2022.3.1 Patch 3`

#### Xcode

Download and install Xcode from the App Store. The code has been developed using `Xcode version 15.0.1 (15A507)``

### Recommend set up:

It is recommended to use `brew`, `rbenv`, `jenv` and `nvm` for the set up. The used versions for ruby, java and node can be found below.

#### brew:

```shell
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/robson/.zprofile
```

#### rbenv:

```shell
brew install rbenv ruby-build
```

#### jenv:

```shell
brew install jenv
```

#### nvm

```shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

```

#### Sample .zshrc

Your `~/.zshrc` should look more or less like this the following:

```shell
# rbenv
eval "$(rbenv init - zsh)"

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

# android
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator
```

#### Dependency version

ruby:

```shell
rbenv install 2.7.8
```

java:

```shell
brew install openjdk@17
jenv add /usr/local/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home # path to java installation from the above

```

node:

```shell
nvm install 18
```

node global packages:

```
yarn global add @ionic/cli @angular/cli
```

### Installation

- Fork and clone the repo
- Install the dependencies: `yarn`

## Scripts

#### `npm run build`

Build the plugin web assets and generate plugin API documentation using [`@capacitor/docgen`](https://github.com/ionic-team/capacitor-docgen).

It will compile the TypeScript code from `src/` into ESM JavaScript in `dist/esm/`. These files are used in apps with bundlers when your plugin is imported.

Then, Rollup will bundle the code into a single file at `dist/plugin.js`. This file is used in apps without bundlers by including it as a script in `index.html`.

#### `npm run verify`

Build and validate the android native project.

This is useful to run in CI to verify that the plugin builds for Android platform.

#### `npm run lint` / `npm run fmt`

Check formatting and code quality, autoformat/autofix if possible.

This template is integrated with ESLint, Prettier. Using these tool is completely optional, but the [Capacitor Community](https://github.com/capacitor-community/) strives to have consistent code style and structure for easier cooperation.
18 changes: 18 additions & 0 deletions CapacitorCommunityNordicDfu.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'CapacitorCommunityNordicDfu'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
s.dependency 'iOSDFULibrary', '~> 4.13.0'
end
Loading

0 comments on commit 99ed858

Please sign in to comment.