@putdotio/taizn 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -85,6 +85,7 @@ TAIZN_SDB=~/tizen-studio/tools/sdb
85
85
  },
86
86
  "widget": {
87
87
  "configXml": "platforms/tizen/config.xml",
88
+ "excludeFiles": ["js/main.js.map", "css/main.css.map"],
88
89
  "indexHtml": "platforms/tizen/index.html",
89
90
  "injectWebapis": true,
90
91
  "rewriteAssetUrls": false,
@@ -99,15 +100,24 @@ TAIZN_SDB=~/tizen-studio/tools/sdb
99
100
  "production": {
100
101
  "applicationId": "Example.app",
101
102
  "bundleName": "example",
103
+ "excludeFiles": ["js/main.js.LICENSE.txt"],
102
104
  "icon": "platforms/tizen/icon.png",
105
+ "indexHtml": "platforms/tizen/hosted.html",
106
+ "injectWebapis": true,
103
107
  "name": "Example",
104
- "packageId": "Example"
108
+ "packageId": "Example",
109
+ "rewriteAssetUrls": false
105
110
  }
106
111
  }
107
112
  }
108
113
  }
109
114
  ```
110
115
 
116
+ Variant `indexHtml`, `injectWebapis`, and `rewriteAssetUrls` values override
117
+ the top-level `widget` values. Variant `excludeFiles` values are added to
118
+ top-level `widget.excludeFiles`. Use them when development packages should
119
+ bundle local app assets but production packages should load hosted asset URLs.
120
+
111
121
  ## Docs
112
122
 
113
123
  - [Contributing](./CONTRIBUTING.md)
package/dist/taizn.mjs CHANGED
@@ -102,9 +102,13 @@ const readSecret = (prompt) => new Promise((resolve) => {
102
102
  const TizenVariantSchema = Schema.Struct({
103
103
  applicationId: Schema.NonEmptyString,
104
104
  bundleName: Schema.NonEmptyString,
105
+ excludeFiles: Schema.optional(Schema.Array(Schema.NonEmptyString)),
105
106
  icon: Schema.NonEmptyString,
107
+ indexHtml: Schema.optional(Schema.NonEmptyString),
108
+ injectWebapis: Schema.optional(Schema.Boolean),
106
109
  name: Schema.NonEmptyString,
107
- packageId: Schema.NonEmptyString
110
+ packageId: Schema.NonEmptyString,
111
+ rewriteAssetUrls: Schema.optional(Schema.Boolean)
108
112
  });
109
113
  const TizenConfigSchema = Schema.Struct({
110
114
  build: Schema.Struct({
@@ -118,6 +122,7 @@ const TizenConfigSchema = Schema.Struct({
118
122
  }),
119
123
  widget: Schema.Struct({
120
124
  configXml: Schema.NonEmptyString,
125
+ excludeFiles: Schema.optional(Schema.Array(Schema.NonEmptyString)),
121
126
  indexHtml: Schema.NonEmptyString,
122
127
  injectWebapis: Schema.optional(Schema.Boolean),
123
128
  rewriteAssetUrls: Schema.optional(Schema.Boolean),
@@ -229,8 +234,9 @@ const createProfile = async ({ config, env }) => {
229
234
  };
230
235
  const packageWidget = ({ config, env }) => {
231
236
  const [command, ...args] = config.build.command;
237
+ const variant = getVariant(config, env.variant);
232
238
  run(command, args, { env: appBuildEnv() });
233
- stageWidget(config, getVariant(config, env.variant));
239
+ stageWidget(config, variant);
234
240
  run(tizenCli(env.tizenCli), [
235
241
  "package",
236
242
  "-t",
@@ -243,7 +249,7 @@ const packageWidget = ({ config, env }) => {
243
249
  stageDir
244
250
  ]);
245
251
  const built = findBuiltWidget();
246
- const installable = join(outputDir, `${getVariant(config, env.variant).bundleName}.wgt`);
252
+ const installable = join(outputDir, `${variant.bundleName}.wgt`);
247
253
  if (built !== installable) copyFileSync(built, installable);
248
254
  console.log(`Packaged ${installable}`);
249
255
  return installable;
@@ -261,6 +267,12 @@ const installWidget = (context) => {
261
267
  run(tizenCli(context.env.tizenCli), installArgs);
262
268
  };
263
269
  const getVariant = (config, variant) => config.widget.variants[variant];
270
+ const getWidgetStageOptions = (config, variant) => ({
271
+ excludeFiles: [...config.widget.excludeFiles ?? [], ...variant.excludeFiles ?? []],
272
+ indexHtml: variant.indexHtml ?? config.widget.indexHtml,
273
+ injectWebapis: variant.injectWebapis ?? config.widget.injectWebapis,
274
+ rewriteAssetUrls: variant.rewriteAssetUrls ?? config.widget.rewriteAssetUrls
275
+ });
264
276
  const getCertificates = (config) => {
265
277
  const certificatesDir = appPath(config.signing.certificateDir);
266
278
  return {
@@ -275,12 +287,12 @@ const rewriteConfigForWidget = (variant) => {
275
287
  widgetConfig = widgetConfig.replace(/<name>[^<]*<\/name>/, `<name>${escapeXml(variant.name)}</name>`);
276
288
  writeFileSync(targetPath, widgetConfig);
277
289
  };
278
- const rewriteIndexForWidget = (config) => {
290
+ const rewriteIndexForWidget = (options) => {
279
291
  const targetPath = join(stageDir, "index.html");
280
292
  const webapisScript = "<script src=\"$WEBAPIS/webapis/webapis.js\"><\/script>";
281
- let html = readFileSync(appPath(config.widget.indexHtml), "utf8");
282
- if (config.widget.rewriteAssetUrls) html = html.replaceAll("href=\"/", "href=\"./").replaceAll("src=\"/", "src=\"./");
283
- if (config.widget.injectWebapis !== false && !html.includes("$WEBAPIS/webapis/webapis.js")) html = html.replace("</head>", `${webapisScript}</head>`);
293
+ let html = readFileSync(appPath(options.indexHtml), "utf8");
294
+ if (options.rewriteAssetUrls) html = html.replaceAll("href=\"/", "href=\"./").replaceAll("src=\"/", "src=\"./");
295
+ if (options.injectWebapis !== false && !html.includes("$WEBAPIS/webapis/webapis.js")) html = html.replace("</head>", `${webapisScript}</head>`);
284
296
  writeFileSync(targetPath, html);
285
297
  };
286
298
  const assertBuildOutput = (config) => {
@@ -289,8 +301,15 @@ const assertBuildOutput = (config) => {
289
301
  for (const requiredFile of config.build.requiredFiles || []) requireFile(join(sourceDir, requiredFile), `Tizen build output ${requiredFile}`);
290
302
  return sourceDir;
291
303
  };
304
+ const removeExcludedStageFiles = (excludeFiles) => {
305
+ for (const file of excludeFiles) rmSync(join(stageDir, file), {
306
+ force: true,
307
+ recursive: true
308
+ });
309
+ };
292
310
  const stageWidget = (config, variant) => {
293
311
  const sourceDir = assertBuildOutput(config);
312
+ const options = getWidgetStageOptions(config, variant);
294
313
  rmSync(stageDir, {
295
314
  force: true,
296
315
  recursive: true
@@ -304,8 +323,9 @@ const stageWidget = (config, variant) => {
304
323
  cpSync(sourceDir, stageDir, { recursive: true });
305
324
  copyFileSync(appPath(config.widget.configXml), join(stageDir, "config.xml"));
306
325
  copyFileSync(requireFile(appPath(variant.icon), "Tizen widget icon"), join(stageDir, "icon.png"));
326
+ removeExcludedStageFiles(options.excludeFiles);
307
327
  rewriteConfigForWidget(variant);
308
- rewriteIndexForWidget(config);
328
+ rewriteIndexForWidget(options);
309
329
  };
310
330
  const findBuiltWidget = () => {
311
331
  const built = execFileSync("find", [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putdotio/taizn",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A tiny CLI companion for interacting with Tizen ecosystem.",
5
5
  "keywords": [
6
6
  "cli",