1.0.0 • Published 5 years ago

dbz-flame-scripts v1.0.0

Weekly downloads
388
License
-
Repository
-
Last release
5 years ago

🔥🔥 Flame scripts 🔥🔥 frontend mafia

Usage 🚀

yarn add dbz-flame-scripts

Development usage

# to be able to link the package
cd dbz-flame-scripts
yarn link

# to use the local package within your app instead of npm’s version
cd app
yarn link dbz-flame-scripts # to use local linked dbz-flame-scripts
yarn unlink dbz-flame-script # to use package.json’s version

Commands 🎮

build [options]  Creates application bundles with Webpack to the /build folder

package.json:
  specify a custom webpack configuration in flame.webpackConfig
  webpack-merge will combine that with the base webpack configuration

[options]
  --no-ssr
  --debug
  --verbose
  --analyze, --analyse
  --colors
  --webpackConfig

start [options]  Launches app using BrowserSync in Webpack watch mode

package.json:
  specify a custom launch url in: flame.startPath
  specify a custom webpack configuration in flame.webpackConfig
  webpack-merge will combine that with the base webpack configuration

env.ini
  takes HOST and PORT and to launch the server with

[options]
  --webpackConfig

deploy <env>     Deploy app to environment

Under the hood:
  git commit --amend --no-edit
  created and pushes a tag "dbz_{branch}_release_{env}_{timestamp}"

<env>:
  pw
  tech
  cc
  red
  bid
  pro
  space
  prod|production

vault <env>      Fetches environment variables from vault and writes it into
a .env file in the projects directory.

package.json:
  specify the vault app name in: flame.vaultAppName

<env>:
  pw
  tech
  cc
  red
  bid
  pro
  space
  production

syncS3 <env>     Deploy app’s build/public folder to aws s3

package.json:
  specify the aws s3 path in: flame.awsS3Path

<env>:
  pw
  tech
  cc
  red
  bid
  pro
  space
  production

test [options]   Tests app using Jest

package.json:
  the jest section will be merged with the base jest configuration

[options]
  -w, --watch
  --color

Devs: to keep this up-to-date, after updating the descriptions for a command, copy/paste the output of flame-scripts --help here.

flame section in package.json

{
  "flame": {
    // For some repo’s we don’t want to open up the browser displaying a 404 page
    // startPath will specify the path to launch the browser in when running the
    // command: flame-scripts start
    "startPath": "/en/property-for-rent/residential/", // Optional

    // vault paths look like this:
    // secret/beta/dashboard-frontend/dashboard-frontend-beta-pw
    // once we run the command: "flame-scripts vault pw", we can figure out
    // the environment from the arguments, but we will still need to know the
    // app name, which is why we need a specified vaultAppName:
    // `secret/beta/${vaultAppName}/${vaultAppName}-beta-${env}`
    "vaultAppName": "property-lpv-desktop", // Required

    // aws s3 paths look like this:
    // s3://dbz-pw-static/property/desktop/latest
    // once we run the command: "flame-scripts syncS3 pw", we will push the
    // build/public/ folder to the correct s3 bucket + specified path
    // `dbz-${env}-static/${awsS3Path}`
    "awsS3Path": "property/desktop/latest", // Required

    // The specified webpack config will be merged using webpack smart merge:
    // https://github.com/survivejs/webpack-merge
    // we check whether its exporting a single object (only client build) or an
    // array of client and server configs. In the latter case the first config is
    // always the client build and the second the server. in case you need to do
    // conditional checks, make sure to check how its done in the base configs
    // (configs/webpack.config.js) and that you do it consistently in the same
    // manner.
    "webpackConfig": "config/webpack.config.js", // Optional

    // This is to specify whether we should start/build with a server side build
    // alternatively you can use the flag --no-ssr in the same commands to disable
    // the server bundle.
    "webpackServer": true, // Optional

    // proxy option while running the command flame-scripts start
    // https://webpack.js.org/configuration/dev-server/#devserver-proxy
    // Optional
    "webpackDevServerProxy": {
      "/api": {
        "target": "https://dubai.dubizzle.space",
        "pathRewrite": {
          "^/api": "",
          "url=http://localhost:5050/api": "url=https://dubai.dubizzle.space"
        },
        "secure": false
      }
    }
  }
}

How does it work?

The entry file is bin/flame-scripts. It’s internally using commander to build the CLI: https://github.com/tj/commander.js/, it sets the package.json config and registers the commands from commands/index.js. The scripts are originally taken from: https://github.com/kriasoft/react-starter-kit/tree/master/tools as it seems to be the most complete webpack server-side-rending solution out there.

Config

The first thing we do for each command is get the project’s package.json and get the flame and jest configs. We can then use this data inside our scripts like so:

const config = require('configs/flame.config');

// the flame section in the package.json will be set directly to the config object
const awsPath = config.awsS3Path;

// whereas the jest config will be set to the jest key
const jest = config.jest;

// additionally we set the projectDir, since we will need to be able to access it later on
const projectDir = config.projectDir;

Commands

Commands can be added by creating a file in the commands/ folder and by adding it to the commands/index.js. Inside the bin file we loop over them as seen below:

// bin/flame-scripts
const commands = require('../commands');
commands.forEach(command => command(program));
Conventions

Descriptions should be listed at the top for readabilty and any checks should happen before we run the script. We probably could write run(require('../scripts/deploy'), env) in a better way, but this way it works with the current implementation of react-starter-kit’s run() script.

