1.3.15 • Published 6 months ago

packaholic v1.3.15

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

packaholic

packaholic-server, a simple implementation of packaging service based on packaholic.

Node packaging tool, support packing service.

Install

# on client
npm i packaholic -D

# on server
bun add packaholic

Usage

step 1:

define packaholic.config.ts under project root directory。

// packaholic.config.ts
import { defineConfig } from 'packaholic';

export default defineConfig({
  commands: [
    'npm run install',
    'npm run build',
  ],
  afterCommandsExec: () => {
    // upload dist dir to cdn
    // or other operations
  },
});

// also can export an function
export default (context) => {
  const { env } = context;

  return defineConfig({
    commands: [
      `npm run install -- --env=${env}`,
      'npm run build',
    ],
    afterCommandsExec: () => {
      // upload dist dir to cdn
      // or other operations
    },
  });
};

step 2:

On the packaging service, execute the runner method, which will automatically pull the project and execute the commands defined in packaholic.config.ts.

import { runner } from 'packaholic';

runner({
  source: 'local_path',
  context: {
    env: 'develop',
  },
});

try {
  await runner({
    source: 'git remote repository uri',
    repositoryRoot: './.cache_root',
    afterRepositoryCloned: () => {
    },
    onCommandExecError(err) {
      // return false to break
      return false;
    },
    afterConfigLoaded(config) {
      // config loaded
    },
    // define config filename, default is `packaholic.config.ts`
    // configFilename: 'packaholic.config.ts',
  });
} catch (err) {
  // fail
}

or run with customize bash:

import { runner } from 'packaholic';
import { spawn } from 'child_process';

runner({
  source: 'local_path',
  context: {
    env: 'develop',
  },
});

// or by Bun.spawn
const bash = spawn('bash', {
  shell: '/bin/bash',
  env: process.env,
});

try {
  await runner({
    source: 'git remote repository uri',
    repositoryRoot: './.cache_root',
    // If you need to customize some environments, such as using nvm to switch node, you can use this method.
    // packaholic will run the command in the bash object passed in.
    bash,
  });
} catch (err) {
  // fail
}

config

// packaholic.config.ts
import { defineConfig } from 'packaholic';

export default defineConfig({
  commands: [
    'npm run install',
    // start with @@ will ignore error
    '@@npm run install',
    // more configure
    {
      // replace env by `mappingEnvVariables`
      cmd: 'npm run build -- --ENV={{env}}',
      cwd: './',
      ignoreError: false,
      beforeExec: (opts) => {},
      afterExec: (opts) => {},
    },
  ],
  afterCommandsExec: (context) => {
    // upload dist dir to cdn
    // or other operations
  },
  mappingEnvVariables(context) {
    return {
      env: context.env,
    };
  },
  ignoreSpawnError: false,
});

why named packaholic

blend of "pack" and "-aholic" (from "workaholic").

1.3.15

6 months ago

1.3.14

6 months ago

1.3.13

6 months ago

1.3.12

6 months ago

1.3.11

6 months ago

1.3.10

6 months ago

1.3.9

6 months ago

1.3.8

6 months ago

1.3.7

6 months ago

1.3.6

6 months ago

1.3.5

6 months ago

1.3.4

6 months ago

1.3.3

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago