Skip to content

Commit

Permalink
chore: Update project scripts and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
hangxingliu committed Mar 14, 2024
1 parent 5d302c0 commit 5c94ae0
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,markdown}]
tab_width = 2
indent_size = 2
indent_style = space
trim_trailing_whitespace = false

[*.{yaml,yml}]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Lint
run: yarn lint
- name: Bundle and Pack Package
run: yarn run release
run: yarn build:vsix
- uses: actions/upload-artifact@v4
with:
name: vscode-extension
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.vscode/settings.json
cspell.yml

# output files
# generated files
artifacts
log
out
.tsc

Expand Down
9 changes: 6 additions & 3 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
# if I don't ignore node_modules, `vsce` will pack optional dependencies into the extension
node_modules
out/**/*.json
/ts
ts

#
#region main
# template: .vscodeignore
# author: hangxingliu
# license: MIT
# version: 2024-03-10
# version: 2024-03-14
#

# spellchecker
cspell.yml

# output files
artifacts
.tsc
Expand Down Expand Up @@ -64,6 +67,6 @@ examples
._*

# logs
/logs
logs
*.log
#endregion main
13 changes: 11 additions & 2 deletions cspell.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# https://cspell.org/
language: en
dictionaries:
- softwareTerms
- bash
ignorePaths:
- src/hint-data/manifests
- src/hint-data/wellknown-targets.ts
Expand All @@ -11,13 +14,14 @@ ignorePaths:
- src/hint-data/*.json
- "*.tmLanguage"
ignoreRegExpList:
- /@\w+/ # usernames
- /\w+:/ # property keys
- /"\w+"/ # a word in a string
- /<\/?\w+>/ # HTML tags
- /[A-Z]{4,}/ # all uppercase
- /\/.+\// # in RegExp
- /HTMLSupported|JSONSchema/
- /`[\w\-=]+`/ # code in markdown
- /@\w+(?:\s*\(.+?\))/ # usernames
- /HTMLSupported|JSONSchema/ # compound words
words:
- automount
- bearmini
Expand Down Expand Up @@ -61,3 +65,8 @@ words:
- verstr
- repart
- foldings
- userspace
- testdir
- syscalls
- unescaping
- balabalabala
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"virtualWorkspaces": true
},
"scripts": {
"release": "node scripts/run scripts build && ./scripts/build-vscode-artifact.sh",
"bundle": "webpack --mode production --devtool hidden-source-map",
"build": "node scripts/run scripts clean bundle build:assets",
"build:ts": "swc -d out src --strip-leading-paths --copy-files",
"build:dev": "node scripts/run scripts --parallel build:ts build:assets && node scripts/run scripts build:syntax",
"build:assets": "cd src && copyfiles '**/*.{tmLanguage,json,png}' ../out",
"build:syntax": "node --enable-source-maps out/syntax/generate-tmLanguage",
"build": "node scripts/run clean build:webpack copy:assets",
"build:dev": "node scripts/run build:ts build:pkgjson build:syntax",
"build:pkgjson": "node --enable-source-maps out/build-contributes",
"build:syntax": "node --enable-source-maps out/syntax/generate-tmLanguage",
"build:ts": "swc -d out src --strip-leading-paths --copy-files",
"build:vsix": "node scripts/run build && ./scripts/build-vscode-artifact.sh",
"build:webpack": "webpack --mode production --devtool hidden-source-map",
"copy:assets": "cd src && copyfiles '**/*.{tmLanguage,png}' ../out",
"fetch:base": "node --enable-source-maps out/hint-data/fetch/systemd-all",
"fetch:podman": "node --enable-source-maps out/hint-data/fetch/podman-quadlet",
"fetch:capabilities": "node --enable-source-maps out/hint-data/fetch/linux-capabilities",
"analyze": "node --enable-source-maps out/hint-data/analyze-value-enum",
"fetch:syscalls": "node --enable-source-maps out/hint-data/fetch/linux-syscalls",
"test": "tsc --project tsconfig.json --outDir .tsc",
"lint": "eslint src",
"clean": "rimraf out .tsc"
Expand Down
35 changes: 0 additions & 35 deletions scripts/build-vscode-artifact.sh

This file was deleted.

60 changes: 28 additions & 32 deletions scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// template: run-cjs.js
// author: hangxingliu
// license: MIT
// version: 2023-11-23
// version: 2024-03-12
const { platform } = require("os");
const { existsSync } = require("fs");
const { resolve, basename, dirname } = require("path");
const { spawn, spawnSync } = require("child_process");
const runFromPackageScript = !!process.env.npm_execpath;
const runFromYarn = /yarn\/bin/.test(process.env.npm_execpath || "");
const isWin32 = platform() === 'win32';
const isWin32 = platform() === "win32";

/** @see https://stackoverflow.com/questions/14031763 */
const cleanupCallbacks = [];
Expand Down Expand Up @@ -154,49 +154,45 @@ function isTrue(str) {
}

/**
* Run scripts defined in package.json
* @param {string[]} args
*/
async function run(args) {
// eslint-disable-next-line
const [nodejs, thisFile, action, ...restArgs] = args;
if (!action) return;
if (action === "scripts") {
let parallel = false;
if (!runFromPackageScript) throw `Action "scripts" is required to be run by npm/yarn`;
const scripts = [];
for (let i = 0; i < restArgs.length; i++) {
const arg = restArgs[i];
if (arg === "--parallel") {
async function runPackageScripts(args) {
/** @type {string[]} */
const scripts = [];
let parallel = false;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
switch (arg) {
case "--parallel":
parallel = true;
continue;
}
if (arg === "--") {
scripts.push(...restArgs.slice(i + 1));
break;
}
scripts.push(arg);
case "--env":
// debug env
for (const key of Object.keys(process.env).sort()) console.log(`${key}=${process.env[key]}`);
return;
case "--":
scripts.push(...args.slice(i + 1));
break;
default:
scripts.push(arg);
}
const base = [runFromYarn ? "yarn" : "npm", "run", "--silent"];
if (runFromYarn) base.splice(1, 0, "--ignore-engines");
if (parallel) return Promise.all(scripts.map((script) => exec([...base, script]).promise));
for (const script of scripts) execSync([...base, script]);
return;
}
if (action === "env") {
const envKeys = Object.keys(process.env).sort();
for (const key of envKeys) console.log(`${key}=${process.env[key]}`);
return;
}
throw `Unknown action: "${action}"`;
if (scripts.length === 0) return;
const base = [runFromYarn ? "yarn" : "npm", "run", "--silent"];
if (runFromYarn) base.splice(1, 0, "--ignore-engines");
if (parallel) return Promise.all(scripts.map((script) => exec([...base, script]).promise));
for (const script of scripts) execSync([...base, script]);
return;
}

exports.isWin32 = isWin32;
exports.exec = exec;
exports.execSync = execSync;
exports.isTrue = isTrue;
exports.run = run;
exports.run = runPackageScripts;
if (typeof require !== "undefined" && require.main === module) {
run(process.argv).catch((error) => {
runPackageScripts(process.argv.slice(2)).catch((error) => {
console.error(typeof error === "string" ? `Error: ${error}` : error);
process.exit(1);
});
Expand Down
Loading

0 comments on commit 5c94ae0

Please sign in to comment.