From 153a029c250f103e0a74d410827908de21c50faa Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Fri, 7 May 2021 19:55:06 +0200 Subject: [PATCH] Restructure the `scripts/` directory (#5546) * Restructure scripts/ directory And update references to this scripts everywhere. * Update names of file-level constants in bump-version.js * Normalize quotes between all scripts * Move "create-release.yml" scripts to scripts/release * Move slugs table script to scripts/release * Update relative path logic in update-slugs-table.js --- .github/workflows/create-release.yml | 6 +++--- package.json | 6 +++--- .../{build-package.js => build/package.js} | 14 +++++++------ scripts/{ => build}/templates/icon-object.js | 0 scripts/{ => build}/templates/index.js | 0 scripts/{ => lint}/jsonlint.js | 5 +++-- scripts/{lint.js => lint/ourlint.js} | 3 ++- scripts/{ => release}/bump-version.js | 20 +++++++++---------- scripts/{ => release}/update-cdn-urls.js | 2 +- .../update-slugs-table.js} | 9 +++++---- 10 files changed, 35 insertions(+), 30 deletions(-) rename scripts/{build-package.js => build/package.js} (82%) rename scripts/{ => build}/templates/icon-object.js (100%) rename scripts/{ => build}/templates/index.js (100%) rename scripts/{ => lint}/jsonlint.js (71%) rename scripts/{lint.js => lint/ourlint.js} (94%) rename scripts/{ => release}/bump-version.js (53%) rename scripts/{ => release}/update-cdn-urls.js (95%) rename scripts/{build-slugs-table.js => release/update-slugs-table.js} (67%) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 8198d364..17659cb6 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -26,11 +26,11 @@ jobs: # Ensure we are checked out on the develop branch ref: develop - name: Bump version - run: node ./scripts/bump-version.js "${{ needs.release-pr.outputs.new-version }}" + run: node ./scripts/release/bump-version.js "${{ needs.release-pr.outputs.new-version }}" - name: Update major version in CDN URLs - run: node ./scripts/update-cdn-urls.js + run: node ./scripts/release/update-cdn-urls.js - name: Update slugs table - run: node ./scripts/build-slugs-table.js + run: node ./scripts/release/update-slugs-table.js - name: Commit version bump uses: stefanzweifel/git-auto-commit-action@v4.11.0 with: diff --git a/package.json b/package.json index f9316f27..032ba5b7 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,11 @@ "uglify-js": "3.13.5" }, "scripts": { - "build": "node scripts/build-package.js", + "build": "node scripts/build/package.js", "clean": "rm -f icons/*.js index.js", "lint": "run-s our-lint jsonlint svglint wslint", - "our-lint": "node scripts/lint.js", - "jsonlint": "node scripts/jsonlint.js", + "our-lint": "node scripts/lint/ourlint.js", + "jsonlint": "node scripts/lint/jsonlint.js", "svglint": "svglint icons/*.svg --ci", "wslint": "editorconfig-checker -exclude \\.svg$", "prepublishOnly": "npm run build", diff --git a/scripts/build-package.js b/scripts/build/package.js similarity index 82% rename from scripts/build-package.js rename to scripts/build/package.js index 86d2ddbc..37e02341 100644 --- a/scripts/build-package.js +++ b/scripts/build/package.js @@ -14,18 +14,20 @@ const minify = require("uglify-js").minify; const UTF8 = "utf8"; -const dataFile = path.resolve(__dirname, "..", "_data", "simple-icons.json"); -const indexFile = path.resolve(__dirname, "..", "index.js"); -const iconsDir = path.resolve(__dirname, "..", "icons"); +const rootDir = path.resolve(__dirname, "..", ".."); +const dataFile = path.resolve(rootDir, "_data", "simple-icons.json"); +const indexFile = path.resolve(rootDir, "index.js"); +const iconsDir = path.resolve(rootDir, "icons"); -const indexTemplateFile = path.resolve(__dirname, "templates", "index.js"); -const iconObjectTemplateFile = path.resolve(__dirname, "templates", "icon-object.js"); +const templatesDir = path.resolve(__dirname, "templates"); +const indexTemplateFile = path.resolve(templatesDir, "index.js"); +const iconObjectTemplateFile = path.resolve(templatesDir, "icon-object.js"); const indexTemplate = fs.readFileSync(indexTemplateFile, UTF8); const iconObjectTemplate = fs.readFileSync(iconObjectTemplateFile, UTF8); const data = require(dataFile); -const { getIconSlug, titleToSlug } = require("./utils.js"); +const { getIconSlug, titleToSlug } = require("../utils.js"); // Local helper functions function escape(value) { diff --git a/scripts/templates/icon-object.js b/scripts/build/templates/icon-object.js similarity index 100% rename from scripts/templates/icon-object.js rename to scripts/build/templates/icon-object.js diff --git a/scripts/templates/index.js b/scripts/build/templates/index.js similarity index 100% rename from scripts/templates/index.js rename to scripts/build/templates/index.js diff --git a/scripts/jsonlint.js b/scripts/lint/jsonlint.js similarity index 71% rename from scripts/jsonlint.js rename to scripts/lint/jsonlint.js index 94a8b8a6..b89e97de 100644 --- a/scripts/jsonlint.js +++ b/scripts/lint/jsonlint.js @@ -1,8 +1,9 @@ const path = require("path"); const Validator = require("jsonschema").Validator; -const schemaFile = path.resolve(__dirname, "..", ".jsonschema.json"); -const dataFile = path.resolve(__dirname, "..", "_data", "simple-icons.json"); +const rootDir = path.resolve(__dirname, "..", ".."); +const schemaFile = path.resolve(rootDir, ".jsonschema.json"); +const dataFile = path.resolve(rootDir, "_data", "simple-icons.json"); const schema = require(schemaFile); const data = require(dataFile); diff --git a/scripts/lint.js b/scripts/lint/ourlint.js similarity index 94% rename from scripts/lint.js rename to scripts/lint/ourlint.js index f250670b..d275a5d7 100644 --- a/scripts/lint.js +++ b/scripts/lint/ourlint.js @@ -12,7 +12,8 @@ const { diffLinesUnified } = require("jest-diff"); const UTF8 = "utf8"; -const dataFile = path.resolve( __dirname, "..", "_data", "simple-icons.json"); +const rootDir = path.resolve(__dirname, "..", ".."); +const dataFile = path.resolve(rootDir, "_data", "simple-icons.json"); const data = require(dataFile); /** diff --git a/scripts/bump-version.js b/scripts/release/bump-version.js similarity index 53% rename from scripts/bump-version.js rename to scripts/release/bump-version.js index 9261be59..90c16cab 100644 --- a/scripts/bump-version.js +++ b/scripts/release/bump-version.js @@ -4,12 +4,12 @@ * Updates the version of this package to the CLI specified version. */ -const { execSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); +const fs = require("fs"); +const path = require("path"); -const PACKAGE_JSON_FILE = path.resolve(__dirname, '..', 'package.json'); -const PACKAGE_LOCK_FILE = path.resolve(__dirname, '..', 'package-lock.json'); +const rootDir = path.resolve(__dirname, "..", ".."); +const packageJsonFile = path.resolve(rootDir, "package.json"); +const packageLockFile = path.resolve(rootDir, "package-lock.json"); function readManifest(file) { const manifestRaw = fs.readFileSync(file).toString(); @@ -18,20 +18,20 @@ function readManifest(file) { } function writeManifest(file, json) { - const manifestRaw = JSON.stringify(json, null, 2) + '\n'; + const manifestRaw = JSON.stringify(json, null, 2) + "\n"; fs.writeFileSync(file, manifestRaw); } function main(newVersion) { try { - const manifest = readManifest(PACKAGE_JSON_FILE); - const manifestLock = readManifest(PACKAGE_LOCK_FILE); + const manifest = readManifest(packageJsonFile); + const manifestLock = readManifest(packageLockFile); manifest.version = newVersion manifestLock.version = newVersion - writeManifest(PACKAGE_JSON_FILE, manifest); - writeManifest(PACKAGE_LOCK_FILE, manifestLock); + writeManifest(packageJsonFile, manifest); + writeManifest(packageLockFile, manifestLock); } catch (error) { console.error(`Failed to bump package version to ${newVersion}:`, error); process.exit(1); diff --git a/scripts/update-cdn-urls.js b/scripts/release/update-cdn-urls.js similarity index 95% rename from scripts/update-cdn-urls.js rename to scripts/release/update-cdn-urls.js index 735f8dab..adf96763 100644 --- a/scripts/update-cdn-urls.js +++ b/scripts/release/update-cdn-urls.js @@ -8,7 +8,7 @@ const fs = require("fs"); const path = require("path"); -const rootDir = path.resolve(__dirname, ".."); +const rootDir = path.resolve(__dirname, "..", ".."); const packageJsonFile = path.resolve(rootDir, "package.json"); const readmeFile = path.resolve(rootDir, "README.md"); diff --git a/scripts/build-slugs-table.js b/scripts/release/update-slugs-table.js similarity index 67% rename from scripts/build-slugs-table.js rename to scripts/release/update-slugs-table.js index cb45670a..69657e8b 100644 --- a/scripts/build-slugs-table.js +++ b/scripts/release/update-slugs-table.js @@ -7,15 +7,16 @@ const fs = require("fs"); const path = require("path"); -const dataFile = path.resolve(__dirname, "..", "_data", "simple-icons.json"); -const slugsFile = path.resolve(__dirname, "..", "slugs.md"); +const rootDir = path.resolve(__dirname, "..", ".."); +const dataFile = path.resolve(rootDir, "_data", "simple-icons.json"); +const slugsFile = path.resolve(rootDir, "slugs.md"); const data = require(dataFile); -const { getIconSlug } = require("./utils.js"); +const { getIconSlug } = require("../utils.js"); let content = ` # Simple Icons slugs