Skip to content

Commit

Permalink
Added "target" and "defaultBranch" answers to support the portal crea…
Browse files Browse the repository at this point in the history
…tor (#818)
  • Loading branch information
UncleSamSwiss authored Sep 13, 2021
1 parent 0a83ec3 commit dc89fc2
Show file tree
Hide file tree
Showing 44 changed files with 412 additions and 96 deletions.
4 changes: 4 additions & 0 deletions .github/create_templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ async function generateTemplates(
/* Define the desired templates here */

const baseAnswers = {
cli: true,
target: "directory",
adapterName: "template",
description: "Template for adapter development",
authorName: "Author",
Expand All @@ -35,6 +37,8 @@ const baseAnswers = {
dependabot: "yes",
license: "MIT License" as any,
releaseScript: "yes",
gitCommit: "no",
defaultBranch: "main",
} as Answers;

const adapterAnswers: Answers = {
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* (AlCalzone) Remove `.npmignore` blacklist, use `files` whitelist in `package.json` instead (#816) · [Migration guide](docs/updates/20210906_files_whitelist.md)
* (UncleSamSwiss) Updated alt texts of ioBroker badges in readme (#722)
* (AlCalzone) Shared testing workflows (#822) · [Migration guide](docs/updates/20210913_shared_testing_workflows.md)
* (UncleSamSwiss) Readme for adapter created using portal reflects the fact that the repository already exists (#788)
* (UncleSamSwiss) The default branch can now be chosen, default is "main", but it is possible to change to "master" (#631)

## 1.34.1 (2021-07-07)
* (UncleSamSwiss) Fix missing `common.main` in `io-package.json` (#778)
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ Command line utility to quickly create a new adapter or VIS widget for [ioBroker
![node](https://img.shields.io/node/v/@iobroker/create-adapter.svg)
![npm](https://img.shields.io/npm/v/@iobroker/create-adapter.svg)
](https://www.npmjs.com/package/@iobroker/create-adapter)
[
![Build Status](https://img.shields.io/travis/ioBroker/create-adapter/master.svg)
](https://travis-ci.org/ioBroker/create-adapter)
![Test and Release](https://github.com/ioBroker/create-adapter/workflows/Test%20and%20Release/badge.svg)
![License](https://img.shields.io/npm/l/@iobroker/create-adapter.svg)
[
![Changelog](https://img.shields.io/badge/read-Changelog-blue.svg)
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const creatorOptions = {

/** Asks a series of questions on the CLI */
async function ask(): Promise<Answers> {
let answers: Record<string, any> = { cli: true };
let answers: Record<string, any> = { cli: true, target: "directory" };
let migrationContext: MigrationContextBase | undefined;

if (!!argv.replay) {
Expand Down Expand Up @@ -306,7 +306,7 @@ async function setupProject_CLI(
? `https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}`
: `[email protected]:${answers.authorGithub}/ioBroker.${answers.adapterName}.git`;
const gitCommandArgs = [
["init"],
["init", "-b", answers.defaultBranch || "main"],
["add", "."],
["commit", "-m", "Initial commit"],
["remote", "add", "origin", gitUrl],
Expand Down
27 changes: 27 additions & 0 deletions src/lib/core/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,28 @@ export const questionGroups: QuestionGroup[] = [
choices: ["yes", "no"],
migrate: () => "no",
},
{
condition: { name: "cli", value: true },
type: "select",
name: "defaultBranch",
label: "Git Default Branch",
expert: true,
message: "How should your default Git branch be called?",
initial: "main",
choices: [
{
message: "main",
},
{
message: "master",
hint: "(deprecated)",
},
],
migrate: (ctx) =>
ctx.ioPackageJson.common?.extIcon?.match(/\/main\/admin\//i)
? "main"
: "master",
},
{
type: "select",
name: "license",
Expand Down Expand Up @@ -882,6 +904,10 @@ export interface UploadedIcon {
}

export interface Answers {
/** false is used in the portal */
cli: boolean;
/** "github" and "zip" are used in the portal */
target: "directory" | "github" | "zip";
adapterName: string;
description?: string;
keywords?: string[];
Expand Down Expand Up @@ -914,6 +940,7 @@ export interface Answers {
es6class?: "yes" | "no";
gitRemoteProtocol: "HTTPS" | "SSH";
gitCommit?: "yes" | "no";
defaultBranch?: "main" | "master";
dependabot?: "yes" | "no";
startMode?: "daemon" | "schedule" | "subscribe" | "once" | "none";
scheduleStartOnChange?: "yes" | "no";
Expand Down
27 changes: 24 additions & 3 deletions templates/README.md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export = (answers => {
const useReact =
answers.adminReact === "yes" || answers.tabReact === "yes";
const autoInitGit = answers.gitCommit === "yes";
const defaultBranch = answers.defaultBranch || "main";
const useReleaseScript = answers.releaseScript === "yes";
const useDevServer = answers.devServer === "yes";
const useDependabot = answers.dependabot === "yes";
const isGitHub = answers.target === "github";

const npmScripts: Record<string, string> = {};
if (useReact) {
Expand Down Expand Up @@ -80,11 +82,17 @@ This section is intended for the developer. It can be deleted later
### Getting started
You are almost done, only a few steps left:
1. Create a new repository on GitHub with the name \`ioBroker.${answers.adapterName}\`
${isGitHub ?
(`1. Clone the repository from GitHub to a directory on your PC:
\`\`\`bash
git clone https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}
\`\`\`
`) :
(`1. Create a new repository on GitHub with the name \`ioBroker.${answers.adapterName}\`
${autoInitGit ? "" : (
`1. Initialize the current folder as a new git repository:
\`\`\`bash
git init
git init -b ${defaultBranch}
git add .
git commit -m "Initial commit"
\`\`\`
Expand All @@ -95,11 +103,12 @@ ${autoInitGit ? "" : (
`)}
1. Push all files to the GitHub repo${autoInitGit ? ". The creator has already set up the local repository for you" : ""}:
\`\`\`bash
git push origin master
git push origin ${defaultBranch}
\`\`\`
${useDependabot ? (
`1. Add a new secret under https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/settings/secrets. It must be named \`AUTO_MERGE_TOKEN\` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens.
`) : ""}
`)}
1. Head over to ${
isAdapter ? (
useTypeScript ? "[src/main.ts](src/main.ts)"
Expand Down Expand Up @@ -157,6 +166,18 @@ dev-server watch
The ioBroker.admin interface will then be available at http://localhost:${answers.devServerPort}/
Please refer to the [\`dev-server\` documentation](https://github.com/ioBroker/dev-server#command-line) for more details.
` : isGitHub ? `
### Test the adapter manually with dev-server
Please use \`dev-server\` to test and debug your adapter.
You may install and start \`dev-server\` by calling from your dev directory:
\`\`\`bash
npm install --global @iobroker/dev-server
dev-server setup
dev-server watch
\`\`\`
Please refer to the [\`dev-server\` documentation](https://github.com/ioBroker/dev-server#readme) for more details.
` : `
### Test the adapter manually on a local ioBroker installation
In order to install the adapter locally without publishing, the following steps are recommended:
Expand Down
78 changes: 44 additions & 34 deletions templates/_github/workflows/test-and-release.yml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ const templateFunction: TemplateFunction = answers => {
...(useTypeScript ? ["build/"] : []),
...(useReact ? ["admin/build/"] : []),
];
const useReleaseScript = answers.releaseScript === "yes";
const isGitHub = answers.target === "github";

const latestNodeVersion = "14.x";
const adapterTestVersions = ["12.x", "14.x", "16.x"];
const adapterTestOS = ["ubuntu-latest", "windows-latest", "macos-latest"];

const adapterName = answers.adapterName;

const deploy = useReleaseScript && isGitHub;
const escapeDeploy =
deploy ?
(input: string) => input :
(input: string) => input.replace(/^/gm, '#');

const template = `
name: Test and Release
Expand Down Expand Up @@ -69,44 +77,46 @@ ${isAdapter ? (
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
# install-command: 'npm install'${needsBuild ? (`
build: true`) : ""}
`) : ""}
`) : ""}${deploy ? "" : (`
# TODO: To enable automatic npm releases, create a token on npmjs.org
# Enter this token as a GitHub secret (with name NPM_TOKEN) in the repository options
# Then uncomment the following block:
`)}
${escapeDeploy(
` # Deploys the final package to NPM
deploy:
needs: [check-and-lint${isAdapter ? ", adapter-tests" : ""}]
# Trigger this step only when a commit on any branch is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: ioBroker/testing-action-deploy@v1
with:
node-version: '${latestNodeVersion}'
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
# install-command: 'npm install'${needsBuild ? (`
build: true`) : ""}
npm-token: \${{ secrets.NPM_TOKEN }}
github-token: \${{ secrets.GITHUB_TOKEN }}
# # Deploys the final package to NPM
# deploy:
# needs: [check-and-lint${isAdapter ? ", adapter-tests" : ""}]
#
# # Trigger this step only when a commit on any branch is tagged with a version number
# if: |
# contains(github.event.head_commit.message, '[skip ci]') == false &&
# github.event_name == 'push' &&
# startsWith(github.ref, 'refs/tags/v')
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: ioBroker/testing-action-deploy@v1
# with:
# node-version: '${latestNodeVersion}'
# # Uncomment the following line if your adapter cannot be installed using 'npm ci'
# # install-command: 'npm install'${needsBuild ? (`
# build: true`) : ""}
# npm-token: \${{ secrets.NPM_TOKEN }}
# github-token: \${{ secrets.GITHUB_TOKEN }}
#
# # When using Sentry for error reporting, Sentry can be informed about new releases
# # To enable create a API-Token in Sentry (User settings, API keys)
# # Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options
# # Then uncomment and customize the following block:
# sentry-token: \${{ secrets.SENTRY_AUTH_TOKEN }}
# sentry-project: "iobroker-${adapterName}"
# sentry-version-prefix: "iobroker.${adapterName}"${needsBuild ? (`
# sentry-sourcemap-paths: "${sourcemapPaths.join(" ")}"`) : ""}
# # If your sentry project is linked to a GitHub repository, you can enable the following option
# # sentry-github-integration: true
`; return template.trimLeft();
# When using Sentry for error reporting, Sentry can be informed about new releases
# To enable create a API-Token in Sentry (User settings, API keys)
# Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options
# Then uncomment and customize the following block:
sentry-token: \${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-project: "iobroker-${adapterName}"
sentry-version-prefix: "iobroker.${adapterName}"${needsBuild ? (`
sentry-sourcemap-paths: "${sourcemapPaths.join(" ")}"`) : ""}
# If your sentry project is linked to a GitHub repository, you can enable the following option
# sentry-github-integration: true`)}
`;
return template.trimLeft();
};

templateFunction.customPath = ".github/workflows/test-and-release.yml";
Expand Down
5 changes: 3 additions & 2 deletions templates/io-package.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export = (async answers => {
const useTypeScript = answers.language === "TypeScript";
const supportCustom = answers.adminFeatures && answers.adminFeatures.indexOf("custom") > -1;
const supportTab = answers.adminFeatures && answers.adminFeatures.indexOf("tab") > -1;
const defaultBranch = answers.defaultBranch || "main";

const languages = ["en", "de", "ru", "pt", "nl", "fr", "it", "es", "pl", "zh-cn"];

Expand Down Expand Up @@ -66,8 +67,8 @@ export = (async answers => {
"main": "${useTypeScript ? "build/" : ""}main.js",
"icon": "${getIconName(answers)}",
"enabled": true,
"extIcon": "https://raw.githubusercontent.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/master/admin/${getIconName(answers)}",
"readme": "https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/blob/master/README.md",
"extIcon": "https://raw.githubusercontent.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/${defaultBranch}/admin/${getIconName(answers)}",
"readme": "https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/blob/${defaultBranch}/README.md",
"loglevel": "info",
${isWidget ? (`
"restartAdapters": ["vis"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"cli": true,
"target": "directory",
"adapterName": "test-adapter",
"title": "Is used to test the creator",
"startMode": "daemon",
Expand Down Expand Up @@ -26,6 +28,8 @@
"authorEmail": "[email protected]",
"gitRemoteProtocol": "HTTPS",
"dependabot": "yes",
"gitCommit": "no",
"defaultBranch": "main",
"license": "Apache License 2.0",
"creatorVersion": "1.34.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You are almost done, only a few steps left:
1. Create a new repository on GitHub with the name `ioBroker.test-adapter`
1. Initialize the current folder as a new git repository:
```bash
git init
git init -b main
git add .
git commit -m "Initial commit"
```
Expand All @@ -35,7 +35,7 @@ You are almost done, only a few steps left:

1. Push all files to the GitHub repo:
```bash
git push origin master
git push origin main
```
1. Add a new secret under https://github.com/AlCalzone/ioBroker.test-adapter/settings/secrets. It must be named `AUTO_MERGE_TOKEN` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"main": "main.js",
"icon": "test-adapter.png",
"enabled": true,
"extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/master/admin/test-adapter.png",
"readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/master/README.md",
"extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/main/admin/test-adapter.png",
"readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/main/README.md",
"loglevel": "info",
"mode": "daemon",
"type": "general",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"cli": true,
"target": "directory",
"adapterName": "test-adapter",
"title": "Is used to test the creator",
"startMode": "daemon",
Expand Down Expand Up @@ -26,6 +28,8 @@
"authorEmail": "[email protected]",
"gitRemoteProtocol": "HTTPS",
"dependabot": "yes",
"gitCommit": "no",
"defaultBranch": "main",
"license": "Apache License 2.0",
"creatorVersion": "1.34.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You are almost done, only a few steps left:
1. Create a new repository on GitHub with the name `ioBroker.test-adapter`
1. Initialize the current folder as a new git repository:
```bash
git init
git init -b main
git add .
git commit -m "Initial commit"
```
Expand All @@ -35,7 +35,7 @@ You are almost done, only a few steps left:

1. Push all files to the GitHub repo:
```bash
git push origin master
git push origin main
```
1. Add a new secret under https://github.com/AlCalzone/ioBroker.test-adapter/settings/secrets. It must be named `AUTO_MERGE_TOKEN` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"main": "main.js",
"icon": "test-adapter.png",
"enabled": true,
"extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/master/admin/test-adapter.png",
"readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/master/README.md",
"extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/main/admin/test-adapter.png",
"readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/main/README.md",
"loglevel": "info",
"mode": "daemon",
"type": "general",
Expand Down
4 changes: 4 additions & 0 deletions test/baselines/adapter_JS_React/.create-adapter.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"cli": true,
"target": "directory",
"adapterName": "test-adapter",
"title": "Is used to test the creator",
"startMode": "daemon",
Expand All @@ -25,6 +27,8 @@
"authorEmail": "[email protected]",
"gitRemoteProtocol": "HTTPS",
"dependabot": "yes",
"gitCommit": "no",
"defaultBranch": "main",
"license": "MIT License",
"creatorVersion": "1.34.0"
}
Loading

0 comments on commit dc89fc2

Please sign in to comment.