Browse Source

Refactor build scripts.

primary
CismonX 2 months ago
parent
commit
19e34d8ed6
Signed by: CismonX GPG Key ID: 3094873E29A482FB
  1. 1
      .gitignore
  2. 2
      .vscodeignore
  3. 5
      package.json
  4. 33
      scripts/make-vsix.js
  5. 47
      scripts/package.sh
  6. 7
      tsconfig.json

1
.gitignore

@ -10,3 +10,4 @@
.vscode/
node_modules/
out/
texinfo-*.d/

2
.vscodeignore

@ -8,7 +8,6 @@
**/*.map
**/*.ts
**/*.vsce-pre-package-backup
.drone.yml
.gitignore
.gitattributes
@ -19,4 +18,5 @@ LICENSE_NOTICE.md
node_modules/
src/
scripts/
texinfo-*.d/
tsconfig.json

5
package.json

@ -53,7 +53,10 @@
},
"eslintConfig": {
"root": true,
"ignorePatterns": "out/**",
"ignorePatterns": [
"out/**",
"scripts/**"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"

33
scripts/make-vsix.js

@ -0,0 +1,33 @@
/**
* Copyright (C) 2021 CismonX <admin@cismon.net>
*
* Copying and distribution of this file, with or without modification, are
* permitted in any medium without royalty, provided the copyright notice and
* this notice are preserved. This file is offered as-is, without any warranty.
*/
const fs = require('fs')
const yazl = require('yazl');
async function addPathToZipFile(zipFile, path) {
for (file of await fs.promises.readdir(path, { withFileTypes: true })) {
const name = `${path}/${file.name}`;
if (file.isDirectory()) {
await addPathToZipFile(zipFile, name);
} else {
zippedPath = name.substr(name.indexOf('/') + 1);
console.log(`+ ${zippedPath}`);
zipFile.addFile(name, zippedPath);
}
}
}
(async () => {
const vsixFile = process.argv.pop();
console.log(`Creating ${vsixFile}:`);
const zipFile = new yazl.ZipFile();
zipFile.outputStream.pipe(fs.createWriteStream(vsixFile))
.on('close', () => console.log(`Finish creating ${vsixFile}`));
await addPathToZipFile(zipFile, `${vsixFile}.d`);
zipFile.end();
})()

47
scripts/package.sh

@ -7,31 +7,24 @@
# this notice are preserved. This file is offered as-is, without any warranty.
#
BACKUP_SUFFIX=vsce-pre-package-backup
JSON_FILES=(package.json language-configuration.json)
for file in ${JSON_FILES[@]}; do
mv $file $file.$BACKUP_SUFFIX
json5 -o $file $file.$BACKUP_SUFFIX
done
XML_PATH=./node_modules/vsce/resources
XML_FILES=($XML_PATH/\[Content_Types\].xml $XML_PATH/extension.vsixmanifest)
for file in ${XML_FILES[@]}; do
mv $file $file.$BACKUP_SUFFIX
minify-xml --output $file $file.$BACKUP_SUFFIX
done
MD_FILES=(README.md CHANGELOG.md)
for file in ${MD_FILES[@]}; do
mv $file $file.$BACKUP_SUFFIX
tail -n +9 $file.$BACKUP_SUFFIX > $file
done
json -j0 -I -e "$(cat ./scripts/package-json-cleanup.js)" -f package.json
VSIX_FILE_NAME=texinfo-$(json -f package.json version).vsix
PACKAGE_JSON_CLEANUP_JS=$(cat ./scripts/package-json-cleanup.js)
vsce package --baseContentUrl=$(json -f package.json repository.url)/tree
for file in ${JSON_FILES[@]}; do
mv $file.$BACKUP_SUFFIX $file
done
for file in ${MD_FILES[@]}; do
mv $file.$BACKUP_SUFFIX $file
done
for file in ${XML_FILES[@]}; do
mv $file.$BACKUP_SUFFIX $file
done
unzip -d $VSIX_FILE_NAME{.d,}
cd $VSIX_FILE_NAME.d
minify-xml --output \[Content_Types\].xml{,}
minify-xml --output extension.vsixmanifest{,}
cd extension
# Minify JSON files.
json -j0 -I -e "$PACKAGE_JSON_CLEANUP_JS" -f package.json
json5 -o package.json{,}
json5 -o language-configuration.json{,}
# Remove comments from Markdown files.
sed -i '' -e '1,8d' README.md CHANGELOG.md
cd ../..
# Re-package .vsix file.
node ./scripts/make-vsix.js $VSIX_FILE_NAME
rm -r $VSIX_FILE_NAME.d

7
tsconfig.json

@ -15,10 +15,11 @@
"sourceMap": true,
"rootDir": "src",
"strict": true,
"noImplicitReturns": true
"noImplicitReturns": true,
},
"exclude": [
"*.config.ts",
"node_modules",
"*.config.ts"
]
"scripts",
],
}
Loading…
Cancel
Save