Skip to content

Commit

Permalink
chore: add linting and fmt scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-MikeS authored Jul 19, 2021
1 parent 3ea580d commit db5cf4f
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 477 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugin-examples
dist
docs
node_modules
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line no-undef
module.exports = {
extends: '@ionic/eslint-config/recommended',
};
27 changes: 16 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- main
- "**"
pull_request:
branches:
- "**"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
lint:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
working-directory: ./
steps:
- uses: actions/setup-node@v1
with:
node-version: 14.x
- uses: actions/checkout@v2
- run: npm install
- run: npm run lint

# Steps represent a sequence of tasks that will be executed as part of the job
build:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
working-directory: ./
steps:
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: actions/checkout@v2
- run: npm install
- run: npm run build
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugin-examples/**
docs/**
.github/**
.husky/**
dist/**
node_modules/**
*.md
*.sh
package.json
package-lock.json
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line no-undef
module.exports = {
...require('@ionic/prettier-config'),
};
38 changes: 21 additions & 17 deletions build-cli_scripts.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
require('esbuild').build({
entryPoints: ['src/cli-scripts/index.ts'],
bundle: true,
outfile: 'dist/cli-scripts/cap-scripts.js',
platform: 'node',
target: 'node14',
minify: true,
external: [
'child_process',
'fs',
'path',
'fs-extra',
'crypto',
'chalk',
'ora'
]
}).catch(() => process.exit(1))
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
require('esbuild')
.build({
entryPoints: ['src/cli-scripts/index.ts'],
bundle: true,
outfile: 'dist/cli-scripts/cap-scripts.js',
platform: 'node',
target: 'node14',
minify: true,
external: [
'child_process',
'fs',
'path',
'fs-extra',
'crypto',
'chalk',
'ora',
],
})
.catch(() => process.exit(1));
28 changes: 13 additions & 15 deletions build-core.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require('esbuild').build({
entryPoints: ['src/electron/index.ts'],
bundle: true,
outfile: 'dist/core/index.js',
platform: 'node',
target: 'node14',
minify: true,
external: [
'electron',
'fs',
'path',
'mime-types',
'events',
]
}).catch(() => process.exit(1))
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
require('esbuild')
.build({
entryPoints: ['src/electron/index.ts'],
bundle: true,
outfile: 'dist/core/index.js',
platform: 'node',
target: 'node14',
minify: true,
external: ['electron', 'fs', 'path', 'mime-types', 'events'],
})
.catch(() => process.exit(1));
24 changes: 13 additions & 11 deletions changelog.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"use strict";
const config = require("conventional-changelog-conventionalcommits");
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict';
const config = require('conventional-changelog-conventionalcommits');

module.exports = config({
types: [
{ type: "feat", section: "Features" },
{ type: "fix", section: "Bug Fixes" },
{ type: "chore", section: "Chores" },
{ type: "docs", section: "Documentation" },
{ type: "style", hidden: true },
{ type: "refactor", hidden: true },
{ type: "perf", hidden: true },
{ type: "test", hidden: true },
{ type: "changelog", hidden: true },
{ type: 'feat', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'chore', section: 'Chores' },
{ type: 'docs', section: 'Documentation' },
{ type: 'style', hidden: true },
{ type: 'refactor', hidden: true },
{ type: 'perf', hidden: true },
{ type: 'test', hidden: true },
{ type: 'changelog', hidden: true },
],
});
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"main": "dist/core/index.js",
"typings": "dist/core/index.d.ts",
"scripts": {
"lint": "npm run eslint && npm run prettier -- --check",
"fmt": "npm run eslint -- --fix && npm run prettier -- --write",
"shipit": "npm run build && np --no-tests --any-branch && npm run generate-changelog && npm run deploy-changelog",
"clean": "rimraf ./dist",
"build": "npm run clean && npm run build-platform && npm run build-cli-scripts",
Expand All @@ -17,23 +19,24 @@
"build-platform": "node ./build-core.js",
"generate-changelog": "conventional-changelog -o CHANGELOG.md -r 0 --config changelog.config.js",
"deploy-changelog": "bash ./deployChangeLog.sh",
"prepare": "husky install",
"pretty-quick": "pretty-quick"
"prettier": "prettier \"**/*.{css,html,js,mjs,ts}\"",
"eslint": "eslint . --ext ts"
},
"license": "MIT",
"author": "IT-MikeS",
"devDependencies": {
"@ionic/eslint-config": "^0.3.0",
"@ionic/prettier-config": "^1.0.1",
"@types/events": "~3.0.0",
"@types/fs-extra": "~9.0.11",
"@types/node": "~14.17.4",
"conventional-changelog-cli": "~2.1.1",
"conventional-changelog-conventionalcommits": "~4.6.0",
"electron": "~13.1.6",
"esbuild": "~0.12.15",
"husky": "~7.0.1",
"eslint": "~7.27.0",
"np": "~7.5.0",
"prettier": "~2.3.2",
"pretty-quick": "~3.1.1",
"prettier": "2.3.2",
"rimraf": "~3.0.2",
"tslib": "~2.3.0",
"typescript": "~4.3.5"
Expand Down
109 changes: 53 additions & 56 deletions src/cli-scripts/add.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
import { existsSync, renameSync } from "fs";
import { copySync } from "fs-extra";
import { join } from "path";
import { readJSON, runExec, writePrettyJSON } from "./common";
import { existsSync, renameSync } from 'fs';
import { copySync } from 'fs-extra';
import { join } from 'path';

export async function doAdd() {
try {
//console.log(process.env.CAPACITOR_ROOT_DIR);
//console.log(process.env.CAPACITOR_WEB_DIR);
//console.log(process.env.CAPACITOR_CONFIG);
const usersProjectDir = process.env.CAPACITOR_ROOT_DIR!;
const capacitorElectronNodeModuleTemplateDir = join(
usersProjectDir,
"node_modules",
"@capacitor-community",
"electron",
"template"
);
const destDir = join(usersProjectDir, "electron");
let usersProjectCapConfigFile: string | undefined = undefined;
let configFileName: string | undefined = undefined;
import { readJSON, runExec, writePrettyJSON } from './common';

const configFileOptions = {
ts: join(usersProjectDir, "capacitor.config.ts"),
js: join(usersProjectDir, "capacitor.config.js"),
json: join(usersProjectDir, "capacitor.config.json"),
}
if (existsSync(configFileOptions.ts)) {
usersProjectCapConfigFile = configFileOptions.ts
configFileName = "capacitor.config.ts"
} else if (existsSync(configFileOptions.js)) {
usersProjectCapConfigFile = configFileOptions.js
configFileName = "capacitor.config.js"
} else {
usersProjectCapConfigFile = configFileOptions.json
configFileName = "capacitor.config.json"
}
export async function doAdd(): Promise<void> {
//console.log(process.env.CAPACITOR_ROOT_DIR);
//console.log(process.env.CAPACITOR_WEB_DIR);
//console.log(process.env.CAPACITOR_CONFIG);
const usersProjectDir = process.env.CAPACITOR_ROOT_DIR;
const capacitorElectronNodeModuleTemplateDir = join(
usersProjectDir,
'node_modules',
'@capacitor-community',
'electron',
'template',
);
const destDir = join(usersProjectDir, 'electron');
let usersProjectCapConfigFile: string | undefined = undefined;
let configFileName: string | undefined = undefined;

const configData = JSON.parse(process.env.CAPACITOR_CONFIG!);
const configFileOptions = {
ts: join(usersProjectDir, 'capacitor.config.ts'),
js: join(usersProjectDir, 'capacitor.config.js'),
json: join(usersProjectDir, 'capacitor.config.json'),
};
if (existsSync(configFileOptions.ts)) {
usersProjectCapConfigFile = configFileOptions.ts;
configFileName = 'capacitor.config.ts';
} else if (existsSync(configFileOptions.js)) {
usersProjectCapConfigFile = configFileOptions.js;
configFileName = 'capacitor.config.js';
} else {
usersProjectCapConfigFile = configFileOptions.json;
configFileName = 'capacitor.config.json';
}

const configData = JSON.parse(process.env.CAPACITOR_CONFIG);

const builtWebAppDir = process.env.CAPACITOR_WEB_DIR!;
const builtWebAppDir = process.env.CAPACITOR_WEB_DIR;

if (!existsSync(destDir)) {
copySync(capacitorElectronNodeModuleTemplateDir, destDir);
copySync(usersProjectCapConfigFile, join(destDir, configFileName));
// writeFileSync(
// join(destDir, "capacitor.config.json"),
// JSON.stringify(configData)
// );
renameSync(join(destDir, "gitignore"), join(destDir, ".gitignore"));
copySync(builtWebAppDir, join(destDir, "app"));
if (!existsSync(destDir)) {
copySync(capacitorElectronNodeModuleTemplateDir, destDir);
copySync(usersProjectCapConfigFile, join(destDir, configFileName));
// writeFileSync(
// join(destDir, "capacitor.config.json"),
// JSON.stringify(configData)
// );
renameSync(join(destDir, 'gitignore'), join(destDir, '.gitignore'));
copySync(builtWebAppDir, join(destDir, 'app'));

const appName: string = configData.appName!;
const electronPackageJson = readJSON(join(destDir, "package.json"));
electronPackageJson.name = appName;
writePrettyJSON(join(destDir, "package.json"), electronPackageJson);
const appName: string = configData.appName;
const electronPackageJson = readJSON(join(destDir, 'package.json'));
electronPackageJson.name = appName;
writePrettyJSON(join(destDir, 'package.json'), electronPackageJson);

await runExec(`cd ${destDir} && npm i`);
} else {
throw new Error("Electron platform already exists.");
}
} catch (e) {
throw e;
await runExec(`cd ${destDir} && npm i`);
} else {
throw new Error('Electron platform already exists.');
}
}
Loading

0 comments on commit db5cf4f

Please sign in to comment.