diff --git a/.gitignore b/.gitignore index faacf20..c473282 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ template/js !.yarn/releases !.yarn/plugins .pnp.* + +*.tgz diff --git a/.husky/pre-commit b/.husky/pre-commit index 5a182ef..3723623 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - yarn lint-staged diff --git a/.releaserc b/.releaserc index ac55788..b823620 100644 --- a/.releaserc +++ b/.releaserc @@ -41,6 +41,12 @@ "changelogFile": "CHANGELOG.md" } ], + [ + "@semantic-release/exec", + { + "prepareCmd": "./scripts/create-npm-package.sh" + } + ], "@semantic-release/npm", [ "@semantic-release/git", diff --git a/README.md b/README.md index fd815d8..dd686cc 100644 --- a/README.md +++ b/README.md @@ -29,18 +29,10 @@ Before starting development, go to the directory where you created the template yarn ``` -**For iOS only**: Install required Pods for the bare React Native example app: +**For iOS only**: Install required Pods for the bare React Native example app (`examples/fabric` or `examples/paper`): ```sh -yarn example:bare pod -``` - -### Getting help - -For more details about the `npx rn-lib-temp` command use the following command: - -```sh -npx rn-lib-temp help +yarn pod ``` ## 💫 GitHub Actions @@ -99,13 +91,13 @@ If you don't need to include **expo** or **fabric**/**paper** React Native app e For launching the bare React Native example app: ```sh -yarn example:bare start|android|ios|pod +yarn start|android|ios|pod ``` For the Expo React Native app: ```sh -yarn example:expo start|android|ios +yarn start|android|ios ``` - `start` - starts metro client diff --git a/bin/index.js b/bin/index.js index 8a7ef4f..f5f7141 100755 --- a/bin/index.js +++ b/bin/index.js @@ -40,10 +40,15 @@ yargs(hideBin(process.argv)) init(argv.projectName, argv.verbose, argv.directory); } ) - .demandCommand(1, 'You need at least one command before moving on') + .demandCommand(1, '', 'You need at least one command before moving on') .help() - .fail(msg => { - logger.error(msg); + .fail((msg, err, yargsInstance) => { + if (!msg && !err) { + logger.error('You need at least one command before moving on.'); + console.log(yargsInstance.help()); + } else { + logger.error(msg || err.message); + } process.exit(1); }) .strict().argv; diff --git a/package.json b/package.json index 50b2018..836defe 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@eslint/js": "^9.1.1", "@semantic-release/changelog": "^6.0.3", "@semantic-release/commit-analyzer": "^13.0.0", + "@semantic-release/exec": "^6.0.3", "@semantic-release/git": "^10.0.1", "@semantic-release/github": "^10.0.7", "@semantic-release/npm": "^12.0.1", @@ -22,7 +23,7 @@ "eslint": "^8.57.0", "eslint-plugin-prettier": "^5.1.3", "globals": "^15.0.0", - "husky": "^9.0.11", + "husky": "^9.1.6", "lint-staged": "^15.2.7", "prettier": "^3.3.2", "semantic-release": "^24.0.0", @@ -83,7 +84,7 @@ "lint": "eslint .", "lint:fix": "eslint --fix .", "postinstall": "yarn library:install", - "prepare": "husky install" + "prepare": "husky" }, "type": "module" } diff --git a/scripts/create-npm-package.sh b/scripts/create-npm-package.sh new file mode 100755 index 0000000..a874145 --- /dev/null +++ b/scripts/create-npm-package.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +PACKAGE_JSON="package.json" +PACKAGE_JSON_BAK="package.json.bak" + +# Check if package.json exists +if [ ! -f "$PACKAGE_JSON" ]; then + echo "Error: $PACKAGE_JSON not found." + exit 1 +fi + +# Backup the original package.json +cp "$PACKAGE_JSON" "$PACKAGE_JSON_BAK" + +# Execute the Node.js script to modify package.json +node ./scripts/remove-scripts.js + +# Check if the Node.js script executed successfully +if [ $? -ne 0 ]; then + echo "Error: Failed to modify package.json." + # Restore the original package.json before exiting + mv "$PACKAGE_JSON_BAK" "$PACKAGE_JSON" + exit 1 +fi + +# Run npm pack +npm pack + +# Capture the exit status of npm pack +PACK_STATUS=$? + +# Restore the original package.json +mv "$PACKAGE_JSON_BAK" "$PACKAGE_JSON" + +# Check if npm pack was successful +if [ $PACK_STATUS -ne 0 ]; then + echo "Error: npm pack failed." + exit 1 +fi + +echo "Successfully packed the package and restored the original package.json." diff --git a/scripts/remove-scripts.js b/scripts/remove-scripts.js new file mode 100644 index 0000000..59e0a38 --- /dev/null +++ b/scripts/remove-scripts.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +import fs from 'fs'; +import chalk from 'chalk'; + +const PACKAGE_JSON = 'package.json'; + +let packageJson; +try { + packageJson = JSON.parse(fs.readFileSync(PACKAGE_JSON, 'utf8')); +} catch (error) { + console.error(chalk.red('Error reading package.json:'), error); + process.exit(1); +} + +// Remove the postinstall and prepare scripts if they exist +if (packageJson.scripts) { + const scriptsRemoved = []; + if (packageJson.scripts.postinstall) { + delete packageJson.scripts.postinstall; + scriptsRemoved.push('postinstall'); + } + if (packageJson.scripts.prepare) { + delete packageJson.scripts.prepare; + scriptsRemoved.push('prepare'); + } + if (scriptsRemoved.length > 0) { + console.log( + chalk.green('Removed scripts: ') + chalk.yellow(scriptsRemoved.join(', ')) + ); + } else { + console.log(chalk.blue('No scripts to remove.')); + } +} else { + console.log(chalk.blue('No scripts section found in package.json.')); +} + +try { + fs.writeFileSync(PACKAGE_JSON, JSON.stringify(packageJson, null, 2)); +} catch (error) { + console.error(chalk.red('Error writing package.json:'), error); + process.exit(1); +} diff --git a/template/.husky/pre-commit b/template/.husky/pre-commit index 5a182ef..3723623 100755 --- a/template/.husky/pre-commit +++ b/template/.husky/pre-commit @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - yarn lint-staged diff --git a/template/package.json b/template/package.json index 1512d19..cfedc58 100644 --- a/template/package.json +++ b/template/package.json @@ -34,11 +34,11 @@ "format:check": "prettier --check . --ignore-unknown", "format:code": "prettier --write . --ignore-unknown", "format:deps": "syncpack format", - "husky:install": "./scripts/husky.sh", + "husky:init": "./scripts/husky.sh", "lib": "yarn workspace __library-name__", "lint": "eslint .", "lint:fix": "eslint --fix .", - "postinstall": "yarn husky:install", + "postinstall": "yarn husky:init", "prepare": "husky", "test": "yarn lib test && yarn workspace example-app test", "typecheck": "yarn lib typecheck && yarn workspace example-app typecheck" diff --git a/template/scripts/husky.sh b/template/scripts/husky.sh index eab4e75..b3e3c70 100755 --- a/template/scripts/husky.sh +++ b/template/scripts/husky.sh @@ -1,4 +1,4 @@ #!/bin/bash if [ -d '.git' ]; then - npx husky install + npx husky init fi diff --git a/yarn.lock b/yarn.lock index 7995621..1a476a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -609,6 +609,22 @@ __metadata: languageName: node linkType: hard +"@semantic-release/exec@npm:^6.0.3": + version: 6.0.3 + resolution: "@semantic-release/exec@npm:6.0.3" + dependencies: + "@semantic-release/error": "npm:^3.0.0" + aggregate-error: "npm:^3.0.0" + debug: "npm:^4.0.0" + execa: "npm:^5.0.0" + lodash: "npm:^4.17.4" + parse-json: "npm:^5.0.0" + peerDependencies: + semantic-release: ">=18.0.0" + checksum: 10c0/87c1f5dcd96e8b51cfa084ff2fd570fa1e2b6368064fba54403797636279e1159b62c199b3e8219d31189acfe8aa6f1b596f6cda6508fd3e1a7e5739c86a1a65 + languageName: node + linkType: hard + "@semantic-release/git@npm:^10.0.1": version: 10.0.1 resolution: "@semantic-release/git@npm:10.0.1" @@ -2478,7 +2494,7 @@ __metadata: languageName: node linkType: hard -"husky@npm:^9.0.11": +"husky@npm:^9.1.6": version: 9.1.6 resolution: "husky@npm:9.1.6" bin: @@ -4166,7 +4182,7 @@ __metadata: languageName: node linkType: hard -"parse-json@npm:^5.2.0": +"parse-json@npm:^5.0.0, parse-json@npm:^5.2.0": version: 5.2.0 resolution: "parse-json@npm:5.2.0" dependencies: @@ -4666,6 +4682,7 @@ __metadata: "@eslint/js": "npm:^9.1.1" "@semantic-release/changelog": "npm:^6.0.3" "@semantic-release/commit-analyzer": "npm:^13.0.0" + "@semantic-release/exec": "npm:^6.0.3" "@semantic-release/git": "npm:^10.0.1" "@semantic-release/github": "npm:^10.0.7" "@semantic-release/npm": "npm:^12.0.1" @@ -4676,7 +4693,7 @@ __metadata: eslint: "npm:^8.57.0" eslint-plugin-prettier: "npm:^5.1.3" globals: "npm:^15.0.0" - husky: "npm:^9.0.11" + husky: "npm:^9.1.6" lint-staged: "npm:^15.2.7" prettier: "npm:^3.3.2" semantic-release: "npm:^24.0.0"