Skip to content

Commit

Permalink
Fix windows build; update README
Browse files Browse the repository at this point in the history
  • Loading branch information
mwistrand committed Sep 14, 2018
1 parent 0a43e6d commit b35abc9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
12 changes: 8 additions & 4 deletions README.md
Expand Up @@ -121,19 +121,23 @@ To build custom elements for legacy environments use the `--legacy` or `-l` flag

### Eject

Ejecting `@dojo/cli-build-widget` will produce the following files under the `config/build-widget` directory:
The `@dojo/cli-build-widget` functionality can be ejected with the `dojo eject` command, but the `--serve` (and therefore `--port`) options are not supported. Ejecting produces the following files under the `config/build-widget` directory:

- `build-options.json`: the build-specific config options removed from the `.dojorc`
- `build-options.json`: the build-specific config options removed from the `.dojorc`.
- `dojo-build-widget.js`: the shell script used to run the ejected build.
- `ejected.config.js`: the root webpack config that passes the build options to the appropriate mode-specific config based on the `--env.mode` flag's value.
- `base.config.js`: a common configuration used by the mode-specific configs.
- `dev.config.js`: the configuration used during development.
- `lib.js`: the library build functionality.
- `dist.config.js`: the production configuration.
- `test.config.js`: the configuration used when running tests.

As already noted, the dojorc's `build-widget` options are moved to `config/build-widget/build-options.json` after ejecting. Further, the modes are specified using webpack's `env` flag (e.g., `--env.mode=dev`), defaulting to `dist`. You can run a build using webpack with:
As already noted, the dojorc's `build-widget` options are moved to `config/build-widget/build-options.json` after ejecting. Further, a simple shell script is provided at `config/build-widget/dojo-build-widget.js`, and if possible, a symlink is created at the project root as `dojo-build-widget`. **Note**: eject must be run with administrative permissions on windows for the symlink to be created successfully.

You can run a build with:

```bash
node_modules/.bin/webpack --config=config/build-widget/ejected.config.js --env.mode={dev|dist|test}
./dojo-build-widget --mode={dev|dist|test} --target={lib|widget} --legacy --watch --elements=...
```

### Configuration
Expand Down
5 changes: 4 additions & 1 deletion src/lib.ts
Expand Up @@ -24,7 +24,10 @@ const allFiles = path.join(allPaths, `**/*.{${allExtensions}}`);

function createChildProcess(command: string, args: string[], errorMessage: string) {
return new Promise((resolve, reject) => {
const child = spawn(path.join(basePath, 'node_modules/.bin', command), args, { cwd: basePath });
const child = spawn(path.join(basePath, 'node_modules/.bin', command), args, {
cwd: basePath,
shell: process.platform.startsWith('win')
});
child.on('error', reject);
child.on('exit', code => (code !== 0 ? reject(new Error(errorMessage)) : resolve()));
});
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Expand Up @@ -277,7 +277,7 @@ const command: Command = {
},
hints: [
`to build run ${chalk.underline(
'./dojo-build-webpack --mode={dev|dist|test} --target={lib|widget} --legacy --watch --elements=...'
'./dojo-build-widget --mode={dev|dist|test} --target={lib|widget} --legacy --watch --elements=...'
)}`
],
npm: {
Expand Down
9 changes: 8 additions & 1 deletion src/util.ts
Expand Up @@ -33,7 +33,14 @@ export function createAndLinkEjectedBuildFile(ejectOutputPath: string) {
const binFileContents = fs.readFileSync(path.join(__dirname, './build-ejected.js'), 'utf8');
fs.writeFileSync(tmpBinFile, `#!/usr/bin/env node\n${binFileContents}`);
fs.chmodSync(tmpBinFile, '755');
fs.symlinkSync(path.join(ejectOutputPath, './dojo-build-widget.js'), path.join(process.cwd(), './dojo-build-widget'));
try {
fs.symlinkSync(
path.join(ejectOutputPath, './dojo-build-widget.js'),
path.join(process.cwd(), './dojo-build-widget')
);
} catch (error) {
console.error(error.message);
}
return tmpBinFile;
}

Expand Down
26 changes: 22 additions & 4 deletions tests/unit/lib.ts
Expand Up @@ -120,7 +120,12 @@ describe('lib', () => {
const tmpPath = join(basePath, 'output/dev/tmp');
const command = join(basePath, 'node_modules/.bin/tsc');
const { spawn } = mockModule.getMock('child_process');
assert.isTrue(spawn.calledWith(command, ['--outDir', tmpPath, '-t', 'es6', '-m', 'esnext'], { cwd: basePath }));
assert.isTrue(
spawn.calledWith(command, ['--outDir', tmpPath, '-t', 'es6', '-m', 'esnext'], {
cwd: basePath,
shell: process.platform.startsWith('win')
})
);
assert.isTrue(mockModule.getMock('cpx').copy.calledWith(join(tmpPath, 'src/**'), outputPath));
assert.isTrue(mockModule.getMock('rimraf').ctor.calledWith(tmpPath));
});
Expand All @@ -134,7 +139,12 @@ describe('lib', () => {
const tmpPath = join(basePath, 'output/dev/tmp');
const command = join(basePath, 'node_modules/.bin/tsc');
const { spawn } = mockModule.getMock('child_process');
assert.isTrue(spawn.calledWith(command, ['--outDir', tmpPath], { cwd: basePath }));
assert.isTrue(
spawn.calledWith(command, ['--outDir', tmpPath], {
cwd: basePath,
shell: process.platform.startsWith('win')
})
);
assert.isTrue(mockModule.getMock('cpx').copy.calledWith(join(tmpPath, 'src/**'), outputPath));
assert.isTrue(mockModule.getMock('rimraf').ctor.calledWith(tmpPath));
});
Expand All @@ -148,7 +158,10 @@ describe('lib', () => {
const command = join(basePath, 'node_modules/.bin/tsc');
const { spawn } = mockModule.getMock('child_process');
assert.isTrue(
spawn.calledWith(command, ['--outDir', outputPath, '-t', 'es6', '-m', 'esnext'], { cwd: basePath })
spawn.calledWith(command, ['--outDir', outputPath, '-t', 'es6', '-m', 'esnext'], {
cwd: basePath,
shell: process.platform.startsWith('win')
})
);
});
});
Expand Down Expand Up @@ -209,7 +222,12 @@ describe('lib', () => {
const command = join(basePath, 'node_modules/.bin/tcm');
const { spawn } = mockModule.getMock('child_process');
const outputPath = join(process.cwd(), 'output/dist');
assert.isTrue(spawn.calledWith(command, [outputPath, '*.m.css'], { cwd: basePath }));
assert.isTrue(
spawn.calledWith(command, [outputPath, '*.m.css'], {
cwd: basePath,
shell: process.platform.startsWith('win')
})
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/main.ts
Expand Up @@ -437,7 +437,7 @@ describe('command', () => {
},
hints: [
`to build run ${chalk.underline(
'./dojo-build-webpack --mode={dev|dist|test} --target={lib|widget} --legacy --watch --elements=...'
'./dojo-build-widget --mode={dev|dist|test} --target={lib|widget} --legacy --watch --elements=...'
)}`
],
npm: {
Expand Down

0 comments on commit b35abc9

Please sign in to comment.