Commit 1d1c704b authored by Guillaume Girol's avatar Guillaume Girol
Browse files

zap-chip: init at 2024.09.27

parent 20499cc1
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
diff --git a/src-script/pack-apack-win-linux.js b/src-script/pack-apack-win-linux.js
index 0120f9f9..41fcf99c 100644
--- a/src-script/pack-apack-win-linux.js
+++ b/src-script/pack-apack-win-linux.js
@@ -6,12 +6,12 @@ exports.default = async function (context) {
     context.electronPlatformName === 'win32' ||
     context.electronPlatformName === 'linux'
   ) {
-    return scriptUtil.executeCmd({}, 'npx', [
-      'copyfiles',
-      '-V',
-      '-f',
-      path.resolve(context.outDir, '../apack.json'),
-      context.appOutDir
+    return scriptUtil.executeCmd({}, 'install', [
+      '-m466',
+      '-v',
+      '-Dt',
+      context.appOutDir,
+      path.resolve(context.outDir, '../apack.json')
     ])
   }
 }
diff --git a/src-script/script-util.js b/src-script/script-util.js
index 1897c2b8..9faa5f20 100644
--- a/src-script/script-util.js
+++ b/src-script/script-util.js
@@ -181,11 +181,9 @@ async function rebuildBackendIfNeeded() {
   return scriptUtil
     .executeCmd({}, 'npx', ['tsc', '--build', './tsconfig.json'])
     .then(() =>
-      scriptUtil.executeCmd({}, 'npx', [
-        'copyfiles',
-        './src-electron/**/*.sql',
-        './src-electron/icons/*',
-        './dist/'
+      scriptUtil.executeCmd({}, 'bash', [
+        '-xec',
+        'for i in ./src-electron/**/*.sql ./src-electron/icons/*; do install -m 644 -Dt dist/$(dirname $i) $i; done'
       ])
     )
 }
+28 −0
Original line number Diff line number Diff line
diff --git a/src-script/script-util.js b/src-script/script-util.js
index 1897c2b8..aaf9a08b 100644
--- a/src-script/script-util.js
+++ b/src-script/script-util.js
@@ -196,23 +194,6 @@ async function rebuildBackendIfNeeded() {
  * ads the timestamp and saves it into .version.json
  */
 async function stampVersion() {
-  try {
-    let out = await getStdout('{"hash": null,"date": null}', 'git', [
-      'log',
-      '-1',
-      '--format={"hash": "%H","timestamp": %ct}'
-    ])
-    let version = JSON.parse(out)
-    let d = new Date(version.timestamp * 1000) // git gives seconds, Date needs milliseconds
-    let result = await setPackageJsonVersion(d, 'real')
-    version.date = d
-    version.zapVersion = result.version
-    let versionFile = path.join(__dirname, '../.version.json')
-    console.log(`🔍 Git commit: ${version.hash} from ${version.date}`)
-    await fsp.writeFile(versionFile, JSON.stringify(version))
-  } catch (err) {
-    console.log(`Error retrieving version: ${err}`)
-  }
 }
 
 /**
+74 −0
Original line number Diff line number Diff line
{
  lib,
  buildNpmPackage,
  electron_31,
  fetchFromGitHub,
  writers,
}:

let
  electron = electron_31;
in
buildNpmPackage rec {
  pname = "zap-chip";
  version = "2024.09.27";

  src = fetchFromGitHub {
    owner = "project-chip";
    repo = "zap";
    rev = "v${version}";
    hash = "sha256-Dc5rU4jJ6aJpk8mwL+XNSmtisYxF86VzXd/Aacd4p0o=";
  };

  npmDepsHash = "sha256-ZFksGwKlXkz6XTs2QdalGB0hR16HfB69XQOFWI9X/KY=";

  env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
  env.CYPRESS_INSTALL_BINARY = "0";

  patches = [
    # the build system creates a file `.version.json` from a git command
    # as we don't build from a git repo, we create the file manually in postPatch
    # and this patch disables the logic running git
    ./dont-get-version-from-git.patch
    # some files are installed via `npx copyfiles` which tries to download
    # code from the internet. This fails in the sandbox. This patch replaces the
    # logic by running "normal" commands instead of `npx copyfiles`
    ./dont-download-copyfiles-to-copy-files.patch
  ];

  postPatch =
    let
      versionJson = {
        hash = version;
        timestamp = 1;
        date = version;
        zapVersion = version;
      };
    in
    ''
      cp ${writers.writeJSON "zapversion.json" versionJson} .version.json
      cat .version.json
    '';

  postBuild = ''
    npm exec electron-builder -- \
      --dir \
      -c.electronDist=${electron.dist} \
      -c.electronVersion=${electron.version}
  '';

  postInstall = ''
    # this file is also used at runtime
    install -m644 .version.json $out/lib/node_modules/zap/
    # home-assistant chip-* python packages need the executable under the name zap-cli
    ln -s $out/bin/zap $out/bin/zap-cli
  '';

  meta = {
    description = "Generic generation engine and user interface for applications and libraries based on Zigbee Cluster Library (ZCL)";
    changelog = "https://github.com/project-chip/zap/releases/tag/v${version}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ symphorien ];
    mainProgram = "zap-cli";
  };
}