From 6e6cecdb3b5397fea98375552ccd27e0ef38bf8c Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 09:56:29 -0500 Subject: [PATCH 1/9] init work for create command --- lib/cli.js | 5 ++-- lib/commands/create.js | 54 ++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 lib/commands/create.js diff --git a/lib/cli.js b/lib/cli.js index 71d2710..ea23bde 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -2,6 +2,7 @@ const yargs = require('yargs/yargs') const dotenv = require('dotenv') const path = require('path') +const initStatusboard = require('./commands/create') const SHARED_OPTIONS = { db: { @@ -81,8 +82,8 @@ module.exports = (create, builder, argv) => { let cli = yargs() - .command('create', 'Create a StatusBoard', {}, async (argv) => { - console.log('Coming soon!') + .command('create [directory]', 'Create a StatusBoard', {}, async (argv) => { + await initStatusboard(argv) }) .command('build', 'Index and build board', SHARED_OPTIONS, async (argv) => { diff --git a/lib/commands/create.js b/lib/commands/create.js new file mode 100644 index 0000000..6f726ab --- /dev/null +++ b/lib/commands/create.js @@ -0,0 +1,54 @@ +const inquirer = require('inquirer') +const path = require('node:path') +const createPackageJson = require('create-package-json') + +async function create (opts) { + const { directory } = opts + let projectPath = directory + + if (!projectPath) { + const res = await inquirer.prompt([ + { + type: 'input', + name: 'path', + message: 'Where would you like to create your project?', + default: 'statusboard' + } + ]) + + projectPath = res.path.trim() + } + + const appPath = path.resolve(projectPath) + let projectName = path.basename(appPath) + + const pkg = await createPackageJson( + { + name: projectName, + description: '"A dashboard for project status', + version: '1.0.0', + dependencies: ['@pkgjs/statusboard'], + author: null, + keywords: null, + repository: null, + type: 'commonjs', + private: true, + cwd: appPath, + license: 'MIT', + main: 'config.js', + devDependencies: null, + scrips: { + build: 'statusboard build -C ./config', + buildsite: 'npm run clean && statusboard site -C ./config', + buildindex: 'statusboard index -C ./config', + clean: 'rm -rf build/css build/js' + } + }, + {} + ) + + console.log(pkg) + console.log(projectPath, projectName) +} + +module.exports = create diff --git a/package.json b/package.json index f54aed5..e750510 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "@wesleytodd/buildjs": "0.0.8", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", "cptmpl": "0.0.4", + "create-package-json": "^1.1.0", "dotenv": "^8.0.0", "es5-lit-element": "^2.2.1", "express": "^4.17.1", From 3c300e502187f0f237a84fcb0b82dc3e4f44b2b3 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 10:42:02 -0500 Subject: [PATCH 2/9] feat: add prompts --- lib/commands/create.js | 113 +++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 39 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index 6f726ab..879f2a2 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -4,51 +4,86 @@ const createPackageJson = require('create-package-json') async function create (opts) { const { directory } = opts - let projectPath = directory - - if (!projectPath) { - const res = await inquirer.prompt([ - { - type: 'input', - name: 'path', - message: 'Where would you like to create your project?', - default: 'statusboard' - } - ]) - - projectPath = res.path.trim() - } - const appPath = path.resolve(projectPath) - let projectName = path.basename(appPath) + const config = { + path: directory, + name: undefined, + labels: [], + orgs: [], + projects: [], + githubActions: false + } - const pkg = await createPackageJson( + const answers = await inquirer.prompt([ + { + type: 'input', + name: 'path', + message: 'Where would you like to create your project?', + default: 'statusboard', + when: () => !config.path + }, + { + type: 'confirm', + name: 'defaultLabels', + message: 'Do you want use default labels?', + default: true + }, + { + type: 'input', + name: 'labels', + message: 'What labels do you want to use (use commas to separate)', + when: (answers) => !answers.defaultLabels + }, + { + type: 'input', + name: 'orgs', + message: 'What organizations do you want to include (use commas to separate)' + }, { - name: projectName, - description: '"A dashboard for project status', - version: '1.0.0', - dependencies: ['@pkgjs/statusboard'], - author: null, - keywords: null, - repository: null, - type: 'commonjs', - private: true, - cwd: appPath, - license: 'MIT', - main: 'config.js', - devDependencies: null, - scrips: { - build: 'statusboard build -C ./config', - buildsite: 'npm run clean && statusboard site -C ./config', - buildindex: 'statusboard index -C ./config', - clean: 'rm -rf build/css build/js' - } + type: 'input', + name: 'repositories', + message: 'What repositories do you want to include (use commas to separate)' }, - {} - ) + { + type: 'confirm', + name: 'githubActions', + message: 'Do you want to use GitHub Pages?', + default: false + } + ]) + + config.path = answers.path.trim() + config.labels = answers.labels.split(',').map((l) => l.trim()) + config.orgs = answers.orgs.split(',').map((l) => l.trim()) + config.projects = answers.repositories.split(',').map((l) => l.trim()) + config.githubActions = answers.githubActions + + const appPath = path.resolve(config.path) + config.name = path.basename(appPath) + + const pkg = await createPackageJson({ + cwd: appPath, + name: config.name, + description: 'A dashboard for project status', + version: '1.0.0', + dependencies: ['@pkgjs/statusboard'], + author: null, + keywords: null, + repository: null, + type: 'commonjs', + private: true, + license: 'MIT', + main: 'config.js', + devDependencies: null, + scrips: { + build: 'statusboard build -C ./config', + buildsite: 'npm run clean && statusboard site -C ./config', + buildindex: 'statusboard index -C ./config', + clean: 'rm -rf build/css build/js' + } + }) console.log(pkg) - console.log(projectPath, projectName) } module.exports = create From a783b32a48eceffe23f0e18ad70d661f56b529ef Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 12:20:54 -0500 Subject: [PATCH 3/9] feat: create directory --- lib/commands/create.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index 879f2a2..ac145c3 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -1,6 +1,7 @@ const inquirer = require('inquirer') const path = require('node:path') const createPackageJson = require('create-package-json') +const fs = require('fs-extra') async function create (opts) { const { directory } = opts @@ -53,37 +54,37 @@ async function create (opts) { ]) config.path = answers.path.trim() - config.labels = answers.labels.split(',').map((l) => l.trim()) - config.orgs = answers.orgs.split(',').map((l) => l.trim()) - config.projects = answers.repositories.split(',').map((l) => l.trim()) + config.labels = answers.labels?.split(',').map((l) => l.trim()) || [] + config.orgs = answers.orgs?.split(',').map((l) => l.trim()) || [] + config.projects = answers.repositories?.split(',').map((l) => l.trim()) || [] config.githubActions = answers.githubActions const appPath = path.resolve(config.path) config.name = path.basename(appPath) - const pkg = await createPackageJson({ + await fs.ensureDir(appPath) + + await createPackageJson({ cwd: appPath, name: config.name, description: 'A dashboard for project status', version: '1.0.0', dependencies: ['@pkgjs/statusboard'], author: null, - keywords: null, + keywords: ["statusboard", "projects"], repository: null, type: 'commonjs', private: true, license: 'MIT', main: 'config.js', devDependencies: null, - scrips: { - build: 'statusboard build -C ./config', - buildsite: 'npm run clean && statusboard site -C ./config', - buildindex: 'statusboard index -C ./config', + scripts: { + build: 'statusboard build -C ./config.js', + buildsite: 'npm run clean && statusboard site -C ./config.js', + buildindex: 'statusboard index -C ./config.js', clean: 'rm -rf build/css build/js' } }) - - console.log(pkg) } module.exports = create From 74634e8f15538db4bf87aa0967e144fc91625f78 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 19:56:13 -0500 Subject: [PATCH 4/9] feat: create config and git repository --- lib/commands/create.js | 22 +++++++++++++++++++++- lib/git.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/git.js diff --git a/lib/commands/create.js b/lib/commands/create.js index ac145c3..a25b83a 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -2,6 +2,7 @@ const inquirer = require('inquirer') const path = require('node:path') const createPackageJson = require('create-package-json') const fs = require('fs-extra') +const { gitInit } = require('../git.js') async function create (opts) { const { directory } = opts @@ -48,7 +49,7 @@ async function create (opts) { { type: 'confirm', name: 'githubActions', - message: 'Do you want to use GitHub Pages?', + message: 'Do you want deploy with GitHub Actions?', default: false } ]) @@ -85,6 +86,25 @@ async function create (opts) { clean: 'rm -rf build/css build/js' } }) + + await createConfigFile(config) + + gitInit(appPath) +} + +async function createConfigFile (config) { + const configFile = path.join(config.path, 'config.js') + + const configJs = `module.exports = {${config.labels.length >= 1 ? `\nissueLabels: ${JSON.stringify(config.labels)},`: ''} + orgs: ${JSON.stringify(config.orgs)}, + projects: ${JSON.stringify(config.projects)}, + github: { + token: process.env.GITHUB_TOKEN + } +} +` + + await fs.writeFile(configFile, configJs) } module.exports = create diff --git a/lib/git.js b/lib/git.js new file mode 100644 index 0000000..e82da88 --- /dev/null +++ b/lib/git.js @@ -0,0 +1,39 @@ +const { execSync } = require("child_process"); +const { rm } = require("fs"); + +function isGitRepo() { + try { + execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" }); + return true; + } catch {} + return false; +} + +module.exports.gitInit = function gitInit(path) { + let didInit = false; + + try { + if(isGitRepo()) { + return false; + } + + execSync("git init", { stdio: "ignore" }); + + didInit = true; + + execSync("git checkout -b main", { stdio: "ignore" }); + execSync("git add -A", { stdio: "ignore" }); + execSync('git commit -m "Initial commit from @pkgjs/statusboard"', { + stdio: "ignore", + }); + + return true; + } catch (e) { + if (didInit) { + try { + rm(join(path, ".git"), { recursive: true, force: true }); + } catch (_) {} + } + return false; + } +} From 59277eafed66361a0f830622a89e6b526f4355a9 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 20:50:44 -0500 Subject: [PATCH 5/9] feat: validate user input --- lib/commands/create.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index a25b83a..8302351 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -34,17 +34,22 @@ async function create (opts) { type: 'input', name: 'labels', message: 'What labels do you want to use (use commas to separate)', - when: (answers) => !answers.defaultLabels + when: (answers) => !answers.defaultLabels, + validate: validateUserInput }, { type: 'input', name: 'orgs', - message: 'What organizations do you want to include (use commas to separate)' + message: + 'What organizations do you want to include (use commas to separate)', + validate: validateUserInput }, { type: 'input', name: 'repositories', - message: 'What repositories do you want to include (use commas to separate)' + message: + 'What repositories do you want to include (use commas to separate)', + validate: validateUserInput }, { type: 'confirm', @@ -56,13 +61,14 @@ async function create (opts) { config.path = answers.path.trim() config.labels = answers.labels?.split(',').map((l) => l.trim()) || [] - config.orgs = answers.orgs?.split(',').map((l) => l.trim()) || [] - config.projects = answers.repositories?.split(',').map((l) => l.trim()) || [] + config.orgs = answers.orgs?.split(',').map((l) => l.trim()) + config.projects = answers.repositories?.split(',').map((l) => l.trim()) config.githubActions = answers.githubActions const appPath = path.resolve(config.path) config.name = path.basename(appPath) - + config.path = appPath +console.log(config) await fs.ensureDir(appPath) await createPackageJson({ @@ -72,7 +78,7 @@ async function create (opts) { version: '1.0.0', dependencies: ['@pkgjs/statusboard'], author: null, - keywords: ["statusboard", "projects"], + keywords: ['statusboard', 'projects'], repository: null, type: 'commonjs', private: true, @@ -95,9 +101,15 @@ async function create (opts) { async function createConfigFile (config) { const configFile = path.join(config.path, 'config.js') - const configJs = `module.exports = {${config.labels.length >= 1 ? `\nissueLabels: ${JSON.stringify(config.labels)},`: ''} - orgs: ${JSON.stringify(config.orgs)}, - projects: ${JSON.stringify(config.projects)}, + const configJs = `module.exports = {${ + config.labels.length >= 1 + ? `\n issueLabels: ${JSON.stringify(config.labels)},` + : '' + }${config.orgs.length >= 1 ? `\n orgs: ${JSON.stringify(config.orgs)},` : ''}${ + config.projects.length >= 1 + ? `\n projects: ${JSON.stringify(config.projects)},` + : '' + } github: { token: process.env.GITHUB_TOKEN } @@ -107,4 +119,8 @@ async function createConfigFile (config) { await fs.writeFile(configFile, configJs) } +function validateUserInput(input) { + return input.trim().length > 0 +} + module.exports = create From 1adbe0509669fe2315a0cd989cd8167f53eca831 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 21:00:38 -0500 Subject: [PATCH 6/9] feat: transform input --- lib/commands/create.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index 8302351..c61fae8 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -34,22 +34,19 @@ async function create (opts) { type: 'input', name: 'labels', message: 'What labels do you want to use (use commas to separate)', - when: (answers) => !answers.defaultLabels, - validate: validateUserInput + when: (answers) => !answers.defaultLabels }, { type: 'input', name: 'orgs', message: - 'What organizations do you want to include (use commas to separate)', - validate: validateUserInput + 'What organizations do you want to include (use commas to separate)' }, { type: 'input', name: 'repositories', message: - 'What repositories do you want to include (use commas to separate)', - validate: validateUserInput + 'What repositories do you want to include (use commas to separate)' }, { type: 'confirm', @@ -60,15 +57,16 @@ async function create (opts) { ]) config.path = answers.path.trim() - config.labels = answers.labels?.split(',').map((l) => l.trim()) || [] - config.orgs = answers.orgs?.split(',').map((l) => l.trim()) - config.projects = answers.repositories?.split(',').map((l) => l.trim()) + + config.labels = transformUserInput(answers.labels) + config.orgs = transformUserInput(answers.orgs) + config.projects = transformUserInput(answers.repositories) config.githubActions = answers.githubActions const appPath = path.resolve(config.path) config.name = path.basename(appPath) config.path = appPath -console.log(config) + await fs.ensureDir(appPath) await createPackageJson({ @@ -119,8 +117,12 @@ async function createConfigFile (config) { await fs.writeFile(configFile, configJs) } -function validateUserInput(input) { - return input.trim().length > 0 +function transformUserInput(input) { + if (input?.length === 0) { + return [] + } + + return input?.split(",").map((l) => l.trim()) || [] } module.exports = create From 902a04efc4d410b0b2927ce4effbc0f8ba2ced3d Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 21:24:42 -0500 Subject: [PATCH 7/9] feat: create build workflow --- lib/commands/create.js | 74 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index c61fae8..91f5aaf 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -68,6 +68,12 @@ async function create (opts) { config.path = appPath await fs.ensureDir(appPath) + + if (config.githubActions) { + createBuildAction(config) + } + + await createConfigFile(config) await createPackageJson({ cwd: appPath, @@ -91,8 +97,6 @@ async function create (opts) { } }) - await createConfigFile(config) - gitInit(appPath) } @@ -107,7 +111,7 @@ async function createConfigFile (config) { config.projects.length >= 1 ? `\n projects: ${JSON.stringify(config.projects)},` : '' - } + }${config.githubActions ? `\n baseUrl: "/${config.name}",` : ''} github: { token: process.env.GITHUB_TOKEN } @@ -125,4 +129,68 @@ function transformUserInput(input) { return input?.split(",").map((l) => l.trim()) || [] } +function createBuildAction(config) { + const workflowDir = path.join(config.path, '.github', 'workflows') + fs.ensureDirSync(workflowDir) + const configFile = path.join(workflowDir, 'build.yml') + + const buildAction = `name: Generate Statusboard + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + index: + environment: + name: github-pages + url: \${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: actions/cache@v4 + id: cache + with: + path: | + ~/.npm + ~/.cache + ./dist + ./node_modules + key: \${{ runner.os }}-build-\${{ github.sha }} + - if: steps.cache.outputs.cache-hit != 'true' + run: npm install + shell: bash + - run: npm run build + env: + GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: './build' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 +` + + fs.writeFileSync(configFile, buildAction) +} + module.exports = create From 94b9fede53c56a3d5cabafbc4808de95365a6f80 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 29 Nov 2024 21:43:31 -0500 Subject: [PATCH 8/9] feat: copy of template --- lib/commands/create.js | 69 ++++++-------------------------- lib/commands/template/.gitignore | 11 +++++ lib/commands/template/build.yml | 54 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 lib/commands/template/.gitignore create mode 100644 lib/commands/template/build.yml diff --git a/lib/commands/create.js b/lib/commands/create.js index 91f5aaf..3e56683 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -74,6 +74,7 @@ async function create (opts) { } await createConfigFile(config) + createGitIgnore(config) await createPackageJson({ cwd: appPath, @@ -97,6 +98,7 @@ async function create (opts) { } }) + gitInit(appPath) } @@ -131,66 +133,19 @@ function transformUserInput(input) { function createBuildAction(config) { const workflowDir = path.join(config.path, '.github', 'workflows') - fs.ensureDirSync(workflowDir) + const templateFile = path.join(__dirname, 'template', 'build.yml') const configFile = path.join(workflowDir, 'build.yml') + + fs.ensureDirSync(workflowDir) + fs.copyFileSync(templateFile, configFile) +} - const buildAction = `name: Generate Statusboard - -on: - push: - branches: - - main - workflow_dispatch: - -permissions: - contents: read - pages: write - id-token: write - - -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - index: - environment: - name: github-pages - url: \${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v5 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - uses: actions/cache@v4 - id: cache - with: - path: | - ~/.npm - ~/.cache - ./dist - ./node_modules - key: \${{ runner.os }}-build-\${{ github.sha }} - - if: steps.cache.outputs.cache-hit != 'true' - run: npm install - shell: bash - - run: npm run build - env: - GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: './build' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 -` +function createGitIgnore(config) { + const gitIgnore = path.join(config.path, '.gitignore') + const templateFile = path.join(__dirname, 'template', '.gitignore') - fs.writeFileSync(configFile, buildAction) + fs.ensureFileSync(gitIgnore) + fs.copyFileSync(templateFile, gitIgnore) } module.exports = create diff --git a/lib/commands/template/.gitignore b/lib/commands/template/.gitignore new file mode 100644 index 0000000..d596a96 --- /dev/null +++ b/lib/commands/template/.gitignore @@ -0,0 +1,11 @@ +# dependencies +node_modules +.pnp +.pnp.js + +# production +build + +# local env files +.env*.local +.env \ No newline at end of file diff --git a/lib/commands/template/build.yml b/lib/commands/template/build.yml new file mode 100644 index 0000000..3691a49 --- /dev/null +++ b/lib/commands/template/build.yml @@ -0,0 +1,54 @@ +name: Generate Statusboard + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + index: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: actions/cache@v4 + id: cache + with: + path: | + ~/.npm + ~/.cache + ./dist + ./node_modules + key: ${{ runner.os }}-build-${{ github.sha }} + - if: steps.cache.outputs.cache-hit != 'true' + run: npm install + shell: bash + - run: npm run build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: './build' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file From 52d3476190ddbf367db6248531ff81aa47542c06 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Sun, 26 Jan 2025 15:35:24 -0500 Subject: [PATCH 9/9] fix code styles --- lib/commands/create.js | 13 ++++++------- lib/git.js | 43 +++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index 3e56683..553cbfd 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -68,7 +68,7 @@ async function create (opts) { config.path = appPath await fs.ensureDir(appPath) - + if (config.githubActions) { createBuildAction(config) } @@ -98,7 +98,6 @@ async function create (opts) { } }) - gitInit(appPath) } @@ -123,24 +122,24 @@ async function createConfigFile (config) { await fs.writeFile(configFile, configJs) } -function transformUserInput(input) { +function transformUserInput (input) { if (input?.length === 0) { return [] } - return input?.split(",").map((l) => l.trim()) || [] + return input?.split(',').map((l) => l.trim()) || [] } -function createBuildAction(config) { +function createBuildAction (config) { const workflowDir = path.join(config.path, '.github', 'workflows') const templateFile = path.join(__dirname, 'template', 'build.yml') const configFile = path.join(workflowDir, 'build.yml') - + fs.ensureDirSync(workflowDir) fs.copyFileSync(templateFile, configFile) } -function createGitIgnore(config) { +function createGitIgnore (config) { const gitIgnore = path.join(config.path, '.gitignore') const templateFile = path.join(__dirname, 'template', '.gitignore') diff --git a/lib/git.js b/lib/git.js index e82da88..91ebf19 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,39 +1,40 @@ -const { execSync } = require("child_process"); -const { rm } = require("fs"); +const { execSync } = require('child_process') +const { rm } = require('fs') +const { join } = require('path') -function isGitRepo() { - try { - execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" }); - return true; - } catch {} - return false; +function isGitRepo () { + try { + execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }) + return true + } catch {} + return false } -module.exports.gitInit = function gitInit(path) { - let didInit = false; +module.exports.gitInit = function gitInit (path) { + let didInit = false try { - if(isGitRepo()) { - return false; + if (isGitRepo()) { + return false } - execSync("git init", { stdio: "ignore" }); + execSync('git init', { stdio: 'ignore' }) - didInit = true; + didInit = true - execSync("git checkout -b main", { stdio: "ignore" }); - execSync("git add -A", { stdio: "ignore" }); + execSync('git checkout -b main', { stdio: 'ignore' }) + execSync('git add -A', { stdio: 'ignore' }) execSync('git commit -m "Initial commit from @pkgjs/statusboard"', { - stdio: "ignore", - }); + stdio: 'ignore' + }) - return true; + return true } catch (e) { if (didInit) { try { - rm(join(path, ".git"), { recursive: true, force: true }); + rm(join(path, '.git'), { recursive: true, force: true }) } catch (_) {} } - return false; + return false } }