Skip to content

Commit

Permalink
chore: prettier optimization (#12869)
Browse files Browse the repository at this point in the history
* chore: prettier some ignored libs

* fix: prettierPath

* chore: prettier husky

* update yarn.lock

* fix: husky and lint-stage

* chore: add echo

* chore: sort package.json scripts

* chore: sort package.json scripts again after merge conflicts

* chore: remove lint-stage and use lint-fix

* update yarn.lock

---------

Co-authored-by: MJ☔ <[email protected]>
  • Loading branch information
0618 and zhamujun authored Jun 28, 2023
1 parent 88da2c9 commit 58c9ac1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 253 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.yarn
.prettierignore
yarn.lock
packages/*/build
packages/*/lib
coverage
Expand All @@ -15,3 +17,7 @@ packages/amplify-e2e-tests/amplify-e2e-reports
packages/amplify-environment-parameters/src/schemas/BackendParameters.schema.json
packages/amplify-nodejs-function-runtime-provider/src/__tests__/utils/handlerWithSyntaxError.js
packages/amplify-velocity-template/src/parse/velocity.yy

# Exceptions:
!packages/amplify-category-hosting/lib
!packages/amplify-frontend-*/lib
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"**/.pnp.*": true
},
"typescript.enablePromptUseWorkspaceTsdk": true,
"prettier.prettierPath": "../node_modules/prettier",
"prettier.prettierPath": "./node_modules/prettier",
"jest.jestCommandLine": "./node_modules/.bin/jest"
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"build": "lerna run build",
"check-version-conflicts:beta": "yarn ts-node ./scripts/check-version.ts beta",
"check-version-conflicts:release": "yarn ts-node ./scripts/check-version.ts",
"cloud-e2e": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2E'",
"cloud-e2e-beta": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2EBeta'",
"cloud-e2e-local": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2ELocal'",
"clean": "lerna run clean && yarn rimraf tsconfig.tsbuildinfo && lerna clean --yes && yarn rimraf node_modules",
"cloud-e2e-beta": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2EBeta'",
"cloud-e2e-circleci-with-rc": "CURR_BRANCH=$(git branch | awk '/\\*/{printf \"%s\", $2}') && UPSTREAM_BRANCH=run-e2e-with-rc/$USER/$CURR_BRANCH && git push $(git remote -v | grep aws-amplify/amplify-cli | head -n1 | awk '{print $1;}') $CURR_BRANCH:$UPSTREAM_BRANCH --no-verify --force-with-lease && echo \"\n\n 🏃 E2E test are running at:\nhttps://app.circleci.com/pipelines/github/aws-amplify/amplify-cli?branch=$UPSTREAM_BRANCH\"",
"cloud-e2e-circleci": "CURR_BRANCH=$(git branch | awk '/\\*/{printf \"%s\", $2}') && UPSTREAM_BRANCH=run-e2e/$USER/$CURR_BRANCH && git push $(git remote -v | grep aws-amplify/amplify-cli | head -n1 | awk '{print $1;}') $CURR_BRANCH:$UPSTREAM_BRANCH --no-verify --force-with-lease && echo \"\n\n 🏃 E2E test are running at:\nhttps://app.circleci.com/pipelines/github/aws-amplify/amplify-cli?branch=$UPSTREAM_BRANCH\"",
"cloud-e2e-local": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2ELocal'",
"cloud-e2e": "bash -c 'source ./scripts/cloud-e2e.sh && cloudE2E'",
"commit": "git-cz",
"coverage:collect": "ts-node ./scripts/collect-test-coverage.ts",
"coverage": "codecov || exit 0",
Expand All @@ -29,16 +29,16 @@
"link-aa-win": "node ./scripts/link-bin.js packages/amplify-app/bin/amplify-app amplify-app-dev",
"link-dev": "mkdir -p .bin/ && cd packages/amplify-cli && ln -s \"$(pwd)/bin/amplify\" ../../.bin/amplify-dev && cd ../../",
"link-win": "node ./scripts/link-bin.js packages/amplify-cli/bin/amplify amplify-dev",
"lint-check-package-json": "yarn eslint --no-eslintrc --config .eslint.package.json.js '**/package.json'",
"lint-check": "yarn eslint . --ext .js,.jsx,.ts,.tsx --max-warnings=835",
"lint-fix": "git diff --name-only --cached --diff-filter d | grep -E '\\.(js|jsx|ts|tsx)$' | xargs eslint --fix --quiet",
"lint-fix-package-json": "yarn lint-check-package-json --fix",
"lint-check-package-json": "yarn eslint --no-eslintrc --config .eslint.package.json.js '**/package.json'",
"lint-fix": "git diff --name-only --cached --diff-filter d | grep -E '\\.(js|jsx|ts|tsx)$' | xargs eslint --fix --quiet",
"mergewords": "yarn ts-node ./scripts/handle-dict-conflicts.ts",
"pkg-all-local": "yarn verdaccio-clean && yarn verdaccio-start && yarn verdaccio-connect && yarn publish-to-verdaccio && yarn pkg-all && yarn verdaccio-disconnect",
"pkg-all": "bash -c 'source .circleci/local_publish_helpers.sh && generatePkgCli'",
"pkg-clean": "rimraf build out pkg/node_modules pkg/yarn.lock",
"prettier-check": "yarn prettier --check .",
"prettier-changes": "git diff --name-only --diff-filter MRA dev | xargs yarn prettier --write",
"prettier-check": "yarn prettier --check .",
"prettier-write": "yarn prettier --write .",
"production-build": "lerna run build --concurrency 3 --stream",
"promote-rc": "./scripts/promote-rc.sh",
Expand All @@ -51,9 +51,9 @@
"smoketest": "lerna run smoketest --output-style=stream-without-prefixes",
"smoketest@latest": "CLI_VERSION=latest lerna run smoketest --output-style=stream-without-prefixes",
"smoketest@rc": "CLI_VERSION=rc lerna run smoketest --output-style=stream-without-prefixes",
"split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts && git add .circleci/config.yml",
"split-e2e-tests-codebuild": "yarn ts-node ./scripts/split-e2e-tests-codebuild.ts",
"split-e2e-tests-codebuild-single": "yarn ts-node ./scripts/generate_single_test_buildspec_codebuild.ts",
"split-e2e-tests-codebuild": "yarn ts-node ./scripts/split-e2e-tests-codebuild.ts",
"split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts && git add .circleci/config.yml",
"test-changed": "lerna run test --since dev",
"test-ci": "lerna run test --concurrency 4 -- --ci -i",
"test": "lerna run test --concurrency 1",
Expand Down Expand Up @@ -85,7 +85,7 @@
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "yarn build-tests-changed && yarn split-e2e-tests",
"pre-commit": "./scripts/package-json-check.sh && yarn verify-commit"
"pre-commit": "yarn prettier-changes && yarn lint-fix && ./scripts/package-json-check.sh && yarn verify-commit"
}
},
"author": "Amazon Web Services",
Expand Down Expand Up @@ -139,7 +139,7 @@
"eslint-plugin-spellcheck": "^0.0.17",
"execa": "^5.1.1",
"glob": "^7.2.0",
"husky": "^3.1.0",
"husky": "^8.0.3",
"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-report": "^3.0.0",
"istanbul-reports": "^3.1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async function configure(context) {
delete context.exeInfo.template.Resources.BucketPolicy;
delete context.exeInfo.template.Resources.S3Bucket.Properties.AccessControl;
}
}

}

