Skip to content

Commit

Permalink
Refactor build platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderby committed May 17, 2024
1 parent 3e4f757 commit 6e49d9b
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 34 deletions.
3 changes: 1 addition & 2 deletions tasks/bundle-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import typescript from 'typescript';
import fs from 'node:fs';
import os from 'node:os';
import {createTask} from './task.js';
import paths from './paths.js';
const {rootDir, rootPath} = paths;
import {rootDir, rootPath} from './paths.js';

async function getVersion() {
const file = await fs.promises.readFile(new URL('../package.json', import.meta.url), 'utf8');
Expand Down
4 changes: 2 additions & 2 deletions tasks/bundle-css.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-check
import less from 'less';
import path from 'node:path';
import paths from './paths.js';
import {getDestDir, rootPath} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {readFile, writeFile} from './utils.js';
const {getDestDir, PLATFORM, rootPath} = paths;

/** @typedef {import('./types').CSSEntry} CSSEntry */

Expand Down
4 changes: 2 additions & 2 deletions tasks/bundle-html.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check
import paths_ from './paths.js';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {writeFile} from './utils.js';
const {getDestDir, PLATFORM} = paths_;

/** @typedef {import('./types').HTMLEntry} HTMLEntry */

Expand Down
3 changes: 1 addition & 2 deletions tasks/bundle-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import rollupPluginReplace from '@rollup/plugin-replace';
/** @type {any} */
import rollupPluginTypescript from '@rollup/plugin-typescript';
import typescript from 'typescript';
import paths from './paths.js';
import {getDestDir, rootDir, rootPath} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
const {PORT} = reload;
import {createTask} from './task.js';
const {getDestDir, rootDir, rootPath} = paths;

/** @typedef {import('./types').JSEntry} JSEntry */

Expand Down
4 changes: 2 additions & 2 deletions tasks/bundle-locales.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-check
import fs from 'node:fs/promises';
import path from 'node:path';
import paths from './paths.js';
import {getDestDir, rootPath} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {readFile, writeFile} from './utils.js';
const {getDestDir, PLATFORM, rootPath} = paths;

async function bundleLocale(/** @type {string} */filePath) {
let file = await readFile(filePath);
Expand Down
4 changes: 2 additions & 2 deletions tasks/bundle-manifest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check
import path from './paths.js';
import {getDestDir, rootPath} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {readJSON, writeJSON} from './utils.js';
const {PLATFORM, getDestDir, rootPath} = path;

async function patchManifest(platform, debug, watch, test) {
const manifest = await readJSON(rootPath('src/manifest.json'));
Expand Down
7 changes: 4 additions & 3 deletions tasks/bundle-signature.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @ts-check
import paths from './paths.js';
import {readFile} from 'node:fs/promises';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import {createTask} from './task.js';
import {copyFile, getPaths, readJSON, readFile, writeFile, fileExists} from './utils.js';
import {copyFile, getPaths, readJSON, writeFile, fileExists} from './utils.js';
import {createHash} from 'node:crypto';
const {getDestDir, PLATFORM} = paths;

function serializeHashManifest(entries) {
const lines = [];
Expand Down
4 changes: 2 additions & 2 deletions tasks/clean.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-check
import paths from './paths.js';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import {createTask} from './task.js';
import {removeFolder} from './utils.js';
const {getDestDir, PLATFORM} = paths;

async function clean({platforms, debug}) {
const enabledPlatforms = Object.values(PLATFORM).filter((platform) => platform !== PLATFORM.API && platforms[platform]);
Expand Down
3 changes: 1 addition & 2 deletions tasks/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {runTasks} from './task.js';
import zip from './zip.js';
import signature from './bundle-signature.js';

import paths from './paths.js';
const {PLATFORM} = paths;
import {PLATFORM} from './platform.js';

const __filename = join(fileURLToPath(import.meta.url), '../build.js');

Expand Down
4 changes: 2 additions & 2 deletions tasks/code-style.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check
import prettier from 'prettier';
import paths from './paths.js';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import {createTask} from './task.js';
import {readFile, writeFile, getPaths} from './utils.js';
const {getDestDir, PLATFORM} = paths;

/** @type {import('prettier').Options} */
const options = {
Expand Down
4 changes: 2 additions & 2 deletions tasks/copy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check
import paths_ from './paths.js';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {pathExists, copyFile, getPaths} from './utils.js';
const {getDestDir, PLATFORM} = paths_;

const srcDir = 'src';

Expand Down
16 changes: 9 additions & 7 deletions tasks/paths.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {dirname, join} from 'node:path';
import {createRequire} from 'node:module';
const rootDir = dirname(createRequire(import.meta.url).resolve('../package.json'));
const rootPath = (...paths) => join(rootDir, ...paths);

export default {
getDestDir: function ({debug, platform}) {
const buildTypeDir = `build/${debug ? 'debug' : 'release'}`;
return `${buildTypeDir}/${platform}`;
},
export const rootDir = dirname(createRequire(import.meta.url).resolve('../package.json'));
export const rootPath = (...paths) => join(rootDir, ...paths);

export function getDestDir({debug, platform}) {
const buildTypeDir = `build/${debug ? 'debug' : 'release'}`;
return `${buildTypeDir}/${platform}`;
}

export default {
getDestDir,
rootDir,
rootPath,
};
4 changes: 2 additions & 2 deletions tasks/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import fs from 'node:fs';
import {exec} from 'node:child_process';
import yazl from 'yazl';
import paths from './paths.js';
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import {createTask} from './task.js';
import {getPaths} from './utils.js';
const {getDestDir, PLATFORM} = paths;

/**
* @param {object} details
Expand Down
3 changes: 1 addition & 2 deletions tests/inject/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import rollupPluginTypescript from '@rollup/plugin-typescript';
import typescript from 'typescript';

import {createEchoServer} from './support/echo-server.js';
import paths from '../../tasks/paths.js';
const {rootPath} = paths;
import {rootPath} from '../../tasks/paths.js';

/**
* @param {Partial<LocalConfig>} config
Expand Down

0 comments on commit 6e49d9b

Please sign in to comment.