npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sjofartstidningen/scripts

v1.1.2

Published

A set of useful scripts used around the project

Downloads

4

Readme

@sjofartstidningen/scripts

A collections of scripts useful while developing WordPress sites. Mainly adapted for developing www.sjofartstidningen.se.

Install the package as a development dependency inside your WordPress plugin or theme.

Installation

Install the package using npm or yarn:

$ npm install --save-dev @sjofartstidningen/scripts
$ yarn add --dev @sjofartstidningen/scripts

Dependecies

Some of the scripts in this package need wp-cli to work. Make sure that it is installad and available as wp in your environment. The commands require atleast version 2.1.0 of wp-cli to work properly since that's the version where the commands wp i18n make-pot and wp i18n make-json where introduced.

Commands

Requirements for all scripts

The scripts in here makes a few assumptions:

  • All javascript source files are located inside {project_root}/src
  • Translations are located inside {project_root}/languages
  • Build files are outputted to {project_root}/dist
  • The dist-directory also contains a assets.json-file with the following structure:
    {
      "{filepath_relative_to_src}.js": "{filepath_relative_to_dist}.{maybe_with_hash?}.js"
    }
    The package parcel-plugin-assets-list does this for you.

sst-scripts make-pot

The command make-pot is a glorified version of the wp-cli equivalent wp i18n make-pot. But that command will fail while searching thru your javascript files if the files contain any dynamic imports (import('package')).

What the script does is that it will comment out an line containing dynamic imports before running the make-pot on them. And when it's done it will restore the files as if nothing has happened.

The .pot-file will be named after the name-property in your package.json and placed inside the dist-folder.

The pot-file can then be used as a base for further translations.

Usage

$ sst-scripts make-pot

Preferably this should run after a build script.

sst-scripts make-json

The command make-json is a glorified version of the wp-cli equivalent wp i18n make-json. It will extract all translations related to your js-files and properly name them and place them inside your dist-directory.

It will use the entrypoints found inside dist/assets.json and try to find all dependecies of that file and group them into one larger translation file.

Usage

sst-scripts make-json

Preferably this should run after a build script.

Usage in PHP

The outputted json-translation files are formatted in a way that WordPress built in translations understand. The structure can be used by the @wordpress/i18n package and sent to the client using the following:

add_action('wp_enqueue_scripts', function () {
  $distPath = plugin_dir_path(__FILE__) . 'dist/';
  $distUrl = plugin_dir_url(__FILE__) . 'dist/';

  $content = file_get_contents($distPath . 'assets.json');
  $manifest = json_decode($content, true);

  foreach ($manifest as $handle => $file) {
    if (strpos($file, '.js') !== false) {
      wp_enqueue_script($handle, $distUrl . $file, ['wp-i18n'], '1.0.0', true);
      wp_set_script_translations($handle, 'domain', $distPath);
    }

    if (strpos($file, '.css') !== false) {
      wp_enqueue_style($handle, $distUrl . $file, [], '1.0.0', 'all');
    }
  }
});

sst-scripts make-aliases

Generate parcel aliases based on the wordpress-packages that exists in your project.

With parcel-bundler you can use an alias-prop in package.json to alias certain packages to local files instead of searching for them in node_modules. This is useful when working with @wordpress/{package}'s since they are generally available under window.wp.{package}.

This command will look thru your dependecies and output alias files to src/alias/wordpress-{package}.js. In it there will only be a singe export pointing to window.wp.{package}.

And during development you can just import the scripts using standard es modules:

import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';

Just make sure that you've also installed the package as a dependecy.

Usage

$ sst-scripts make-aliases

Preferably this should run after new installs (e.g as postinstall script).