Skip to content

Commit

Permalink
add jsdoc, eslint, remove www
Browse files Browse the repository at this point in the history
  • Loading branch information
Emile Nijssen committed Jun 23, 2022
1 parent cbfa134 commit f22f831
Show file tree
Hide file tree
Showing 168 changed files with 3,656 additions and 136,383 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "athom",
"ignorePatterns": [
"/examples/**"
]
}
32 changes: 32 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy Documentation To GitHub Pages

# v1.0.0
#
# This workflow runs `npm run build` and then syncs the `build` folder to GitHub Pages.

on:
push:
branches: [ production ]

jobs:
deploy:
name: Build & Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12'

# Build
- name: Build
run: npm run build

# Deploy
- name: Deploy To GitHub Pages
uses: peaceiris/[email protected]
with:
personal_token: ${{ secrets.HOMEY_GITHUB_ACTIONS_BOT_PERSONAL_ACCESS_TOKEN }}
publish_dir: ./build
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

# Optional secrets:
# - SSH_KEY: if `npm ci` needs to install private npm packages

# GitHub repo configuration:
# 1. If you have protected branches, go to Branches > edit protected branch > enable 'Require status checks to pass before
# merging' and select the 'ESLint' status check.

# Note: make sure to commit package-lock.json, this is needed for `npm ci`.

# Defines the trigger for this action (e.g. [pull_request, push])
# For more information see: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#about-workflow-events)
on:
push:
branches:
- master
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
# Checks out the current repository.
- uses: actions/checkout@v2

# Configures a Node.js environment.
- uses: actions/setup-node@v1
with:
node-version: '12'

# Set SSH key
- uses: webfactory/[email protected]
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
if: env.SSH_KEY != null
with:
ssh-private-key: ${{ env.SSH_KEY }}

# Run `npm ci` to re-create your local environment (make sure to commit your package-lock.json!).
# Finally run `npm run lint` (make sure you have defined a lint command in package.json e.g. "lint": "eslint .").
- run: npm ci
- run: npm run lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/build

# Added by Homey CLI
/.homeybuild/
14 changes: 8 additions & 6 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
for (const script of Object.values(scripts)) {
response[script.id] = {
...script,
code: undefined
code: undefined,
};
}

Expand All @@ -34,8 +34,8 @@ module.exports = {
lastExecuted: script.lastExecuted,
args,
}).finally(() => {
homey.app.updateScript({ id: script.id, lastExecuted: new Date() }).catch(() => {})
})
homey.app.updateScript({ id: script.id, lastExecuted: new Date() }).catch(() => {});
});

return {
success: true,
Expand All @@ -48,7 +48,7 @@ module.exports = {
message: err.message,
stack: err.stack,
},
}
};
}
},

Expand All @@ -58,7 +58,9 @@ module.exports = {
return homey.app.createScript({ name, code });
},

