1 | const fs = require('fs-extra')
|
2 | const replace = require('replace-in-file')
|
3 |
|
4 | fs.copy('build/nav', 'build/preact/nav', (err) => {
|
5 | if (err) return console.error('copy: ' + err)
|
6 |
|
7 | replaceText({
|
8 | files: `build/preact/nav/**/*.js`,
|
9 | from: `import React from 'react'`,
|
10 | to: `import {h} from 'preact'`
|
11 | }).then(() => replaceText({
|
12 | files: `build/preact/nav/**/*.js`,
|
13 | from: `import React, { Component } from 'react'`,
|
14 | to: `import {h, Component} from 'preact'`
|
15 | }).then(() => replaceText({
|
16 | files: `build/preact/nav/**/*.js`,
|
17 | from: /React.Component/g,
|
18 | to: `Component`
|
19 | }).then(() => replaceText({
|
20 | files: `build/preact/nav/**/*.js`,
|
21 | from: /React.createElement/g,
|
22 | to: `h`
|
23 | }).then(() => replaceText({
|
24 | files: `build/preact/nav/**/*.js`,
|
25 | from: `import { render } from 'react-dom'`,
|
26 | to: `import {render} from 'preact'`
|
27 | })))))
|
28 |
|
29 | console.log('success!')
|
30 | })
|
31 |
|
32 | function replaceText (opts) {
|
33 | return replace(opts)
|
34 | .then(changes => console.log('Modified files:', changes.join(', ')))
|
35 | .catch(error => console.error('Error occurred:', error))
|
36 | }
|