Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new dist build process #788

Merged
merged 24 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b1fab7a
Update wp-env symlinks to use vendor dir
westonruter Nov 22, 2023
4732cf8
Update .gitattributes
westonruter Nov 22, 2023
1f7a338
Remove .gitattributes
westonruter Nov 22, 2023
bc62634
WIP: Create new build script
westonruter Nov 22, 2023
9ae1737
Merge branch 'develop' into update/build-process
westonruter Mar 13, 2024
78c69f5
Append date and commit hash to non-stable version
westonruter Mar 14, 2024
4a7b4f0
Add .distignore
westonruter Mar 14, 2024
fef648e
Use WP-CLI to create zip
westonruter Mar 14, 2024
cd83d55
Run dist-archive from root
westonruter Mar 14, 2024
87850b6
Use long args for composer install
westonruter Mar 14, 2024
135ec95
Update npm scripts
westonruter Apr 2, 2024
1ae3405
Remove unused grunt-contrib-copy
westonruter Apr 2, 2024
c011f14
Remove unused grunt dist
westonruter Apr 2, 2024
06707e2
Add ZIP files to .distignore
westonruter Apr 2, 2024
37f1bd9
Use dev-main of dist-archive
westonruter Apr 2, 2024
49a5452
Fix build-dist
westonruter Apr 2, 2024
d577cf0
Fix creating ZIP of build
westonruter Apr 2, 2024
9587d26
Use unzipped directory for dist target
westonruter Apr 2, 2024
1d887d1
Bump versions
westonruter Apr 2, 2024
ae98ec7
Merge branch 'develop' of https://github.com/westonruter/syntax-highl…
westonruter Apr 2, 2024
f53e0e9
Fix where setting DEVELOPMENT_MODE
westonruter Apr 2, 2024
26bfb24
Reduce duplication
westonruter Apr 2, 2024
18adf1c
Remove obsolete composer script
westonruter Apr 2, 2024
520d5fd
Add deploy dir to gitignore
westonruter Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.distignore
.editorconfig
.eslintignore
.eslintrc.js
.github
.gitignore
.husky
.lintstagedrc.js
.nvmrc
.phpcs.xml.dist
.prettierrc
.wordpress-org
.wp-env.json
Gruntfile.js
README.md
bin
block-library.md5
composer.json
composer.lock
node_modules
package-lock.json
package.json
phpstan.neon.dist
src
tests
*.zip
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
tab_width = 4

[{.babelrc,.eslintrc,.rtlcssrc,*.json,*.yml,*.yaml}]
indent_style = space
Expand Down
15 changes: 0 additions & 15 deletions .gitattributes

This file was deleted.

11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
/build
/vendor
/node_modules

# Directories used in the dist/deploy process.
/dist
/syntax-highlighting-code-block

# Generated via bin/transform-readme.php
/readme.txt

# Ignore symlinked directories for wp-env
/wp-core
/wp-tests-phpunit

# In case the GitHub Wiki repo is cloned.
/wiki

# IDE files
.idea
.vscode
127 changes: 2 additions & 125 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,139 +12,16 @@ module.exports = function (grunt) {
deploy: {
options: {
plugin_slug: 'syntax-highlighting-code-block',
build_dir: 'dist',
build_dir: 'syntax-highlighting-code-block',
assets_dir: '.wordpress-org',
},
},
},
});

// Load tasks.
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-wp-deploy');

// Register tasks.
grunt.registerTask('default', ['dist']);

grunt.registerTask('dist', function () {
const done = this.async();
const spawnQueue = [];
const stdout = [];

spawnQueue.push({
cmd: 'git',
args: ['--no-pager', 'log', '-1', '--format=%h', '--date=short'],
});

function finalize() {
const commitHash = stdout.shift();
const versionAppend =
new Date()
.toISOString()
.replace(/\.\d+/, '')
.replace(/-|:/g, '') +
'-' +
commitHash;

const paths = [
'syntax-highlighting-code-block.php',
'inc/*',
'language-names.php',
'editor-styles.css',
'style.css',
'readme.txt',
'LICENSE',
'build/*',
];

grunt.config.set('copy', {
build: {
src: paths,
dest: 'dist',
expand: true,
options: {
noProcess: ['*/**', 'LICENSE'], // That is, only process syntax-highlighting-code-block.php and README.md.
process(content, srcpath) {
if (
!/syntax-highlighting-code-block\.php$/.test(
srcpath
)
) {
return content;
}
let updatedContent = content;
const versionRegex =
/(\*\s+Version:\s+)(\d+(\.\d+)+-\w+)/;
let version;

// If not a stable build (e.g. 0.7.0-beta), amend the version with the git commit and current timestamp.
const matches = content.match(versionRegex);
if (matches) {
version = matches[2] + '-' + versionAppend;
console.log(
'Updating version in plugin version to ' +
version
);
updatedContent = updatedContent.replace(
versionRegex,
'$1' + version
);
updatedContent = updatedContent.replace(
/(const PLUGIN_VERSION = ')(.+?)(?=')/,
'$1' + version
);
}

updatedContent = updatedContent.replace(
/const DEVELOPMENT_MODE = true;.*/,
'const DEVELOPMENT_MODE = false;'
);

return updatedContent;
},
},
},
composer: {
src: ['vendor/autoload.php', 'vendor/composer/**'],
dest: 'dist',
expand: true,
options: {
noProcess: ['vendor/composer/installed.json'],
process(content) {
return content.replace(
/\/highlight\.php/g,
'/highlight-php'
);
},
},
},
vendor: {
src: ['Highlight/**', 'HighlightUtilities/**', 'styles/*'],
expand: true,
cwd: 'vendor/scrivo/highlight.php/',
dest: 'dist/vendor/scrivo/highlight-php/',
},
});
grunt.task.run('copy');

done();
}

function doNext() {
const nextSpawnArgs = spawnQueue.shift();
if (!nextSpawnArgs) {
finalize();
} else {
grunt.util.spawn(nextSpawnArgs, function (err, res) {
if (err) {
throw new Error(err.message);
}
stdout.push(res.stdout);
doNext();
});
}
}

doNext();
});
grunt.registerTask('default', ['wp_deploy']);
};
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Extending the Code block with syntax highlighting rendered on the server, thus b