async updateScript({ homey, params, query, body = {} }) {
async updateScript({
homey, params, query, body = {},
}) {
const { id } = params;
const { name, code } = body;

Expand All @@ -70,4 +72,4 @@ module.exports = {
return homey.app.deleteScript({ id });
},

}
};
63 changes: 31 additions & 32 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = class HomeyScriptApp extends Homey.App {
await Promise.all(files.map(async filename => {
if (!filename.endsWith('.js')) return;

const id = 'example-' + filename.substring(0, filename.length - '.js'.length);
const id = `example-${filename.substring(0, filename.length - '.js'.length)}`;
const filepath = path.join(__dirname, 'examples', filename);
const code = await fs.readFile(filepath, 'utf8');

Expand Down Expand Up @@ -93,7 +93,6 @@ module.exports = class HomeyScriptApp extends Homey.App {
}
}


// Register Flow Cards
this.homey.flow.getConditionCard('run')
.registerRunListener(async ({ script }) => {
Expand Down Expand Up @@ -176,17 +175,15 @@ module.exports = class HomeyScriptApp extends Homey.App {

async getHomeyAPI() {
const api = new HomeyAPI({
localUrl: this.localURL,
baseUrl: this.localURL,
token: this.sessionToken,
apiVersion: 2,
online: true
},
() => {
// called by HomeyAPI on 401 requests
api.setToken(this.sessionToken);
}
);
localUrl: this.localURL,
baseUrl: this.localURL,
token: this.sessionToken,
apiVersion: 2,
online: true,
}, () => {
// called by HomeyAPI on 401 requests
api.setToken(this.sessionToken);
});

return api;
}
Expand Down Expand Up @@ -237,8 +234,6 @@ module.exports = class HomeyScriptApp extends Homey.App {

this.tokens[id].value = value;
this.homey.settings.set('tokens', this.tokens);

return;
}
}

Expand Down Expand Up @@ -305,21 +300,21 @@ module.exports = class HomeyScriptApp extends Homey.App {
Homey: homeyAPI,

// Logging
log: log,
log,
console: {
log: log,
log,
error: log,
info: log,
},

// Shortcuts
say: async (text) => await homeyAPI.speechOutput.say({ text }),
tag: async (id, value) => await this.setToken({ id, value }),
wait: async (delay) => new Promise(resolve => setTimeout(resolve, delay)),
say: async text => homeyAPI.speechOutput.say({ text }),
tag: async (id, value) => this.setToken({ id, value }),
wait: async delay => new Promise(resolve => setTimeout(resolve, delay)),

// Cross-Script Settings
global: {
get: (key) => this.homey.settings.get(`homeyscript-${key}`),
get: key => this.homey.settings.get(`homeyscript-${key}`),
set: (key, value) => this.homey.settings.set(`homeyscript-${key}`, value),
keys: () => this.homey.settings.getKeys()
.filter(key => key.startsWith('homeyscript-'))
Expand All @@ -342,13 +337,13 @@ module.exports = class HomeyScriptApp extends Homey.App {
const sandbox = new vm.Script(`Promise.resolve().then(async () => {\n${code}\n});`, {
filename: `${name}.js`,
lineOffset: -1,
columnOffset: 0
columnOffset: 0,
});

const runPromise = sandbox.runInNewContext(context, {
displayErrors: true,
timeout: this.constructor.RUN_TIMEOUT,
microtaskMode: 'afterEvaluate' // from Node 14 should properly timeout async script
microtaskMode: 'afterEvaluate', // from Node 14 should properly timeout async script
});

const result = await runPromise;
Expand All @@ -360,28 +355,32 @@ module.exports = class HomeyScriptApp extends Homey.App {
log('⚠️', err.stack);
// Create a new Error because an Error from the sandbox behaves differently
const error = new Error(err.message);
error.stack = error.stack;
error.stack = err.stack;
throw error;
} finally {
homeyAPI && homeyAPI.destroy();
if (homeyAPI) {
homeyAPI.destroy();
}
}
}

async createScript({ name, code }) {
const newScript = {
id: uuid.v4(),
name: name,
code: code,
lastExecuted: null
}
name,
code,
lastExecuted: null,
};

this.scripts[newScript.id] = newScript
this.scripts[newScript.id] = newScript;
this.homey.settings.set('scripts', this.scripts);

return newScript;
}

async updateScript({ id, name, code, lastExecuted }) {
async updateScript({
id, name, code, lastExecuted,
}) {
this.scripts[id] = {
...this.scripts[id],
};
Expand All @@ -408,4 +407,4 @@ module.exports = class HomeyScriptApp extends Homey.App {
this.homey.settings.set('scripts', this.scripts);
}

}
};
17 changes: 17 additions & 0 deletions docs/jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"opts": {
"mainpagetitle": "HomeyScript",
"template": "./node_modules/homey-jsdoc-template",
"simpleAnalyticsHost": "sa.athom.com",
"destination": "./build"
},
"source": {
"include": [
"./README.md",
"./"
]
},
"plugins": [
"plugins/markdown"
]
}
Loading

0 comments on commit f22f831

Please sign in to comment.