// commands/deploy.js
const description = `Deploy app to environment

Under the hood:
  git commit --amend --no-edit
  created and pushes a tag "dbz_{branch}_release_{env}_{timestamp}"

<env>:
  ${environments.join('\n  ')}
`;

function deploy(program) {
  program
    .command('deploy <env>')
    .description(description)
    .action(() => {
      /* eslint-disable global-require, no-console */
      const env = process.argv[3];

      if (!environments.includes(env)) {
        console.log(`Invalid deploy environment "${env}"

Valid options:
  ${environments.join('\n  ')}`);
        process.exit(1);
      }

      run(require('../scripts/deploy'), env).catch(err => {
        console.error(err.stack);
        process.exit(1);
      });
    });
}

Environments

To keep a central place for all the environments, we have a single config for it in configs/environments.js. The commands deploy vault syncS3 are all referencing this.

Issues encountered

If a command is not able to run, it’s likely due to the fact that some dependency is trying to run the version of your project’s dependency. Generally, you can simply remove that dependency and it should work.

If the project has the dependency react-scripts, the command test will not work properly.

Build/start issues related to:

acorn, chalk

Can be resolve by reinstalling webpack to flame-scripts: yarn remove webpack && yarn add webpack

Babel config

Remove any babel configs (.babelrc) from your project’s directory, otherwise it will get picked up instead by babel and/or jest. We are using a central babel.config.js in the configs folder.

@babel/core@babel/node@babel/plugin-proposal-class-properties@babel/plugin-proposal-decorators@babel/plugin-proposal-do-expressions@babel/plugin-proposal-export-namespace-from@babel/plugin-proposal-function-sent@babel/plugin-proposal-json-strings@babel/plugin-proposal-numeric-separator@babel/plugin-proposal-throw-expressions@babel/plugin-syntax-dynamic-import@babel/plugin-syntax-import-meta@babel/plugin-transform-modules-commonjs@babel/plugin-transform-object-assign@babel/plugin-transform-react-constant-elements@babel/plugin-transform-react-inline-elements@babel/polyfill@babel/preset-env@babel/preset-react@svgr/webpackautoprefixeraws-sdkaxiosbabel-corebabel-jestbabel-loaderbabel-plugin-react-remove-propertiesbabel-plugin-transform-dynamic-importbabel-plugin-transform-react-remove-prop-typesbody-parserbrowser-syncbrowser-sync-webpack-pluginchokidarcommandercss-loadercssnanodotenveslinteslint-config-airbnbeslint-config-prettiereslint-loadereslint-plugin-css-moduleseslint-plugin-importeslint-plugin-jsx-a11yeslint-plugin-prettiereslint-plugin-reactexpressexpress-http-proxyfile-loaderfront-matterglobhtml-webpack-pluginhtml-webpack-pug-pluginhuskyiniinterpolate-html-pluginjestjest-configlint-stagedmarkdown-itmimemini-css-extract-pluginminimistmkdirpmomentmoment-timezonenode-fetchnode-sassnull-loaderpixrempleeease-filterspostcsspostcss-calcpostcss-color-functionpostcss-custom-mediapostcss-custom-propertiespostcss-custom-selectorspostcss-flexbugs-fixespostcss-importpostcss-loaderpostcss-media-minmaxpostcss-nestedpostcss-nestingpostcss-pseudoelementspostcss-selector-matchespostcss-selector-notprettierpromiseraw-loaderreactreact-deep-force-updatereact-dev-utilsreact-error-overlayreact-loadablerimrafsass-loaderserve-faviconsvg-url-loaderurl-loaderurl-polyfillurl-search-params-polyfillwebpackwebpack-assets-manifestwebpack-bundle-analyzerwebpack-dev-middlewarewebpack-dev-serverwebpack-hot-clientwebpack-hot-middlewarewebpack-mergewebpack-node-externalspretty-quick
1.0.0

5 years ago

0.2.1

5 years ago

0.2.0-beta

5 years ago

0.2.0

5 years ago

0.1.29-gneric

5 years ago

0.1.30

5 years ago

0.1.29

5 years ago

0.1.28

5 years ago

0.1.27

5 years ago

0.1.26

5 years ago

0.1.25

5 years ago

0.1.24

5 years ago

0.1.23

5 years ago

0.1.22

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.94

5 years ago

0.0.93

5 years ago

0.0.92

5 years ago

0.0.91

5 years ago

0.0.90

5 years ago

0.0.89

5 years ago

0.0.88

5 years ago

0.0.87

5 years ago

0.0.86

5 years ago

0.0.85

5 years ago

0.0.84

5 years ago

0.0.83

5 years ago

0.0.82

5 years ago

0.0.81

5 years ago

0.0.80

5 years ago

0.0.79

5 years ago

0.0.78

5 years ago

0.0.77

5 years ago

0.0.76

5 years ago

0.0.75

5 years ago

0.0.74

5 years ago

0.0.73

5 years ago

0.0.72

5 years ago

0.0.71

5 years ago

0.0.70

5 years ago

0.0.69

5 years ago

0.0.68

5 years ago

0.0.67

5 years ago

0.0.66

5 years ago

0.0.65

5 years ago

0.0.64

5 years ago

0.0.63

5 years ago

0.0.62

5 years ago

0.0.61

5 years ago

0.0.59

5 years ago

0.0.58

5 years ago

0.0.57

5 years ago

0.0.56

5 years ago

0.0.55

5 years ago

0.0.54

5 years ago

0.0.53

5 years ago

0.0.52

5 years ago

0.0.51

5 years ago

0.0.50

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago