tungsten 0.2.4 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ProdServer.d.ts","sourceRoot":"","sources":["../../src/Servers/ProdServer.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAI7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAMpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAM3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAKnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AASrD,qBAAa,UAAW,SAAQ,cAAc;IAC1C,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,uBAAuB,CAAA;IAC/B,eAAe,EAAE,eAAe,CAAA;IAChC,SAAS,EAAE,SAAS,CAAA;IACpB,mBAAmB,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAK5C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IAC9B,GAAG,EAAE,OAAO,CAAC,WAAW,CAAA;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACrC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEX,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,uBAAuB,EAC/B,eAAe,EAAE,eAAe,EAChC,SAAS,EA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IAC9B,GAAG,EAAE,OAAO,CAAC,WAAW,CAAA;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACrC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEX,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,uBAAuB,EAC/B,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,EACpB,mBAAmB,EAAE,gBAAgB,GAAG,IAAI,EAC5C,gBAAgB,EAAE,gBAAgB,GAAG,IAAI;IA8H7C,OAAO,CAAC,gBAAgB,CAgBvB;IACD,aAAa,GAAU,KAAK,OAAO,CAAC,OAAO,EAAE,KAAK,OAAO,CAAC,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CA6GjF;IACD,SAAS,eASR;IAMD,KAAK,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBlE,IAAI;CAKP"}
@@ -4,7 +4,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
4
4
  import express from 'express';
5
5
  import { join } from 'path';
6
6
  import { existsSync } from 'fs';
7
- import { staticFolder, assetsFolder, packageNameCapitalized, publicFolder } from "../settings.js";
7
+ import { staticFolder, assetsFolder, packageNameCapitalized, publicFolder, componentCssFolder } from "../settings.js";
8
8
  import { rootToHtml as renderRootToHtml } from "../render/rootToHtml.js";
9
9
  import { contentToHtml as renderContentToHtml } from "../render/contentToHtml.js";
10
10
  import { Instance } from "../Instance/Instance.js";
@@ -239,6 +239,7 @@ export class ProdServer extends TungstenServer {
239
239
  throwError('ProdServer', 'compilationInfo.bundleLocation is unset/undefined');
240
240
  }
241
241
  this.app.use('/bundle', express.static(this.compilationInfo.bundleLocation));
242
+ this.app.use(`/${componentCssFolder}/`, express.static(join(this.compilationInfo.buildLocation, componentCssFolder)));
242
243
  const publicLocation = join(this.compilationInfo.buildLocation, publicFolder);
243
244
  //console.log('publicLocation', publicLocation, existsSync(publicLocation))
244
245
  if (existsSync(publicLocation)) this.app.use(express.static(publicLocation)); // files from public folder
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/compile.ts"],"names":[],"mappings":"AA4JA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,91 @@
1
+ import { join } from 'path';
2
+ import rmfr from 'rmfr';
3
+ import { compileJavascript } from "../../build/compileJavascript.js";
4
+ import { compileStyles } from "../../build/compileStyles.js";
5
+ import { copyAssets } from "../../build/copyAssets.js";
6
+ import { copyPublicFiles } from "../../build/copyPublicFiles.js";
7
+ import { createClientFiles } from "../../build/createClientFiles.js";
8
+ import { createInstanceConfigFile } from "../../build/createInstanceConfigFile.js";
9
+ import { getUserConfig } from "../../getUserConfig.js";
10
+ import { buildCodeSubPath, assetsFolder, clientFolder, componentCssFolder, devBuildOuterFolder, packagesCacheFolder, packagesFolder, publicFolder, staticFolder } from "../../settings.js";
11
+ import { cliError, cliNews, cliOut } from "../../cliOutput.js";
12
+ const targetOptions = {
13
+ '--js': 'js',
14
+ '--css': 'css',
15
+ '--client': 'client',
16
+ '--assets': 'assets',
17
+ '--public': 'public'
18
+ };
19
+ const args = process.argv.slice(3);
20
+ if (args.includes('--help') || args.includes('-h')) {
21
+ cliOut('Usage: tungsten compile [targets] [--all] [--watch] [--no-clean]');
22
+ cliOut('Targets: --js, --css, --client, --assets, --public');
23
+ cliOut('With no target options, all targets are compiled.');
24
+ process.exit(0);
25
+ }
26
+ const commandOptions = new Set(['--all', '--watch', '--no-clean']);
27
+ const unknownOptions = args.filter(arg => !(arg in targetOptions) && !commandOptions.has(arg));
28
+ if (unknownOptions.length > 0) {
29
+ cliError(`Unknown compile option${unknownOptions.length === 1 ? '' : 's'}: ${unknownOptions.join(', ')}`);
30
+ cliOut('Usage: tungsten compile [targets] [--all] [--watch] [--no-clean]');
31
+ process.exit(1);
32
+ }
33
+ const requestedTargets = new Set();
34
+ for (const arg of args) {
35
+ const target = targetOptions[arg];
36
+ if (target !== undefined) requestedTargets.add(target);
37
+ }
38
+ const targets = requestedTargets.size === 0 || args.includes('--all') ? new Set(['js', 'css', 'client', 'assets', 'public']) : requestedTargets;
39
+ const watch = args.includes('--watch');
40
+ const clean = !args.includes('--no-clean');
41
+ const projectDir = process.cwd();
42
+ const config = await getUserConfig();
43
+ const codeLocation = join(projectDir, config.codeDir);
44
+ const relSourceDir = config.sourceDir !== undefined && config.sourceDir !== '' ? config.sourceDir : config.codeDir;
45
+ const sourceLocation = join(projectDir, relSourceDir);
46
+ const styleImportBase = config.styleImportBase !== undefined ? join(sourceLocation, config.styleImportBase) : sourceLocation;
47
+ const buildLocation = join(projectDir, devBuildOuterFolder);
48
+ const buildCodeLocation = join(buildLocation, buildCodeSubPath);
49
+ const cleanTasks = [];
50
+ if (clean && targets.has('js')) {
51
+ cleanTasks.push(rmfr(buildCodeLocation), rmfr(join(buildLocation, componentCssFolder)), rmfr(join(buildLocation, packagesFolder)), rmfr(join(projectDir, packagesCacheFolder)));
52
+ }
53
+ if (clean && targets.has('css')) {
54
+ cleanTasks.push(rmfr(join(buildLocation, staticFolder)));
55
+ }
56
+ if (clean && targets.has('client')) {
57
+ cleanTasks.push(rmfr(join(buildLocation, clientFolder)), rmfr(join(buildLocation, '.tungsten.config.js')));
58
+ }
59
+ if (clean) {
60
+ if (targets.has('assets')) cleanTasks.push(rmfr(join(buildLocation, assetsFolder)));
61
+ if (targets.has('public')) cleanTasks.push(rmfr(join(buildLocation, publicFolder)));
62
+ cliOut(`Cleaning compile output: ${[...targets].join(', ')}`);
63
+ await Promise.all(cleanTasks);
64
+ }
65
+ const compilationTasks = [];
66
+ if (targets.has('js')) {
67
+ compilationTasks.push(compileJavascript(projectDir, config, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, 'dev', watch));
68
+ }
69
+ if (targets.has('css')) {
70
+ compilationTasks.push(compileStyles(projectDir, config, styleImportBase, buildLocation, watch));
71
+ }
72
+ if (targets.has('client')) {
73
+ compilationTasks.push(createInstanceConfigFile(config, 'dev'));
74
+ compilationTasks.push(createClientFiles(config, 'dev'));
75
+ }
76
+ if (targets.has('assets')) {
77
+ const assetsTask = copyAssets(projectDir, config, buildLocation, watch);
78
+ if (assetsTask !== undefined) compilationTasks.push(assetsTask);
79
+ }
80
+ if (targets.has('public')) {
81
+ compilationTasks.push(copyPublicFiles(projectDir, config, buildLocation, watch));
82
+ }
83
+ await Promise.all(compilationTasks);
84
+ cliNews(`Compile complete: ${[...targets].join(', ')}`);
85
+ if (watch && (targets.has('js') || targets.has('css') || targets.has('assets') || targets.has('public'))) {
86
+ cliNews('Watching for changes');
87
+ } else {
88
+ // The underlying development compilers watch after their initial pass.
89
+ // End them when this command is being used for one-shot test preparation.
90
+ process.exit(0);
91
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AA8CA,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AAmDA,OAAO,EAAE,CAAA"}
package/dist/bin/index.js CHANGED
@@ -34,6 +34,12 @@ switch (command) {
34
34
  await import("./commands/clean.js");
35
35
  break;
36
36
  }
37
+ case 'compile':
38
+ {
39
+ process.env.__TUNGSTEN_ENV = 'development';
40
+ await import("./commands/compile.js");
41
+ break;
42
+ }
37
43
  case 'compile-simple-package':
38
44
  {
39
45
  await import("./commands/compileSimplePackage.js");
@@ -1 +1 @@
1
- {"version":3,"file":"babel.user.common.config.d.ts","sourceRoot":"","sources":["../../src/build/babel.user.common.config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAcnD,QAAA,MAAM,gBAAgB,EAAE,gBA2BvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
1
+ {"version":3,"file":"babel.user.common.config.d.ts","sourceRoot":"","sources":["../../src/build/babel.user.common.config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAcnD,QAAA,MAAM,gBAAgB,EAAE,gBA6BvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
@@ -20,6 +20,8 @@ const userCommonConfig = {
20
20
  // }],
21
21
  ],
22
22
  plugins: [[babelPluginSxyModuleResolve, {
23
+ // This alias is resolved after Tungsten rewrites package imports.
24
+ "loglevel": "silent",
23
25
  "alias": {
24
26
  "tungsten/jsx-runtime": "tungsten/jsxRuntime.js" // fix the import location created by @babel/preset-react
25
27
  }
@@ -3,10 +3,10 @@ import type { FrameworkConfigComplete } from '../FrameworkConfig.js';
3
3
  import type { ImportAliases } from './ImportAliases.js';
4
4
  import type { Mode } from '../Mode.js';
5
5
  type CompileJavascriptResult = {
6
- watcher: chokidar.FSWatcher;
6
+ watcher: chokidar.FSWatcher | null;
7
7
  copyWatcher: chokidar.FSWatcher | null;
8
8
  importAliases: ImportAliases;
9
9
  };
10
- export declare function compileJavascript(projectDir: string, appConfig: FrameworkConfigComplete, codeLocation: string, sourceLocation: string, styleImportBase: string, buildLocation: string, buildCodeLocation: string, mode: Mode): Promise<CompileJavascriptResult>;
10
+ export declare function compileJavascript(projectDir: string, appConfig: FrameworkConfigComplete, codeLocation: string, sourceLocation: string, styleImportBase: string, buildLocation: string, buildCodeLocation: string, mode: Mode, watch?: boolean): Promise<CompileJavascriptResult>;
11
11
  export {};
12
12
  //# sourceMappingURL=compileJavascript.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileJavascript.d.ts","sourceRoot":"","sources":["../../src/build/compileJavascript.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAO/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBA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AI,EAAE,IAAI,EAAE,KAAK,UAAO,GAC3E,OAAO,CAAC,uBAAuB,CAAC,CAwPlC"}
@@ -13,14 +13,14 @@ import { TungstenError } from "../TungstenError.js";
13
13
  import { getFrameworkDir } from "../getFrameworkDir.js";
14
14
  ///// needs work to work in prod mode
15
15
  ///// see babel config
16
- export async function compileJavascript(projectDir, appConfig, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, mode) {
16
+ export async function compileJavascript(projectDir, appConfig, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, mode, watch = true) {
17
17
  cliOut(`Compiling app code`);
18
- let dependencyGraphDir;
19
- let dependencyGraphLocation;
20
- let oldDependencyGraph;
21
- let dependencyGraph;
22
- let importAliases;
23
- let promises;
18
+ let dependencyGraphDir = '';
19
+ let dependencyGraphLocation = '';
20
+ let oldDependencyGraph = {};
21
+ let dependencyGraph = {};
22
+ let importAliases = {};
23
+ let promises = [];
24
24
  let config;
25
25
  if (mode === 'dev') {
26
26
  dependencyGraphDir = join(projectDir, packagesCacheFolder);
@@ -119,8 +119,25 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
119
119
  transformPromises.push(transformFile(file));
120
120
  });
121
121
  await Promise.all(transformPromises);
122
+ if (!watch) {
123
+ if (mode === 'dev') {
124
+ await Promise.all(promises);
125
+ if (!fs.existsSync(dependencyGraphDir)) {
126
+ fs.mkdirSync(dependencyGraphDir, {
127
+ recursive: true
128
+ });
129
+ }
130
+ fs.writeFileSync(dependencyGraphLocation, `export const graph = ${serializeJavascript(dependencyGraph)}`);
131
+ }
132
+ return {
133
+ watcher: null,
134
+ copyWatcher: null,
135
+ importAliases
136
+ };
137
+ }
122
138
  const watcher = chokidar.watch(watchGlob, {
123
- ignored
139
+ ignored,
140
+ ignoreInitial: true
124
141
  //useFsEvents: false
125
142
  });
126
143
  watcher.on('all', async (event, file) => {
@@ -1,3 +1,3 @@
1
1
  import type { FrameworkConfigComplete } from '../FrameworkConfig.js';
2
- export declare function compileStyles(projectDir: string, config: FrameworkConfigComplete, styleImportBase: string, buildLocation: string): Promise<unknown>;
2
+ export declare function compileStyles(projectDir: string, config: FrameworkConfigComplete, styleImportBase: string, buildLocation: string, watch?: boolean): Promise<unknown>;
3
3
  //# sourceMappingURL=compileStyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileStyles.d.ts","sourceRoot":"","sources":["../../src/build/compileStyles.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiOpE,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,oBA+EhI"}
1
+ {"version":3,"file":"compileStyles.d.ts","sourceRoot":"","sources":["../../src/build/compileStyles.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiOpE,wBAAsB,aAAa,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,uBAAuB,EAC/B,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,KAAK,UAAO,oBA8Ff"}
@@ -3,6 +3,7 @@ import chokidar from 'chokidar';
3
3
  import { join, dirname, resolve } from 'path';
4
4
  import { promises as fsPromises, utimesSync } from 'fs';
5
5
  import * as sass from 'sass';
6
+ import { globby } from 'globby';
6
7
  import { staticFolder } from "../settings.js";
7
8
  import { cliError, cliOut } from "../cliOutput.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
8
9
  import { throwError } from "../throwError.js";
@@ -186,7 +187,7 @@ async function processAndCopyFile(sourceLocation, targetLocation, filePathFull,
186
187
  }
187
188
  cssFiles[targetRelFile] = relFile;
188
189
  }
189
- export function compileStyles(projectDir, config, styleImportBase, buildLocation) {
190
+ export async function compileStyles(projectDir, config, styleImportBase, buildLocation, watch = true) {
190
191
  cliOut(`Compiling app stylesheets`);
191
192
  // we need to create and maintain a dependency tree for correct updating
192
193
  // we are going to save the dependencies of each file
@@ -217,6 +218,11 @@ export function compileStyles(projectDir, config, styleImportBase, buildLocation
217
218
  const watchGlob = sourceLocation + '/**/*.{css,scss,sass,less}';
218
219
  const ignoreGlob = buildLocation + '/**/*';
219
220
  debug('Styles watchGlob', watchGlob);
221
+ if (!watch) {
222
+ const files = await globby(slash(watchGlob));
223
+ await Promise.all(files.map(file => processAndCopyFile(sourceLocation, staticLocation, slash(file), styleImportBase, cssFiles, cssDependencies, cssdependers)));
224
+ return null;
225
+ }
220
226
  const watcher = chokidar.watch(watchGlob, {
221
227
  ignored: ignoreGlob
222
228
  //ignoreInitial: true
@@ -1,3 +1,3 @@
1
1
  import type { FrameworkConfigComplete } from '../FrameworkConfig.js';
2
- export declare function copyAssets(projectDir: string, config: FrameworkConfigComplete, buildLocation: string): Promise<unknown> | undefined;
2
+ export declare function copyAssets(projectDir: string, config: FrameworkConfigComplete, buildLocation: string, watch?: boolean): Promise<unknown>;
3
3
  //# sourceMappingURL=copyAssets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"copyAssets.d.ts","sourceRoot":"","sources":["../../src/build/copyAssets.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiBpE,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,gCA+CpG"}
1
+ {"version":3,"file":"copyAssets.d.ts","sourceRoot":"","sources":["../../src/build/copyAssets.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiBpE,wBAAsB,UAAU,CAC5B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,uBAAuB,EAC/B,aAAa,EAAE,MAAM,EACrB,KAAK,UAAO,oBA2Df"}
@@ -2,6 +2,7 @@ import slash from 'slash';
2
2
  import chokidar from 'chokidar';
3
3
  import { join, dirname } from 'path';
4
4
  import { promises as fsPromises } from 'fs';
5
+ import { globby } from 'globby';
5
6
  import { cliOut } from "../cliOutput.js";
6
7
  async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
7
8
  const relFile = filePathFull.slice(assetsLocation.length + 1);
@@ -13,7 +14,7 @@ async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
13
14
  });
14
15
  return fsPromises.copyFile(filePathFull, target);
15
16
  }
16
- export function copyAssets(projectDir, config, buildLocation) {
17
+ export async function copyAssets(projectDir, config, buildLocation, watch = true) {
17
18
  if (config.assetsDir !== undefined) {
18
19
  cliOut(`Copying assets`);
19
20
  const assetsLocation = join(projectDir, config.assetsDir);
@@ -21,6 +22,11 @@ export function copyAssets(projectDir, config, buildLocation) {
21
22
  //console.log('copy assets from', assetsLocation, 'to', targetLocation)
22
23
  const watchGlob = assetsLocation + '/**/*';
23
24
  //const ignoreGlob = buildLocation + '/**/*'
25
+ if (!watch) {
26
+ const files = await globby(slash(watchGlob));
27
+ await Promise.all(files.map(file => copyFile(assetsLocation, targetLocation, slash(file), 'add')));
28
+ return null;
29
+ }
24
30
  const watcher = chokidar.watch(watchGlob, {
25
31
  //ignored: ignoreGlob,
26
32
  //ignoreInitial: true
@@ -1,3 +1,3 @@
1
1
  import type { FrameworkConfigComplete } from '../FrameworkConfig.js';
2
- export declare function copyPublicFiles(projectDir: string, config: FrameworkConfigComplete, buildLocation: string): Promise<unknown>;
2
+ export declare function copyPublicFiles(projectDir: string, config: FrameworkConfigComplete, buildLocation: string, watch?: boolean): Promise<unknown>;
3
3
  //# sourceMappingURL=copyPublicFiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"copyPublicFiles.d.ts","sourceRoot":"","sources":["../../src/build/copyPublicFiles.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiBpE,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAgDzG"}
1
+ {"version":3,"file":"copyPublicFiles.d.ts","sourceRoot":"","sources":["../../src/build/copyPublicFiles.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAiBpE,wBAAsB,eAAe,CACjC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,uBAAuB,EAC/B,aAAa,EAAE,MAAM,EACrB,KAAK,UAAO,oBA4Df"}
@@ -2,6 +2,7 @@ import slash from 'slash';
2
2
  import chokidar from 'chokidar';
3
3
  import { join, dirname } from 'path';
4
4
  import { promises as fsPromises } from 'fs';
5
+ import { globby } from 'globby';
5
6
  import { cliOut } from "../cliOutput.js";
6
7
  async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
7
8
  const relFile = filePathFull.slice(assetsLocation.length + 1);
@@ -13,7 +14,7 @@ async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
13
14
  });
14
15
  return fsPromises.copyFile(filePathFull, target);
15
16
  }
16
- export function copyPublicFiles(projectDir, config, buildLocation) {
17
+ export async function copyPublicFiles(projectDir, config, buildLocation, watch = true) {
17
18
  //if ( config.publicDir !== undefined ) {
18
19
  cliOut(`Copying public files`);
19
20
  const publicLocation = config.publicDir !== undefined ? join(projectDir, config.publicDir) : join(projectDir, 'public');
@@ -22,6 +23,11 @@ export function copyPublicFiles(projectDir, config, buildLocation) {
22
23
  //console.log('copy assets from', publicLocation, 'to', targetLocation)
23
24
  const watchGlob = publicLocation + '/**/*';
24
25
  //const ignoreGlob = buildLocation + '/**/*'
26
+ if (!watch) {
27
+ const files = await globby(slash(watchGlob));
28
+ await Promise.all(files.map(file => copyFile(publicLocation, targetLocation, slash(file), 'add')));
29
+ return null;
30
+ }
25
31
  const watcher = chokidar.watch(watchGlob, {
26
32
  //ignored: ignoreGlob,
27
33
  //ignoreInitial: true
@@ -507,15 +507,7 @@ async function hydrateNodeSingle(node, parentElement, domPointer, instance, meta
507
507
  renderedChildren = await hydrateNode(children, parentElement, childDomPointer, instance, meta);
508
508
  }
509
509
  if (node[$type] === 'select' && node[$props].value !== undefined && node[$props].value !== null) {
510
- const options = domNode.options;
511
- const value = String(node[$props].value);
512
- for (let i = options.length - 1; i >= 0; i--) {
513
- const option = options[i];
514
- if (option.value === value) {
515
- option.selected = true;
516
- break;
517
- }
518
- }
510
+ domNode.value = String(node[$props].value);
519
511
  }
520
512
  // note that we have left the form
521
513
  if (node[$type] === 'form') meta.insideForm = false;
@@ -662,13 +654,6 @@ function hydrateAttributes(node, domNode) {
662
654
  domNode[htmlEventHandlerKey(eventName)] = handler;
663
655
  }
664
656
  }
665
- if (node[$type] === 'option') {
666
- const option = domNode;
667
- const select = option.closest('select');
668
- if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
669
- option.selected = true;
670
- }
671
- }
672
657
  debug('--');
673
658
  }
674
659
  // onChange -> add
@@ -1 +1 @@
1
- {"version":3,"file":"integrateUpdateVdom.d.ts","sourceRoot":"","sources":["../../src/update/integrateUpdateVdom.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACH,WAAW,EAAwC,eAAe,EAElE,uBAAuB,EAG1B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAKlD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAKjD,OAAO,EAKyB,4BAA4B,EAI3D,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAYhD,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAC5C,wBAAwB,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,KAAK,G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AA;CACzB,CAAA;AAYD,wBAAsB,0BAA0B,CAC5C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,GAC/C,OAAO,CAAC,YAAY,CAAC,CA0GvB;AAkmBD,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,QAkK7E;AAwUD,KAAK,2BAA2B,GAAG;IAC/B,MAAM,EAAE,eAAe,CAAA;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,uBAAuB,CAAC;IAE9B,UAAU,EAAE,UAAU,CAAA;CACzB,CAAA;AACD,wBAAsB,uBAAuB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,2BAA2B,GAC3G,OAAO,CAAC,4BAA4B,CAAC,CAU1C"}
@@ -410,23 +410,11 @@ async function updateHtmlElement(tungstenElement, instance, newNode, oldNode, do
410
410
  domPointer: new DomPointer(domNode, 0),
411
411
  parentNode: newNode
412
412
  });
413
- if (newNode[$type] === 'select') {
414
- // if we updated a select element
415
- // if the value changed, we need to update the options
416
- // alternatively the options might have changed, also requiring
417
- // updates to `selected`
418
- // if the options update without the select updating, then they will need to look-back to find the value of the select
419
- if (newNode[$props].value !== undefined && newNode[$props].value !== null && String(newNode[$props].value) !== String(oldNode[$props].value)) {
420
- const options = domNode.options;
421
- const value = String(newNode[$props].value);
422
- for (let i = options.length - 1; i >= 0; i--) {
423
- const option = options[i];
424
- if (option.value === value) {
425
- option.selected = true;
426
- break;
427
- }
428
- }
429
- }
413
+ // Reapply the controlled value after reconciling the options. Updating the
414
+ // option collection can change the browser's selection even when the
415
+ // virtual select value itself has not changed.
416
+ if (newNode[$type] === 'select' && newNode[$props].value !== undefined && newNode[$props].value !== null) {
417
+ domNode.value = String(newNode[$props].value);
430
418
  }
431
419
  return makeRenderedContentNodeHtml(newNode, domNode, renderedChildren);
432
420
  }
@@ -800,22 +788,7 @@ async function createHtmlElement(tungstenElement, instance, node, domPointer, pa
800
788
  });
801
789
  if (node[$type] === 'select') {
802
790
  if (node[$props].value !== undefined && node[$props].value !== null) {
803
- const options = htmlEl.options;
804
- const value = String(node[$props].value);
805
- for (let i = options.length - 1; i >= 0; i--) {
806
- const option = options[i];
807
- if (option.value === value) {
808
- option.selected = true;
809
- break;
810
- }
811
- }
812
- }
813
- }
814
- if (node[$type] === 'option') {
815
- const option = htmlEl;
816
- const select = option.closest('select');
817
- if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
818
- option.selected = true;
791
+ htmlEl.value = String(node[$props].value);
819
792
  }
820
793
  }
821
794
  return {
@@ -938,13 +911,6 @@ function updateAttributes(node, oldNode, domNodeHTMLElement) {
938
911
  }
939
912
  }
940
913
  }
941
- if (node[$type] === 'option') {
942
- const option = domNode;
943
- const select = option.closest('select');
944
- if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
945
- option.selected = true;
946
- }
947
- }
948
914
  domNode.__tungsten_oldAttributes = newAttributes;
949
915
  return newAttributes;
950
916
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {
package/readme.md CHANGED
@@ -1,3 +1,39 @@
1
1
  # Tungsten Frontend Framework
2
2
 
3
- [Docs](https://robertsandiford.co.uk/tungsten)
3
+ [Docs](https://robertsandiford.co.uk/tungsten)
4
+
5
+ ## Preparing code for tests
6
+
7
+ Run a one-shot development compilation without starting a server:
8
+
9
+ ```sh
10
+ tungsten compile
11
+ ```
12
+
13
+ By default this compiles JavaScript (including JSX and Tungsten's Babel
14
+ transforms), stylesheets, client support files, assets, and public files into
15
+ `.tungsten/dev`.
16
+ Each selected target's existing generated output is cleaned before the initial
17
+ compilation, including when watch mode is used. Pass `--no-clean` to preserve
18
+ existing output.
19
+ Limit the work with one or more options:
20
+
21
+ ```sh
22
+ tungsten compile --js
23
+ tungsten compile --css
24
+ tungsten compile --client
25
+ tungsten compile --assets
26
+ tungsten compile --public
27
+ tungsten compile --js --css
28
+ ```
29
+
30
+ `--all` explicitly selects all three targets.
31
+
32
+ Add `--watch` to keep the JavaScript, stylesheet, asset, and/or public-file
33
+ compiler running after the initial pass. Client support files are still
34
+ generated once:
35
+
36
+ ```sh
37
+ tungsten compile --watch
38
+ tungsten compile --js --watch
39
+ ```