Skip to content

Commit

Permalink
fix: replace only file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour committed Jan 2, 2020
1 parent 330bd3b commit 85c0283
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build/module-builder/src/build.ts
Expand Up @@ -90,7 +90,7 @@ export async function buildBackend(modulePath: string) {
const outputFiles = []

for (const file of files) {
const dest = file.replace(/^src\//i, 'dist/').replace(/.ts$/i, '.js')
const dest = file.replace(/^src\//i, 'dist/').replace(/\.ts$/i, '.js')
mkdirp.sync(path.dirname(dest))

if (copyWithoutTransform.find(x => file.startsWith(`src/${x}`))) {
Expand Down
2 changes: 1 addition & 1 deletion modules/.knowledge/src/backend/classifier.ts
Expand Up @@ -39,7 +39,7 @@ export class DocumentClassifier {
if (mostRecent) {
const index = await ghost.readFileAsObject<{ [canonical: string]: Snippet }>(
'./models',
mostRecent.replace('knowledge_', 'knowledge_meta_').replace('.bin', '.json')
mostRecent.replace('knowledge_', 'knowledge_meta_').replace(/\.bin$/i, '.json')
)
const buff = await ghost.readFileAsBuffer('./models', mostRecent)
await this.loadFromBuffer(index, buff)
Expand Down
2 changes: 1 addition & 1 deletion modules/code-editor/src/views/full/Editor.tsx
Expand Up @@ -79,7 +79,7 @@ class Editor extends React.Component<Props> {

const { location, readOnly } = this.props.editor.currentFile
const fileType = location.endsWith('.json') ? 'json' : 'typescript'
const filepath = fileType === 'json' ? location : location.replace('.js', '.ts')
const filepath = fileType === 'json' ? location : location.replace(/\.js$/i, '.ts')

const uri = monaco.Uri.parse(`bp://files/${filepath}`)

Expand Down
Expand Up @@ -53,7 +53,7 @@ const Flow: SFC<{ stacktrace: sdk.IO.JumpPoint[] }> = props => (
<H5 color={Colors.DARK_GRAY5}>Flow Nodes</H5>
<ol>
{props.stacktrace.map(({ flow, node }, idx) => {
const flowName = flow && flow.replace('.flow.json', '')
const flowName = flow && flow.replace(/\.flow\.json$/i, '')
return (
<li key={`${flow}:${node}:${idx}`}>
<span>
Expand Down
2 changes: 1 addition & 1 deletion modules/nlu/src/backend/storage.ts
Expand Up @@ -14,7 +14,7 @@ export const ID_REGEX = /[\t\s]/gi
export const sanitizeFilenameNoExt = name =>
name
.toLowerCase()
.replace('.json', '')
.replace(/\.json$/i, '')
.replace(ID_REGEX, '-')

export default class Storage {
Expand Down
2 changes: 1 addition & 1 deletion modules/qna/src/backend/storage.ts
Expand Up @@ -218,7 +218,7 @@ export default class Storage {
questions = questions.slice(opts.start, opts.start + opts.count)
}

return Promise.map(questions, itemName => this.getQnaItem(itemName.replace('.json', '')))
return Promise.map(questions, itemName => this.getQnaItem(itemName.replace(/\.json$/i, '')))
} catch (err) {
this.bp.logger.warn(`Error while reading questions. ${err}`)
return []
Expand Down
14 changes: 11 additions & 3 deletions modules/qna/src/views/full/index.tsx
Expand Up @@ -186,7 +186,13 @@ export default class QnaAdmin extends Component<Props> {
<div className={style.searchBar}>{this.renderSearch()}</div>
<ButtonGroup style={{ float: 'right' }}>
<ImportModal axios={this.props.bp.axios} onImportCompleted={this.fetchData} />
<Button id="btn-export" icon="upload" text="Export to JSON" onClick={this.downloadJson} style={{ marginLeft: 5 }} />
<Button
id="btn-export"
icon="upload"
text="Export to JSON"
onClick={this.downloadJson}
style={{ marginLeft: 5 }}
/>
</ButtonGroup>
</ButtonToolbar>
</FormGroup>
Expand Down Expand Up @@ -253,7 +259,7 @@ export default class QnaAdmin extends Component<Props> {
return null
}

const flowName = redirectFlow.replace('.flow.json', '')
const flowName = redirectFlow.replace(/\.flow\.json$/i, '')
const flowBuilderLink = `/studio/${window.BOT_ID}/flows/${flowName}/#search:${redirectNode}`

return (
Expand Down Expand Up @@ -347,7 +353,9 @@ export default class QnaAdmin extends Component<Props> {
}

if (needDelete) {
this.props.bp.axios.post(`/mod/qna/questions/${id}/delete`, { params }).then(({ data }) => this.setState({ ...data }))
this.props.bp.axios
.post(`/mod/qna/questions/${id}/delete`, { params })
.then(({ data }) => this.setState({ ...data }))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bp/core/services/action/action-service.ts
Expand Up @@ -128,7 +128,7 @@ export class ScopedActionService {
includeMetadata: boolean
): Promise<ActionDefinition> {
let action: ActionDefinition = {
name: file.replace(/.js$/i, ''),
name: file.replace(/\.js$/i, ''),
isRemote: false,
location: location
}
Expand Down
6 changes: 3 additions & 3 deletions src/bp/core/services/bot-service.ts
Expand Up @@ -587,8 +587,8 @@ export class BotService {
return revisions
.filter(rev => rev.startsWith(`${botId}${REV_SPLIT_CHAR}`) && rev.includes(stageID))
.sort((revA, revB) => {
const dateA = revA.split(REV_SPLIT_CHAR)[1].replace('.tgz', '')
const dateB = revB.split(REV_SPLIT_CHAR)[1].replace('.tgz', '')
const dateA = revA.split(REV_SPLIT_CHAR)[1].replace(/\.tgz$/i, '')
const dateB = revB.split(REV_SPLIT_CHAR)[1].replace(/\.tgz$/i, '')

return parseInt(dateA, 10) - parseInt(dateB, 10)
})
Expand All @@ -611,7 +611,7 @@ export class BotService {

public async rollback(botId: string, revision: string): Promise<void> {
const workspaceId = await this.workspaceService.getBotWorkspaceId(botId)
const revParts = revision.replace('.tgz', '').split(REV_SPLIT_CHAR)
const revParts = revision.replace(/\.tgz$/i, '').split(REV_SPLIT_CHAR)
if (revParts.length < 2) {
throw new VError('invalid revision')
}
Expand Down
2 changes: 1 addition & 1 deletion src/bp/core/services/cms.ts
Expand Up @@ -95,7 +95,7 @@ export class CMSService implements IDisposeOnExit {
let contentElements: ContentElement[] = []

for (const fileName of fileNames) {
const contentType = path.basename(fileName).replace(/.json$/i, '')
const contentType = path.basename(fileName).replace(/\.json$/i, '')
const fileContentElements = await this.ghost
.forBot(botId)
.readFileAsObject<ContentElement[]>(this.elementsDir, fileName)
Expand Down
2 changes: 1 addition & 1 deletion src/bp/core/services/migration/index.ts
Expand Up @@ -250,7 +250,7 @@ export class MigrationService {
return {
filename: path.basename(filepath),
version: semver.valid(rawVersion.replace(/_/g, '.')),
title: (title || '').replace('.js', ''),
title: (title || '').replace(/\.js$/i, ''),
date: Number(timestamp),
location: path.join(rootPath, filepath)
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ const RollbackBotModal: FC<Props> = props => {
const { data } = await api.getSecured().get(`/admin/bots/${props.botId}/revisions`)

const revisions = data.payload.revisions.map(rev => {
const parts = rev.replace('.tgz', '').split('++')
const parts = rev.replace(/\.tgz$/i, '').split('++')
parts[1] = new Date(parseInt(parts[1], 10)).toLocaleString()
return {
label: parts.join(' - '),
Expand Down
Expand Up @@ -46,7 +46,7 @@ export class StandardPortWidgetDisconnected extends React.Component<Props> {
renderSubflowNode() {
const node = this.props.node
const index = Number(this.props.name.replace('out', ''))
const subflow = node.next[index].node.replace(/\.flow\.json/, '')
const subflow = node.next[index].node.replace(/\.flow\.json/i, '')

return (
<div className={style.label}>
Expand Down
2 changes: 1 addition & 1 deletion src/bp/ui-studio/src/web/views/FlowBuilder/index.tsx
Expand Up @@ -167,7 +167,7 @@ class FlowBuilder extends Component<Props, State> {
}

pushFlowState = flow => {
this.props.history.push(`/flows/${flow.replace(/\.flow\.json/, '')}`)
this.props.history.push(`/flows/${flow.replace(/\.flow\.json/i, '')}`)
}

hideSearch = () => this.setState({ showSearch: false })
Expand Down
Expand Up @@ -41,7 +41,7 @@ const SidePanelContent: FC<Props> = props => {
const [flowAction, setFlowAction] = useState<any>('create')
const [filter, setFilter] = useState()

const goToFlow = flow => history.push(`/flows/${flow.replace(/\.flow\.json/, '')}`)
const goToFlow = flow => history.push(`/flows/${flow.replace(/\.flow\.json/i, '')}`)

const normalFlows = reject(props.flows, x => x.name.startsWith('skills/'))
const flowsName = normalFlows.map(x => {
Expand Down

0 comments on commit 85c0283

Please sign in to comment.