feat: tophat script, reluctantly

This commit is contained in:
Matt Seccafien 2021-11-07 22:18:18 +01:00
parent a16039324d
commit 84631b29bd
5 changed files with 150 additions and 4 deletions

View file

@ -182,3 +182,16 @@ When finished, push up your changes.
Next, visit the Shipit page for Hydrogen and click **Deploy**.
After Shipit has released your version, visit the [releases page on GitHub](https://github.com/Shopify/hydrogen/releases), click on the version number you just released, and select "Create release from tag." Then, select "Auto-generate release notes." At this point, edit the release notes as you see fit (e.g. call out any breaking changes or upgrade guides). Finally, click "Publish release."
## Testing changes in another project
From the root of the repo, run:
```bash
yarn tophat ../PATH/TO/PROJECT --packages [...PACKAGES_LIST]
# example
yarn tophat../cartogram/hydrogen-shop --packages cli hydrogen eslint-plugin
```

View file

@ -30,7 +30,8 @@
"h2": "./packages/cli/bin/hydrogen",
"update-docs-on-version": "ts-node --project ./tsconfig.json ./scripts/update-docs-on-version.ts",
"generate-docs": "ts-node --project ./tsconfig.json ./scripts/generate-docs.ts",
"generate-docs:debug": "node --inspect-brk ./node_modules/.bin/ts-node --project ./tsconfig.json ./scripts/generate-docs.ts"
"generate-docs:debug": "node --inspect-brk ./node_modules/.bin/ts-node --project ./tsconfig.json ./scripts/generate-docs.ts",
"tophat": "node ./scripts/tophat"
},
"devDependencies": {
"@shopify/prettier-config": "^1.1.2",
@ -66,7 +67,8 @@
"typescript": "^4.2.3",
"vite": "^2.6.0",
"yorkie": "^2.0.0",
"glob": "^7.2.0"
"glob": "^7.2.0",
"shelljs": "^0.8.4"
},
"gitHooks": {
"pre-commit": "lint-staged",

View file

@ -12,7 +12,8 @@
"test": "jest",
"dev": "yarn build -w",
"build": "tsc -p .",
"prepack": "yarn build"
"prepack": "yarn build",
"tophat": "node ./scripts/tophat"
},
"repository": {
"type": "git",

109
scripts/tophat.js Normal file
View file

@ -0,0 +1,109 @@
const {resolve} = require('path');
const {config, exec, pushd, cp, mkdir, rm, echo, exit} = require('shelljs');
const logBreak = () => {
echo(' ');
};
const log = (text) => {
echo(` ${text}`);
};
const logDivder = () => {
logBreak();
echo('-----');
logBreak();
};
const logHeader = (header) => {
echo(`/ ${header}`);
logBreak();
};
function tophat({scope, files, packageDir, destProjectDir, skipBuild}) {
const root = resolve(__dirname, '..');
config.fatal = true;
if (!destProjectDir) {
log(
'A target project directory is required. `yarn tophat PROJECT_DIRECTORY`'
);
exit(1);
}
const destPackageDir = resolve(root, `../${destProjectDir}/node_modules/`);
logBreak();
files.forEach(({name, scoped, directory}) => {
logHeader(name);
const source = resolve(packageDir, directory);
const destination = scoped
? resolve(destPackageDir, scope)
: resolve(destPackageDir);
const destinationPackage = resolve(destination, name);
if (skipBuild) {
log(`skipping build`);
} else {
log(`building ${name}...`);
pushd(source);
exec('yarn run build');
pushd('+1');
}
log(`Removing ${destinationPackage}...`);
rm('-rf', destinationPackage);
log(`Creating new build directory at ${destination}...`);
mkdir('-p', destination);
log(`Copying source in ${source} to build to ${destination} to `);
cp('-R', source, destinationPackage);
log('Success!');
logDivder();
});
logBreak();
log('Build copied to project. ');
}
const DEFAULT_PKGS = ['cli'];
const PACKAGE_CONFIG_MAP = [
{
name: 'hydrogen-cli',
directory: 'cli',
scoped: true,
},
{
name: 'eslint-plugin-shopify',
directory: 'eslint-plugin',
scoped: false,
},
];
(() => {
const args = process.argv.slice(2);
const destProjectDir = args[0];
const packagesIndex = args.findIndex((arg) => arg === '--packages');
const packages = args.slice(packagesIndex + 1);
const skipBuild = args.findIndex((arg) => arg === '--skip-build');
const files = packages.map((pkg) => {
const results = PACKAGE_CONFIG_MAP.filter(
(config) => config.directory === pkg
);
return results.length && results[0];
});
tophat({
skipBuild: skipBuild !== -1,
files,
scope: '@shopify',
packageDir: 'packages',
destProjectDir: destProjectDir,
});
})();

View file

@ -7791,6 +7791,11 @@ internal-slot@^1.0.3:
has "^1.0.3"
side-channel "^1.0.4"
interpret@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@ -11946,6 +11951,13 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
dependencies:
resolve "^1.1.6"
redent@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f"
@ -12270,7 +12282,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
resolve@^1.10.0, resolve@^1.10.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.20.0:
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
@ -12648,6 +12660,15 @@ shell-quote@^1.6.1:
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
shelljs@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
shellwords@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"