if (context.exeInfo.template.Resources.CloudFrontDistribution) {
const { DistributionConfig } = context.exeInfo.template.Resources.CloudFrontDistribution.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ async function run(context, distributionDirPath) {

const hasCloudFront = !!context?.exeInfo?.template?.Resources?.CloudFrontDistribution;

const uploadFileTasks = sortUploadFiles(fileList)
.map(filePath => () => uploadFile(s3Client, hostingBucketName, distributionDirPath, filePath, hasCloudFront));
const uploadFileTasks = sortUploadFiles(fileList).map(
(filePath) => () => uploadFile(s3Client, hostingBucketName, distributionDirPath, filePath, hasCloudFront),
);

const spinner = new Ora('Uploading files.');
try {
Expand All @@ -31,8 +32,8 @@ async function run(context, distributionDirPath) {
}

function sortUploadFiles(fileList) {
const filesToUploadLast = "index.html";
const sortFiles = (fileA, fileB) => fileA.includes(filesToUploadLast) ? 1 : fileB.includes(filesToUploadLast) ? -1 : 0;
const filesToUploadLast = 'index.html';
const sortFiles = (fileA, fileB) => (fileA.includes(filesToUploadLast) ? 1 : fileB.includes(filesToUploadLast) ? -1 : 0);

return fileList.sort(sortFiles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const fs = require('fs-extra');
const path = require('path');
const mime = require('mime-types');


async function uploadFile(s3Client, hostingBucketName, distributionDirPath, filePath, hasCloudFront) {
let relativeFilePath = path.relative(distributionDirPath, filePath);
// make Windows-style relative paths compatible to S3
Expand All @@ -26,6 +25,5 @@ async function uploadFile(s3Client, hostingBucketName, distributionDirPath, file
}

module.exports = {
uploadFile
uploadFile,
};

Loading

0 comments on commit 58c9ac1

Please sign in to comment.