**Contributors:** [westonruter](https://profiles.wordpress.org/westonruter), [allejo](https://profiles.wordpress.org/allejo)
**Tags:** [block](https://wordpress.org/plugins/tags/block), [code](https://wordpress.org/plugins/tags/code), [code syntax](https://wordpress.org/plugins/tags/code-syntax), [syntax highlight](https://wordpress.org/plugins/tags/syntax-highlight), [code highlighting](https://wordpress.org/plugins/tags/code-highlighting)
**Requires at least:** 6.3
**Tested up to:** 6.4
**Stable tag:** 1.4.0
**Requires at least:** 6.4
**Tested up to:** 6.5
**Stable tag:** 1.5.0
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
**Requires PHP:** 7.4

Expand Down
44 changes: 44 additions & 0 deletions bin/build-dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -e
cd $(dirname $0)/..

if [ ! -e dist ]; then
mkdir dist
fi

echo "Exporting repo to dist directory"
git archive --format=tar HEAD | (cd dist/ && tar xf -)

cd dist

# Symlink node_modules rather than installing anew if possible.
if [ -e ../node_modules ]; then
ln -s ../node_modules node_modules
else
npm install
fi

# Install composer dependencies with optimized autoloader and excluding dev-dependencies.
composer install --no-dev --classmap-authoritative --optimize-autoloader

# Since the "highlight.php" directory name can trip up some systems, rename to "highlight-php".
mv vendor/scrivo/highlight{.php,-php}
find vendor/autoload.php vendor/composer -type f -print0 | xargs -0 sed -i "s:/highlight\.php/:/highlight-php/:g"
sed -i "s/const DEVELOPMENT_MODE = true;.*/const DEVELOPMENT_MODE = false;/g" syntax-highlighting-code-block.php

# Build the JS.
npm run build:js

# Convert markdown README.
npm run build:transform-readme

# Grab amend the version with the commit hash.
VERSION=$(grep 'PLUGIN_VERSION' syntax-highlighting-code-block.php | cut -d\' -f2)
if [[ $VERSION == *-* ]]; then
NEW_VERSION="$VERSION-$(date -u +%Y%m%dT%H%M%SZ)-$(git --no-pager log -1 --format=%h --date=short)"
VERSION_ESCAPED="${VERSION//./\\.}"
sed -i "s/$VERSION_ESCAPED/$NEW_VERSION/g" syntax-highlighting-code-block.php
echo "Detected non-stable version: $VERSION"
echo "Creating build for version: $NEW_VERSION"
fi
6 changes: 4 additions & 2 deletions bin/symlink-wp-env-install-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ if [[ -z "$install_path" ]]; then
exit 1
fi

core_dir="wp-core"
mkdir -p vendor/wp-env

core_dir="vendor/wp-env/wp-core"
if [[ -e "$core_dir" ]]; then
rm "$core_dir"
fi
ln -s "$install_path/WordPress" "$core_dir"
echo "Created $core_dir symlink"

tests_dir="wp-tests-phpunit"
tests_dir="vendor/wp-env/wp-tests-phpunit"
if [[ -e "$tests_dir" ]]; then
rm "$tests_dir"
fi
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"civicrm/composer-downloads-plugin": "3.0.1",
"phpcompatibility/php-compatibility": "9.3.5",
"szepeviktor/phpstan-wordpress": "1.3.4",
"wp-cli/dist-archive-command": "dev-main",
"wp-coding-standards/wpcs": "3.1.0"
},
"config": {
Expand Down Expand Up @@ -40,7 +41,6 @@
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi; fi",
"normalize": "composer-normalize",
"phpcbf": "bin/phpcbf.sh",
"phpcs": "phpcs",
"zip": "git archive --format=zip HEAD > syntax-highlighting-code-block.zip && unzip -l syntax-highlighting-code-block.zip"
"phpcs": "phpcs"
}
}
Loading
Loading