codeplay-common 4.10.4 → 4.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.10.4",
4
- "description": "Common build scripts and files",
5
- "scripts": {
6
- "postinstall": "node scripts/sync-files.js",
7
- "preinstall": "node scripts/uninstall.js"
8
- },
9
- "dependencies": {
10
- "adm-zip": "^0.6.1",
11
- "plist": "^3.1.0"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/merbin2012/codeplay-common.git"
16
- },
17
- "author": "Codeplay Technologies",
18
- "license": "MIT",
19
- "files": [
20
- "files/",
21
- "scripts/",
22
- "README.md",
23
- "CHANGELOG.md",
24
- "RELEASE_NOTES.md",
25
- "LICENSE"
26
- ]
27
- }
1
+ {
2
+ "name": "codeplay-common",
3
+ "version": "4.10.6",
4
+ "description": "Common build scripts and files",
5
+ "scripts": {
6
+ "postinstall": "node scripts/sync-files.js",
7
+ "preinstall": "node scripts/uninstall.js"
8
+ },
9
+ "dependencies": {
10
+ "adm-zip": "^0.6.1",
11
+ "plist": "^3.1.0"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/merbin2012/codeplay-common.git"
16
+ },
17
+ "author": "Codeplay Technologies",
18
+ "license": "MIT",
19
+ "files": [
20
+ "files/",
21
+ "scripts/",
22
+ "README.md",
23
+ "CHANGELOG.md",
24
+ "RELEASE_NOTES.md",
25
+ "LICENSE"
26
+ ]
27
+ }
@@ -1,86 +1,111 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
-
5
- function migrateAppScripts(projectRoot) {
6
- const root = path.resolve(projectRoot);
7
- const source = path.resolve(root, 'scripts');
8
- const destination = path.resolve(root, 'scripts-common');
9
- if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
10
- if (!fs.existsSync(source)) return;
11
- // Preflight the entire tree before moving anything. Never overwrite a
12
- // different existing file or follow a linked directory.
13
- function check(from, to) {
14
- if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
15
- if (!fs.existsSync(to)) return;
16
- if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
17
- for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
18
- } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
19
- throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
20
- }
21
- }
22
- function move(from, to) {
23
- if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
24
- if (fs.statSync(from).isDirectory()) {
25
- for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
26
- fs.rmdirSync(from);
27
- } else fs.unlinkSync(from); // Identical existing file, verified above.
28
- }
29
- check(source, destination);
30
- move(source, destination);
31
- }
32
-
33
- function findProjectRoot() {
34
- // npm may execute a file: dependency's lifecycle in its source directory.
35
- // INIT_CWD identifies the app that invoked npm in that case.
36
- for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
37
- if (!candidate) continue;
38
- const root = path.resolve(candidate);
39
- const file = path.join(root, 'package.json');
40
- if (!fs.existsSync(file)) continue;
41
- if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
42
- }
43
- return null;
44
- }
45
-
46
- function install(options = {}) {
47
- const resolved = options.projectRoot || findProjectRoot();
48
- if (!resolved) {
49
- console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
50
- return null;
51
- }
52
- const projectRoot = path.resolve(resolved);
53
- const commonFiles = path.resolve(__dirname, '../files');
54
- const packagePath = path.join(projectRoot, 'package.json');
55
- if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
56
- const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
57
- const scripts = updateBuildScripts(pkg.scripts || {});
58
- migrateAppScripts(projectRoot);
59
- // Copy the common templates into each application for local testing.
60
- const buildSource = path.join(commonFiles, 'buildCodeplay');
61
- const buildTarget = path.join(projectRoot, 'buildCodeplay');
62
- fs.mkdirSync(buildTarget, { recursive: true });
63
- for (const name of fs.readdirSync(buildSource)) {
64
- const target = path.join(buildTarget, name);
65
- if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
66
- fs.cpSync(path.join(buildSource, name), target, { recursive: true });
67
- }
68
- fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
69
- if (options.copyAssets !== false) {
70
- for (const name of fs.readdirSync(commonFiles)) {
71
- if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
72
- fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
73
- }
74
- }
75
- pkg.scripts = scripts;
76
- fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
77
- // Cleanup happens only after replacement assets and package commands exist.
78
- removeVersionedBuildScripts(projectRoot);
79
- console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
80
- // Coupled IAP/AdMob/Home migrations run together during before-build.
81
- return pkg;
82
- }
83
- module.exports = { install, findProjectRoot, migrateAppScripts };
84
- if (require.main === module) {
85
- try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
+
5
+ function migrateAppScripts(projectRoot) {
6
+ const root = path.resolve(projectRoot);
7
+ const source = path.resolve(root, 'scripts');
8
+ const destination = path.resolve(root, 'scripts-common');
9
+ if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
10
+ if (!fs.existsSync(source)) return;
11
+ // Preflight the entire tree before moving anything. Never overwrite a
12
+ // different existing file or follow a linked directory.
13
+ function check(from, to) {
14
+ if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
15
+ if (!fs.existsSync(to)) return;
16
+ if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
17
+ for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
18
+ } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
19
+ throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
20
+ }
21
+ }
22
+ function move(from, to) {
23
+ if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
24
+ if (fs.statSync(from).isDirectory()) {
25
+ for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
26
+ fs.rmdirSync(from);
27
+ } else fs.unlinkSync(from); // Identical existing file, verified above.
28
+ }
29
+ check(source, destination);
30
+ move(source, destination);
31
+ }
32
+
33
+ function migrateAppConfigurator(projectRoot) {
34
+ const filePath = path.join(projectRoot, 'scripts-common', 'configure-codeplay-common.js');
35
+ if (!fs.existsSync(filePath)) return;
36
+ const original = fs.readFileSync(filePath, 'utf8');
37
+ let updated = original;
38
+ // Preserve app-specific configuration; extend only the known legacy lookups.
39
+ for (const [variable, script] of [
40
+ ['buildFile', 'codeplayBeforeBuild.js'],
41
+ ['packageIdFile', 'packageidBaseModification.js'],
42
+ ]) {
43
+ updated = updated.replace(
44
+ `const ${variable} = fs.readdirSync(buildDir)`,
45
+ `const ${variable} = fs.existsSync(path.join(buildDir, '${script}'))\n` +
46
+ ` ? '${script}'\n` +
47
+ ` : fs.readdirSync(buildDir)`
48
+ );
49
+ }
50
+ updated = updated.replace(
51
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts/run-codeplay-sync-after.js';",
52
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts-common/run-codeplay-sync-after.js';"
53
+ );
54
+ if (updated !== original) fs.writeFileSync(filePath, updated, 'utf8');
55
+ }
56
+
57
+ function findProjectRoot() {
58
+ // npm may execute a file: dependency's lifecycle in its source directory.
59
+ // INIT_CWD identifies the app that invoked npm in that case.
60
+ for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
61
+ if (!candidate) continue;
62
+ const root = path.resolve(candidate);
63
+ const file = path.join(root, 'package.json');
64
+ if (!fs.existsSync(file)) continue;
65
+ if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
66
+ }
67
+ return null;
68
+ }
69
+
70
+ function install(options = {}) {
71
+ const resolved = options.projectRoot || findProjectRoot();
72
+ if (!resolved) {
73
+ console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
74
+ return null;
75
+ }
76
+ const projectRoot = path.resolve(resolved);
77
+ const commonFiles = path.resolve(__dirname, '../files');
78
+ const packagePath = path.join(projectRoot, 'package.json');
79
+ if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
80
+ const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
81
+ const scripts = updateBuildScripts(pkg.scripts || {});
82
+ migrateAppScripts(projectRoot);
83
+ // Copy the common templates into each application for local testing.
84
+ const buildSource = path.join(commonFiles, 'buildCodeplay');
85
+ const buildTarget = path.join(projectRoot, 'buildCodeplay');
86
+ fs.mkdirSync(buildTarget, { recursive: true });
87
+ for (const name of fs.readdirSync(buildSource)) {
88
+ const target = path.join(buildTarget, name);
89
+ if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
90
+ fs.cpSync(path.join(buildSource, name), target, { recursive: true });
91
+ }
92
+ fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
93
+ if (options.copyAssets !== false) {
94
+ for (const name of fs.readdirSync(commonFiles)) {
95
+ if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
96
+ fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
97
+ }
98
+ }
99
+ migrateAppConfigurator(projectRoot);
100
+ pkg.scripts = scripts;
101
+ fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
102
+ // Cleanup happens only after replacement assets and package commands exist.
103
+ removeVersionedBuildScripts(projectRoot);
104
+ console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
105
+ // Coupled IAP/AdMob/Home migrations run together during before-build.
106
+ return pkg;
107
+ }
108
+ module.exports = { install, findProjectRoot, migrateAppScripts, migrateAppConfigurator };
109
+ if (require.main === module) {
110
+ try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
86
111
  }
@@ -1,3 +1,3 @@
1
- // Preserve working app files during preinstall. Postinstall migrates commands
2
- // first, then removes only recognized copied build scripts.
1
+ // Preserve working app files during preinstall. Postinstall migrates commands
2
+ // first, then removes only recognized copied build scripts.
3
3
  console.log('codeplay-common: preserving app files until installation completes.');